array within an arrayList? - comparing objects - in way over my head!
in
Programming Questions
•
9 months ago
Hello, thanks for reading my question!
I am trying to make a patch that interprets the MIDI data I send it into class objects that are then represented visually.
Per MIDI note played, two messages are sent - a note-on and a note-off (both containing channel, pitch and velocity data). I am trying to add a note object to an ArrayList when a note-on message is received and then subsequently, to remove that same object when this note's corresponding note-off message is received. Here is my problem...
Adding note objects to an ArrayList when a note-on message is received doesn't seem to be the problem, the problem is removing the corresponding object. I think I need to compare the note-off message received with the note objects contained in the array list, removing the note object that corresponds - but doing this has proved to be well beyond my programming abilities.
Below is what I have so far, I'd be very grateful for any help you could provide.
Thank you,
Adam
- import fullscreen.*;
- import themidibus.*; //Import the library
- MidiBus busA; //The first MidiBus
- import javax.sound.midi.MidiMessage; //Import the MidiMessage classes http://java.sun.com/j2se/1.5.0/docs/api/javax/sound/midi/MidiMessage.html
- import javax.sound.midi.SysexMessage;
- import javax.sound.midi.ShortMessage;
- PVector v1;
- FullScreen fs;
- void setup() {
- size(400,400,P3D);
- background(0);
- MidiBus.list(); //List all available Midi devices. This will show each device's index and name.
- busA = new MidiBus(this, 0, 0);
- busA.addInput("IAC Bus 1");
- v1 = new PVector (width/2,height/2,0);
- // Create the fullscreen object
- fs = new FullScreen(this);
- // enter fullscreen mode
- fs.enter();
- }
- void draw() {
- //lights();
- //fill(0,10);
- //noStroke();
- //rect(0,0,width/2,height/2);
- }
- void noteOn(int channel, int pitch, int velocity){
- //println(channel +" "+ pitch +" "+ velocity);
- Note.addANote(channel, pitch, velocity);
- }
- void noteOff(int channel, int pitch, int velocity){
- //println(channel +" "+ pitch +" "+ velocity);
- Note.removeANote(channel, pitch, velocity);
- }
- class Note {
- ArrayList notes = new ArrayList();
- Note(int channel, int pitch, int velocity){
- int[] data = {channel, pitch, velocity};
- }
- void addANote (int channel, int pitch, int velocity){
- notes.add(new Note(channel,pitch,velocity));
- }
- void removeANote (int channel, int pitch, int velocity){
- int _channel = this.channel;
- int _pitch = this.pitch;
- int _velocity = this.velocity;
- int[] _data = {_channel, _pitch, _velocity};
- for (int i = 0; i < notes.size(); i++){
- if(notes.get[i] == _data){
- notes.remove(i);
- }
- }
- }
- void display (){
- for(int i = 0; i < notes.size(); i++){
- }
- }
- }
1