We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSound,  Music Libraries › RemoveEvent in ProMIDI
Page Index Toggle Pages: 1
RemoveEvent in ProMIDI (Read 3224 times)
RemoveEvent in ProMIDI
Jun 25th, 2008, 1:15pm
 
Hi there,
I am new to promidi and I'd like to make a kind of step sequencer. I am creating notes when someone toggles a button:
track.addEvent(new Note(35+row,127,30),col-1);
and when someone is turning off the button I'd like to remove this note/event and this is where my problem pops up:
track.removeEvent(???,col-1);  
I do not know what to put as a first parameter....
Please help!

Regards
Reverb Rick
Re: RemoveEvent in ProMIDI
Reply #1 - Jun 25th, 2008, 2:22pm
 
This is purely a guess,having not used the library, but the standard way would be:

Code:
Note n=new Note(35+row,127,30);
track.addEvent(n,col-1);
track.removeEvent(n,col-1);
Re: RemoveEvent in ProMIDI
Reply #2 - Jun 25th, 2008, 3:24pm
 
Great! It will work!
Thank you very much!
RR
Re: RemoveEvent in ProMIDI
Reply #3 - Jun 26th, 2008, 9:05am
 
I'm still to weak to complete that one :(
Your advice works if I know the name of variable defined.
To track which one to switch off I've created an array:
Note[] n = new Note[255];
and then:
track.addEvent(n[id],col-1);
...
track.removeEvent(n[id],col-1);  
...
which produces:

ERROR. an error occured while forwarding a Controller value
to a method in your program. please check your code for any
possible errors that might occur in this method .
e.g. check for casting errors, possible nullpointers, array overflows ... .
method: controlEvent
exception:  java.lang.reflect.InvocationTargetException

...looks like array overflow, but dont know why...

Please help!
Re: RemoveEvent in ProMIDI
Reply #4 - Jun 26th, 2008, 9:52am
 
You'll have to show a bit more code for us to be able to help. It's possible you've not initialised the n[id] and so are sending a null in to the function...
Re: RemoveEvent in ProMIDI
Reply #5 - Jun 26th, 2008, 10:16am
 
Many thanks for a quick response!

the code looks like that:

Note[] n = new Note[255];
....
  if(valu==1.0){
      n[id] = new Note(35+row,127,30);
      track.addEvent(n[id],col-1);
  }
  else{
      track.removeEvent(n[id],col-1);      
  }
....
the id is a number of step of my sequencer
Re: RemoveEvent in ProMIDI
Reply #6 - Dec 24th, 2008, 6:56am
 
hey there,
im having the exact same problam.

cant remove Event.

did you come up with something?
Re: RemoveEvent in ProMIDI
Reply #7 - Dec 24th, 2008, 11:52am
 
nope...it was thrown to a drawer. Hope I'll come back to that with a king of fresh mind.
Hope you'll succeed!

RR
Re: RemoveEvent in ProMIDI
Reply #8 - Dec 24th, 2008, 3:50pm
 
oh my...

i have a large project stuck on this bit.
i get a 'NullPointerException' when i try removeEvent.

anyway thanks for your replay,
i hope someone will have a solution.
Re: RemoveEvent in ProMIDI
Reply #9 - Feb 16th, 2009, 10:38pm
 
Hi.. I was having some problems with this as well. I'm not sure I can tell exactly why your code isn't working but I have two working examples. I've written one step-sequencer using an array for storing the events and one that doesn't use MIDI-events at all (it does use notes Wink but it doesn't add() and remove() them). Both ways work, so try them both!

The Array way:

MidiEvent[] buttonEvents;

//in void setup(){

 buttonEvents = new MidiEvent[16]; //Storing the "active" events of one bar.
 
 
//in void mousePressed(){  
 
 for(int i = 0 ; i < 16  ; i++){
   if(buttons[i].isOver()){    //if I press the mouse when over a button
     if(buttons[i].isPressed()){  //and the button is already pressed,
                                                 //then the active event will be removed
       track.removeEvent(buttonEvents[i],i);  
 //the second argument to removeEvent() could be anything, really.
     }else{              //It depends on what number of ticks you have chosen
                             // for your sequencer - in this case 16.
       //if the mouse is clicked when over a button that is not already pressed:
       // we save a Note in the buttonEvents-array,

       buttonEvents[i+16] = new Note(60, 20, 2);

       // and add it to the track, at tick i.

       track.addEvent(buttonEvents[i],i);      
     }
   }
 }

Re: RemoveEvent in ProMIDI
Reply #10 - Feb 16th, 2009, 10:52pm
 
Oh, and my second example:

//this program doesn't use a track to send MIDI-events,
//but rather just sends notes whenever the sequencer
//"lands" on a trigger - in this case steps in a step-
//sequencer. The code below is taken from a class called Buttons.

//in constructor:
 int tempTick = 0
 Button[] buttons;  //the class uses an array of another class:
 //clickable two-state buttons with a method isPressed() that returns
 //what state the button is in.
 buttons = new Button[16];
//

 void sendMidi(){    //this is a method of a class of buttons.
 
 //the variable b is used to store the position of the sequencer:
   int b = int(sequencer.getTickPosition() % 16);  
   if(b != tempTick){  //this only happens once every tick.

 //if the button corresponding to the current tick is pressed...
         if(buttons[b].isPressed()){  
 // we send a note.
           Note note = new Note(36,120,20);
           midiOut.sendNote(note);
         }
     }
   }
   tempTick = b;  //we set the tempTick to be the current tick.
 }

