Skip to content

Commit 7f9fa54

Browse files
committed
Fix arduinoboy sync issues
1 parent e527f30 commit 7f9fa54

File tree

6 files changed

+45
-20
lines changed

6 files changed

+45
-20
lines changed

config/config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
#define SEMVER_MAJOR 0
66
#define SEMVER_MINOR 3
7-
#define SEMVER_PATCH 1
7+
#define SEMVER_PATCH 2
88

99
#define PLUG_NAME "RetroPlug"
1010
#define PLUG_MFR "tommitytom"
11-
#define PLUG_VERSION_HEX 0x00000301
11+
#define PLUG_VERSION_HEX 0x00000302
1212
#define PLUG_VERSION_STR VERSION_STRING(SEMVER_MAJOR, SEMVER_MINOR, SEMVER_PATCH)
1313
#define PLUG_UNIQUE_ID '2wvF'
1414
#define PLUG_MFR_ID 'tmtt'

src/plugin/audio/RetroPlugInstrument.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ int RetroPlugInstrument::UnserializeState(const IByteChunk& chunk, int pos) {
8585

8686
void RetroPlugInstrument::ProcessMidiMsg(const IMidiMsg& msg) {
8787
TRACE;
88+
8889
_controller.getMenuLock()->lock(); // Temporary
8990
if (_controller.audioLua()) {
9091
_controller.audioLua()->onMidi(msg.mOffset, msg.mStatus, msg.mData1, msg.mData2);

src/retroplug/platform/Platform.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
//#define FORCE_LUA_COMPILE
44
#if !defined(_DEBUG) || defined(FORCE_LUA_COMPILE)// || defined(VST2_API)
5-
#define COMPILE_LUA_SCRIPTS
5+
//#define COMPILE_LUA_SCRIPTS
66
#endif

src/retroplug/scripts/audio/Controller.lua

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ function Controller:update(frameCount)
100100
if self._timeInfo.transportIsRunning ~= self._transportRunning then
101101
trans.changed = true
102102

103+
self._transportRunning = self._timeInfo.transportIsRunning
104+
self:emit("onTransportChanged", self._transportRunning)
105+
103106
if self._timeInfo.transportIsRunning == true then
104107
trans.state = TransportState.Playing
105108
trans.started = true
@@ -108,9 +111,6 @@ function Controller:update(frameCount)
108111
trans.stopped = true
109112
self._ppqGen:reset()
110113
end
111-
112-
self._transportRunning = self._timeInfo.transportIsRunning
113-
self:emit("onTransportChanged", self._transportRunning)
114114
end
115115

116116
if self._transportRunning == true then
@@ -132,22 +132,25 @@ end
132132
function Controller:onMidi(offset, statusByte, data1, data2)
133133
local channel = statusByte & 0x0F
134134
local status = statusByte >> 4
135-
136135
local r = self._model:getSettings().midiRouting
136+
137137
if status == midi.Status.System or r == MidiChannelRouting.SendToAll then
138138
local msg = midi.Message(offset, statusByte, data1, data2)
139+
139140
for _, v in ipairs(Project.systems) do
140141
self:emit("onMidi", v, msg)
141142
end
142143
elseif r == MidiChannelRouting.OneChannelPerInstance then
143144
local target = Project.systems[channel]
145+
144146
if target ~= nil then
145147
local msg = midi.Message(offset, statusByte, data1, data2)
146148
self:emit("onMidi", target, msg)
147149
end
148150
elseif r == MidiChannelRouting.FourChannelsPerInstance then
149151
local targetIdx = math.floor(channel / 4)
150152
local target = Project.systems[targetIdx + 1]
153+
151154
if target ~= nil then
152155
local msg = midi.Message(offset, (channel | (status << 4)), data1, data2)
153156
self:emit("onMidi", target, msg)

src/retroplug/scripts/audio/components/LsdjArduinoboy.lua

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,27 @@ function LsdjArduinoboy.onMenu(menu)
5252
end
5353

5454
function LsdjArduinoboy.onTransportChanged(running)
55-
local state = System.state.arduinoboy
56-
if state.autoPlay == true then
57-
System:buttons():press(Button.Start)
55+
for _, system in ipairs(Project.systems) do
56+
local state = system.state.arduinoboy
57+
58+
if state ~= nil then
59+
if state.syncMode == LsdjSyncModes.MidiMap then
60+
state.playing = running
61+
end
62+
63+
if state.autoPlay == true then
64+
system:buttons():press(Button.Start)
65+
end
66+
67+
if running == false and state.lastRow ~= -1 then
68+
system:sendSerialByte(0, 0xFE)
69+
end
70+
end
5871
end
5972
end
6073

6174
function LsdjArduinoboy.onUpdate(frameCount)
62-
75+
--print("---")
6376
end
6477

6578
local function processSync(system, offset)
@@ -71,7 +84,7 @@ local function processSync(system, offset)
7184
if state.playing == true then
7285
system:sendSerialByte(offset, 0xF8)
7386
end
74-
elseif state.syncMode == LsdjSyncModes.MidiSync then
87+
elseif state.syncMode == LsdjSyncModes.MidiMap then
7588
system:sendSerialByte(offset, 0xFF)
7689
end
7790
end
@@ -105,25 +118,29 @@ function LsdjArduinoboy.onMidi(system, msg)
105118
elseif msg.note == 28 then state.tempoDivisor = 4
106119
elseif msg.note == 29 then state.tempoDivisor = 8
107120
elseif msg.note >= 30 then
108-
System:sendSerialByte(msg.offset, msg.note - 30)
121+
system:sendSerialByte(msg.offset, msg.note - 30)
109122
end
110123
end
111124
elseif state.syncMode == LsdjSyncModes.MidiMap then
112125
-- Notes trigger row numbers
126+
113127
if status == midi.Status.NoteOn then
114128
local rowIdx = midiMapRowNumber(msg.channel, msg.note)
129+
115130
if rowIdx ~= -1 then
116-
System:sendSerialByte(msg.offset, rowIdx)
131+
system:sendSerialByte(msg.offset, rowIdx)
117132
state.lastRow = rowIdx
118133
end
119-
elseif status == midi.Status.Noteff then
134+
elseif status == midi.Status.NoteOff then
120135
local rowIdx = midiMapRowNumber(msg.channel, msg.note)
136+
121137
if rowIdx == state.lastRow then
122-
System:sendSerialByte(msg.offset, 0xFE)
138+
system:sendSerialByte(msg.offset, 0xFE)
123139
state.lastRow = -1
124140
end
141+
-- Pseudocode... not sure what to handle here! FL studio does nothing useful when stop is clicked
125142
elseif msg.type == "stop" then
126-
System:sendSerialByte(msg.offset, 0xFE)
143+
system:sendSerialByte(msg.offset, 0xFE)
127144
end
128145
end
129146
end

src/retroplug/scripts/audio/components/MidiPassthrough.lua

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ end
66
function MidiPassthrough.onTransportChanged()
77
end
88

9+
function MidiPassthrough.requires()
10+
return System ~= nil and System.desc.romName:match("MGB") ~= nil
11+
end
12+
913
function MidiPassthrough.onMidi(system, message)
10-
system:sendSerialByte(message.offset, message.statusByte, 8)
11-
system:sendSerialByte(message.offset, message.data1, 8)
12-
system:sendSerialByte(message.offset, message.data2, 8)
14+
system:sendSerialByte(message.offset, message.statusByte, 8)
15+
system:sendSerialByte(message.offset, message.data1, 8)
16+
system:sendSerialByte(message.offset, message.data2, 8)
1317
end
1418

1519
return MidiPassthrough

0 commit comments

Comments
 (0)