Skip to content

Commit

Permalink
Changing sync map delay on USB MIDI.
Browse files Browse the repository at this point in the history
  • Loading branch information
trash80 committed Jul 15, 2016
1 parent 239dc67 commit d67d8a0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
3 changes: 2 additions & 1 deletion Arduinoboy/Arduinoboy.ino
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,8 @@ unsigned long mapQueueTime;
// mapQueueWait is used for delaying a sync byte
// if it is called right before a note on message on sequencer start
// (Note value is also a clock tick)
unsigned long mapQueueWait = 2000; //2ms
uint8_t mapQueueWaitSerial = 2; //2ms
uint8_t mapQueueWaitUsb = 5; //5ms - Needs to be longer because message packet is processed all at once

/***************************************************************************
* mGB Settings
Expand Down
39 changes: 22 additions & 17 deletions Arduinoboy/Mode_LSDJ_Map.ino
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void modeLSDJMap()
if(incomingMidiByte & 0x80) { //If we have received a MIDI Status Byte
switch (incomingMidiByte) {
case 0xF8:
setMapByte(0xFF);
setMapByte(0xFF, false);
usbMidiSendRTMessage(incomingMidiByte);
break;
case 0xFA: // Case: Transport Start Message
Expand All @@ -47,7 +47,7 @@ void modeLSDJMap()
break;
case 0xFC: // Case: Transport Stop Message
sequencerStop();
setMapByte(0xFE);
setMapByte(0xFE, false);
usbMidiSendRTMessage(incomingMidiByte);
break;
default:
Expand All @@ -72,16 +72,16 @@ void modeLSDJMap()
|| midiData[0] == (0x90+(memory[MEM_LIVEMAP_CH]+1))) {
if(incomingMidiByte) {
if(midiData[0] == (0x90+(memory[MEM_LIVEMAP_CH]+1))) {
setMapByte(128+midiData[1]);
setMapByte(128+midiData[1], false);
} else {
setMapByte(midiData[1]);
setMapByte(midiData[1], false);
}
} else {
setMapByte(0xFE);
setMapByte(0xFE, false);
}
} else if (midiData[0] == (0x80+memory[MEM_LIVEMAP_CH])
|| midiData[0] == (0x80+(memory[MEM_LIVEMAP_CH]+1))) {
setMapByte(0xFE);
setMapByte(0xFE, false);
}
usbMidiSendThreeByteMessage(midiData[0], midiData[1], incomingMidiByte);
checkMapQueue();
Expand All @@ -95,17 +95,22 @@ void modeLSDJMap()
}
}

void setMapByte(uint8_t b)
void setMapByte(uint8_t b, boolean usb)
{
uint8_t wait = mapQueueWaitSerial;
if(usb) {
wait = mapQueueWaitUsb;
}

switch(b) {
case 0xFF:
setMapQueueMessage(0xFF);
setMapQueueMessage(0xFF, wait);
break;
case 0xFE:
if(!sequencerStarted) {
sendByteToGameboy(0xFE);
} else if (mapCurrentRow >= 0) {
setMapQueueMessage(mapCurrentRow);
setMapQueueMessage(mapCurrentRow, wait);
}
break;
default:
Expand All @@ -115,10 +120,10 @@ void setMapByte(uint8_t b)
}
}

void setMapQueueMessage(uint8_t m)
void setMapQueueMessage(uint8_t m, uint8_t wait)
{
if(mapQueueMessage == -1 || mapQueueMessage == 0xFF) {
mapQueueTime=micros()+mapQueueWait;
mapQueueTime=millis()+wait;
mapQueueMessage=m;
}
}
Expand All @@ -130,7 +135,7 @@ void resetMapCue()

void checkMapQueue()
{
if(mapQueueMessage >= 0 && micros()>mapQueueTime) {
if(mapQueueMessage >= 0 && millis()>mapQueueTime) {
if(mapQueueMessage == 0xFF) {
sendByteToGameboy(mapQueueMessage);
} else {
Expand All @@ -150,7 +155,7 @@ void usbMidiLSDJMapRealtimeMessage(uint8_t message)
{
switch(message) {
case 0xF8:
setMapByte(0xFF);
setMapByte(0xFF, true);
break;
case 0xFA: // Case: Transport Start Message
case 0xFB: // and Case: Transport Continue Message
Expand All @@ -159,7 +164,7 @@ void usbMidiLSDJMapRealtimeMessage(uint8_t message)
break;
case 0xFC: // Case: Transport Stop Message
sequencerStop(); // Stop the sequencer
setMapByte(0xFE);
setMapByte(0xFE, true);
break;
}
}
Expand All @@ -176,13 +181,13 @@ void modeLSDJMapUsbMidiReceive()

switch(usbMIDI.getType()) {
case 0: // note off
setMapByte(0xFE);
setMapByte(0xFE, true);
break;
case 1: // note on
if(ch == (memory[MEM_LIVEMAP_CH] + 1)) {
setMapByte(128+usbMIDI.getData1());
setMapByte(128+usbMIDI.getData1(), true);
} else {
setMapByte(usbMIDI.getData1());
setMapByte(usbMIDI.getData1(), true);
}
break;
/*
Expand Down

0 comments on commit d67d8a0

Please sign in to comment.