//this last bit is from    void draw()

 if(sequencer.isRunning()){    
   boxes.sendMidi();
 }
Re: RemoveEvent in ProMIDI
Reply #11 - Feb 16th, 2009, 11:07pm
 
oh..

and the problem in the code you posted is probably that you're not referring to a specific MIDI-event. For the program to remove a MIDI-event from the track, you have to tell it exactly which event to remove. For example,

 track.addEvent(Note(1,1,1),1);  
//followed by
 track.removeEvent(Note(1,1,1),1);

probably wouldn't work (I haven't actually tested this, but I don't think it works), because even if the notes look the same, they are not the exact same Note.

And in,

 track.removeEvent(n[id],col-1);

I would rather use an int than the expression "col-1" - to remove an event you have to tell the track exactly at which tick it is scheduled, and by giving removeEvent() a variable you risk giving it an empty tick.

Also, it is very important that the event n[id] have been explicitly defined earlier in your code. In the code...

  if(valu==1.0){
 n[id] = new Note(35+row,127,30);
 track.addEvent(n[id],col-1);  
  }
  else{
 track.removeEvent(n[id],col-1);  
  }

...you are clearly taking the risk of removing an event that doesn't exist.



God, this became a quite long answer but I hope it helps. And I hope you get the sequencer up and running! Good luck!


Moe.


Re: RemoveEvent in ProMIDI
Reply #12 - Feb 2nd, 2010, 1:47am
 
I've the same problem. I don't undersand why I can't remove notes.
If someone could help me.

The idea here is very simple.
-Create an array of 4 notes
-Delete each notes one by one with "DELETE" keyCode
- Another solution would be with '1', '2', '3', '4' keys but it doesn't work too.

Code:

/* *PROMIDI SEQUENCER * */

import promidi.*;

// DECLARATIONS PROMIDI
MidiIO midiIO;
MidiOut midiOut;
Sequencer sequencer;
Track track;
Note [] notes;
int counterDelete = 0;

void setup(){

 // MIDI IN OUT
 MidiIO midiIO = MidiIO.getInstance();
 midiIO.printDevices();
 midiIO.closeOutput(1);
 MidiOut midiOut = midiIO.getMidiOut(1,1);

 // TRACK
 track = new Track("one", midiOut);
 track.setQuantization(Q._1_4);
 
 // NOTES > TRACK
 notes = new Note[4];
 notes[0] = new Note(36,90,100);
 notes[1] = new Note(41,90,100);
 notes[2] = new Note(46,90,100);
 notes[3] = new Note(48,90,100);
 
 track.addEvent(notes[0], 0);
 track.addEvent(notes[1], 1);
 track.addEvent(notes[2], 2);
 track.addEvent(notes[3], 3);

 // SONG
 Song song = new Song("midiOut", 120);
 song.addTrack(track);
 
 // SEQUENCER
 sequencer = new Sequencer();
 sequencer.setSong(song);
 sequencer.setLoopStartPoint(0);
 sequencer.setLoopEndPoint(512);
 sequencer.setLoopCount(-1);
}

void mousePressed(){
 if(mouseButton == LEFT) sequencer.start();
 else sequencer.stop();
}

void keyPressed() {
 if (key == DELETE) {
  track.removeEvent(notes[counterDelete], counterDelete);
  println("DELETE " + counterDelete);
  counterDelete ++;
 }

// Another solution :
//  if (key == '1') track.removeEvent(notes[0], 0);
//  else if (key == '2') track.removeEvent(notes[1], 1);
//  else if (key == '3') track.removeEvent(notes[2], 2);
//  else if (key == '4') track.removeEvent(notes[3], 3);
}

void draw(){}


Quite simple, isn't it ?

But It does'nt work at all  Sad

The message error concern ticks greater than the first tick I guess.
The first note is deleted and the second stop the programm and display this message :


Exception in thread "Animation Thread" java.lang.NullPointerException
     at promidi.TickMapEvents.removeEvent(TickMapEvents.java:85)
     at promidi.Pattern.removeEvent(Pattern.java:503)
     at proMidi_sequencer.keyPressed(proMidi_sequencer.java:74)
     at processing.core.PApplet.handleKeyEvent(PApplet.java:1752)
     at processing.core.PApplet.dequeueKeyEvents(PApplet.java:1735)
     at processing.core.PApplet.handleDraw(PApplet.java:1437)
     at processing.core.PApplet.run(PApplet.java:1327)
     at java.lang.Thread.run(Thread.java:619)


Any help ?
Re: RemoveEvent in ProMIDI
Reply #13 - Feb 2nd, 2010, 7:28pm
 
Great info. It really makes sense. Thanks!
Problem solved.
Page Index Toggle Pages: 1