-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMode_LSDJ_SlaveSync_teensy.ino
142 lines (129 loc) · 3.87 KB
/
Mode_LSDJ_SlaveSync_teensy.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/**
* TeensyBoy
* 1.2.3
* ArduinoBoy Firmware for Teensy 2.0
*
* noizeinabox@gmail.com
* http://noizeinabox.blogspot.com/2012/12/teensyboy.htm
*
*
* Original ArduinoBoy
* Timothy Lamb (trash80@gmail.com)
* https://github.com/trash80/Arduinoboy
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
*/
void modeLSDJSlaveSyncSetup()
{
digitalWrite(pinStatusLed, LOW);
DDRF = B00111111; //Set analog in pins as outputs
PORTF = B00000001;
blinkMaxCount = 1000;
modeLSDJSlaveSync();
}
void modeLSDJSlaveSync()
{
while (1)
{ //Loop forever
usbMIDI.read();
setMode(); //Check if the mode button was depressed
updateStatusLight();
}
}
//NIB: function when a realtime midi message is received and LSDJ slavemode is enabled
void RealTimeLSDJSlave(byte realtimebyte)
{
switch (realtimebyte)
{
case 0xF8: //Case: Clock Message Recieved
if ((sequencerStarted && midiSyncEffectsTime && !countSyncTime) //If the seq has started and our sync effect is on and at zero
|| (sequencerStarted && !midiSyncEffectsTime))
{ //or seq is started and there is no sync effects
if (!countSyncPulse && midiDefaultStartOffset)
{ //if we received a note for start offset
//sendByteToGameboy(midiDefaultStartOffset); //send the offset ??????????? why disabled
}
sendClockTickToLSDJ(); //send the clock tick
updateVisualSync();
}
if (midiSyncEffectsTime)
{ //If sync effects are turned on
countSyncTime++; //increment our tick counter
countSyncTime = countSyncTime % countSyncSteps; //and mod it by the number of steps we want for the effect
}
break;
case 0xFA: // Case: Transport Start Message
case 0xFB: // and Case: Transport Continue Message
sequencerStart(); // Start the sequencer
break;
case 0xFC: // Case: Transport Stop Message
sequencerStop(); // Stop the sequencer
break;
default:
break;
}
}
//NIB: function when a Note ON is received and LSDJ slave mode is enabled
void NoteONLSDJSlave(byte channel, byte note, byte velocity)
{
if ((channel - 1) == (memory[MEM_LSDJSLAVE_MIDI_CH]))
{ //if a midi note was received and its on the channel of the sync effects channel
midiData[0] = note;
if (velocity != 0)
{
getSlaveSyncEffect(midiData[0]); //then call our sync effects function
}
}
}
/*
sendClockTickToLSDJ is a lovely loving simple function I wish they where all this short
Technicallyly we are sending nothing but a 8bit clock pulse
*/
void sendClockTickToLSDJ()
{
for (countLSDJTicks = 0; countLSDJTicks < 8; countLSDJTicks++)
{
PORTF = B00000000;
PORTF = B00000001;
}
}
/*
getSlaveSyncEffect receives a note, and assigns the propper effect of that note
*/
void getSlaveSyncEffect(byte note)
{
switch (note)
{
case 48: //C-3ish, Transport Start
sequencerStart();
break;
case 49: //C#3 Transport Stop
sequencerStop();
break;
case 50: //D-3 Turn off sync effects
midiSyncEffectsTime = false;
break;
case 51: //D#3 Sync effect, 1/2 time
midiSyncEffectsTime = true;
countSyncTime = 0;
countSyncSteps = 2;
break;
case 52: //E-3 Sync Effect, 1/4 time
midiSyncEffectsTime = true;
countSyncTime = 0;
countSyncSteps = 4;
break;
case 53: //F-3 Sync Effect, 1/8 time
midiSyncEffectsTime = true;
countSyncTime = 0;
countSyncSteps = 8;
break;
default: //All other notes will make LSDJ Start at the row number thats the same as the note number.
midiDefaultStartOffset = midiData[0];
break;
}
}