/**
* Notifies any of the supported methods implemented inside the Parent of a new MIDI message from one of the MIDI input devices.
*
* Message: The new inbound MidiMessage.
* TimeStamp: The timestamp
*/
void NotifyParent(MidiMessage Message, long TimeStamp) {
if (parent == null) return;
byte[] data = Message.getMessage();
switch ( (int)((byte)data[0] & 0xF0) ) {
case ShortMessage.NOTE_ON: //////// NOTE ON ////////
LastNoteOnVelocity = Constrain((int)(data[2] & 0xFF), 0, 127);
if ( parent.subExists(eventName + "_noteon") ){
// BA.Log("esiste la sub noteon");
try {
parent.raiseEventFromDifferentThread(this, null, 0, eventName + "_noteon", false, new Object[] { (int)(data[0] & 0x0F), (int)(data[1] & 0xFF), (int)(data[2] & 0xFF) });
//parent.raiseEvent(this, eventName + "_noteon", new Object[] { (int)(data[0] & 0x0F), (int)(data[1] & 0xFF), (int)(data[2] & 0xFF) }); //ORIGINALE********************
} catch (Exception e) {
//BA.Log("MidiBus Warning: Disabling NoteOn(Channel As Int, Note As Int, Velocity As Int) because an unkown exception was thrown and caught");
e.printStackTrace();
}
}
if ( parent.subExists(eventName + "_noteon_timestamp_busname") ){
try{
parent.raiseEventFromDifferentThread(this, null, 0, eventName + "_noteon_timestamp_busname", false, new Object[] { (int)(data[0] & 0x0F), (int)(data[1] & 0xFF), (int)(data[2] & 0xFF), TimeStamp/1000, bus_name });
//parent.raiseEvent(this, eventName + "_noteon_timestamp_busname", new Object[] { (int)(data[0] & 0x0F), (int)(data[1] & 0xFF), (int)(data[2] & 0xFF), TimeStamp/1000, bus_name }); //ORIGINALE********************
} catch (Exception e){
e.printStackTrace();
}
}
if ( parent.subExists(eventName + "_noteon_note") ){
try {
parent.raiseEventFromDifferentThread(this, null, 0, eventName + "_noteon_note", false, new Object[] {new Note((int)(data[0] & 0x0F), (int)(data[1] & 0xFF), (int)(data[2] & 0xFF), TimeStamp/1000, bus_name)});
//parent.raiseEvent(this, eventName + "_noteon_note", new Note((int)(data[0] & 0x0F), (int)(data[1] & 0xFF), (int)(data[2] & 0xFF), TimeStamp/1000, bus_name) );
} catch (Exception e){
e.printStackTrace();
}
}
break;
case ShortMessage.NOTE_OFF: //////// NOTE OFF ////////
if ( parent.subExists(eventName + "_noteoff") ){
try {
parent.raiseEventFromDifferentThread(this, null, 0, eventName + "_noteoff", false, new Object[] { (int)(data[0] & 0x0F), (int)(data[1] & 0xFF), (int)(data[2] & 0xFF) });
//parent.raiseEvent(this, eventName + "_noteoff", new Object[] { (int)(data[0] & 0x0F), (int)(data[1] & 0xFF), (int)(data[2] & 0xFF) }); //ORIGINALE********************
} catch(Exception e) {
e.printStackTrace();
}
}
if ( parent.subExists(eventName + "_noteoff_timestamp_busname") ){
try {
parent.raiseEventFromDifferentThread(this, null, 0, eventName + "_noteoff_timestamp_busname", false, new Object[] { (int)(data[0] & 0x0F), (int)(data[1] & 0xFF), (int)(data[2] & 0xFF), TimeStamp/1000, bus_name });
//parent.raiseEvent(this, eventName + "_noteoff_timestamp_busname", new Object[] { (int)(data[0] & 0x0F), (int)(data[1] & 0xFF), (int)(data[2] & 0xFF), TimeStamp/1000, bus_name }); //ORIGINALE********************
} catch(Exception e) {
//BA.Log("MidiBus Warning: Disabling NoteOff_TimeStamp_BusName(Channel As Int, Note As Int, Velocity As Int, TimeStamp As Long, BusName As String) because an unkown exception was thrown and caught");
e.printStackTrace();
}
}
if ( parent.subExists(eventName + "_noteoff_note") ){
try {
parent.raiseEventFromDifferentThread(this, null, 0, eventName + "_noteoff_note", false, new Object[] {new Note((int)(data[0] & 0x0F), (int)(data[1] & 0xFF), (int)(data[2] & 0xFF), TimeStamp/1000, bus_name)});
//parent.raiseEvent(this, eventName + "_noteoff_note", new Note((int)(data[0] & 0x0F), (int)(data[1] & 0xFF), (int)(data[2] & 0xFF), TimeStamp/1000, bus_name) );
} catch(Exception e) {
e.printStackTrace();
}
}
break;
case ShortMessage.CONTROL_CHANGE: //////// CONTROL CHANGE ////////
if ( parent.subExists(eventName + "_controlchange") ){
try {
parent.raiseEventFromDifferentThread(this, null, 0, eventName + "_controlchange", false, new Object[] { (int)(data[0] & 0x0F), (int)(data[1] & 0xFF), (int)(data[2] & 0xFF)});
//parent.raiseEvent(this, eventName + "_controlchange", new Object[] { (int)(data[0] & 0x0F), (int)(data[1] & 0xFF), (int)(data[2] & 0xFF)}); //ORIGINALE********************
} catch(Exception e) {
e.printStackTrace();
}
}
if ( parent.subExists(eventName + "_controlchange_timestamp_busname") ){
try {
parent.raiseEventFromDifferentThread(this, null, 0, eventName + "_controlchange_timestamp_busname", false, new Object[] { (int)(data[0] & 0x0F), (int)(data[1] & 0xFF), (int)(data[2] & 0xFF), TimeStamp/1000, bus_name });
//parent.raiseEvent(this, eventName + "_controlchange_timestamp_busname", new Object[] { (int)(data[0] & 0x0F), (int)(data[1] & 0xFF), (int)(data[2] & 0xFF), TimeStamp/1000, bus_name }); //ORIGINALE********************
} catch(Exception e) {
e.printStackTrace();
}
}
if ( parent.subExists(eventName + "_controlchange_control") ){
try {
parent.raiseEventFromDifferentThread(this, null, 0, eventName + "_controlchange_control", false, new Object[] {new ControlChange((int)(data[0] & 0x0F), (int)(data[1] & 0xFF), (int)(data[2] & 0xFF), TimeStamp/1000, bus_name)});
//parent.raiseEvent(this, eventName + "_controlchange_control", new ControlChange((int)(data[0] & 0x0F), (int)(data[1] & 0xFF), (int)(data[2] & 0xFF), TimeStamp/1000, bus_name));
} catch(Exception e) {
e.printStackTrace();
}
}
break;
default:
break;
}
//////// RAW MIDI ////////
if ( parent.subExists(eventName + "_rawdata") ) { // Always notify raw data input if callback sub exist
try {
int[] dataint = new int[data.length];
for(int i = 0; i < data.length; i++) dataint[i] = (int)(data[i] & 0xFF);
parent.raiseEventFromDifferentThread(this, null, 0, eventName + "_rawdata", false, new Object[] { dataint });
// parent.raiseEvent(this, eventName + "_rawdata", new Object[] { data });
//parent.raiseEvent(this, eventName + "_rawdata", new Object[] { dataint }); //ORIGINALE********************
} catch(Exception e) {
e.printStackTrace();
}
}
if ( parent.subExists(eventName + "_rawdata_timestamp_busname") ) { // Always notify raw data input if callback sub exist
try {
int[] dataint = new int[data.length];
for(int i = 0; i < data.length; i++)dataint[i] = (int)(data[i] & 0xFF);
parent.raiseEventFromDifferentThread(this, null, 0, eventName + "_rawdata_timestamp_busname", false, new Object[] { dataint, TimeStamp/1000, bus_name });
//parent.raiseEvent(this, eventName + "_rawdata_timestamp_busname", new Object[] { dataint, TimeStamp/1000, bus_name }); //ORIGINALE********************
} catch(Exception e) {
e.printStackTrace();
}
}
//////// SHORT MESSAGE //////// We return a ShortMessage class instead of MidiMessage because B4J do not know java MidiMessage and we need to wrap it inside a custom class
if ( parent.subExists(eventName + "_shortmessage") ) { // Always notify short messages if callback sub exist
try {
ShortMessage SM = new ShortMessage(data);
parent.raiseEventFromDifferentThread(this, null, 0, eventName + "_shortmessage", false, new Object[] { SM });
} catch(Exception e) {
e.printStackTrace();
}
}
if ( parent.subExists(eventName + "_shortmessage_timestamp_busname") ) { // Always notify short messages if callback sub exist
try {
ShortMessage SM = new ShortMessage(data);
parent.raiseEventFromDifferentThread(this, null, 0, eventName + "_shortmessage_timestamp_busname", false, new Object[] { SM, TimeStamp/1000, bus_name });
} catch(Exception e) {
e.printStackTrace();
}
}
}