Skip to content

Commit

Permalink
use byte instead of bool for cross lang callback
Browse files Browse the repository at this point in the history
the size between c++ and c# might not match otherwise
re #24
  • Loading branch information
x37v committed Jul 12, 2023
1 parent 7de1a32 commit 93dbe9b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
10 changes: 5 additions & 5 deletions RNBOTypes/Runtime/Cycling74.RNBOTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public class PresetList {
public List<PresetEntry> presets;
}

public delegate void TransportRequestDelegate(IntPtr userData, MillisecondTime time, out bool running, out Float bpm, out Float beatTime, out int timeSigNum, out int timeSigDenom);
public delegate void TransportRequestDelegate(IntPtr userData, MillisecondTime time, out byte running, out Float bpm, out Float beatTime, out int timeSigNum, out int timeSigDenom);

public class Transport {

Expand Down Expand Up @@ -243,21 +243,21 @@ public void SeekTo(Float beatTime) {
(UInt16, UInt16) timeSignatureCur = (4, 4);

[AOT.MonoPInvokeCallback(typeof(TransportRequestDelegate))]
public static void AudioThreadUpdate(IntPtr inst, MillisecondTime time, out bool run, out Float tempo, out Float beatTime, out int timeSigNum, out int timeSigDenom) {
public static void AudioThreadUpdate(IntPtr inst, MillisecondTime time, out byte run, out Float tempo, out Float beatTime, out int timeSigNum, out int timeSigDenom) {
GCHandle gch = GCHandle.FromIntPtr(inst);
Transport transport = (Transport)gch.Target;
if (transport != null) {
transport.Update(time, out run, out tempo, out beatTime, out timeSigNum, out timeSigDenom);
} else {
run = false;
run = 0; //false
tempo = 100.0;
beatTime = 0.0;
timeSigNum = 4;
timeSigDenom = 4;
}
}

internal void Update(MillisecondTime time, out bool run, out Float tempo, out Float beatTime, out int timeSigNum, out int timeSigDenom) {
internal void Update(MillisecondTime time, out byte run, out Float tempo, out Float beatTime, out int timeSigNum, out int timeSigDenom) {
if (time != _lastUpdate) {
var last = _lastUpdate;

Expand All @@ -284,7 +284,7 @@ internal void Update(MillisecondTime time, out bool run, out Float tempo, out Fl
BeatTime = beatTimeCur;
}

run = runningCur;
run = (byte)(runningCur ? 1 : 0);
tempo = tempoCur;
beatTime = beatTimeCur;
timeSigNum = (int)timeSignatureCur.Item1;
Expand Down
7 changes: 4 additions & 3 deletions src/RNBOWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ extern "C" {
typedef void (UNITY_AUDIODSP_CALLBACK * CBeatTimeEventCallback)(void * handle, RNBO::number, RNBO::MillisecondTime);
typedef void (UNITY_AUDIODSP_CALLBACK * CTimeSignatureEventCallback)(void * handle, int32_t, int32_t, RNBO::MillisecondTime);

typedef void (UNITY_AUDIODSP_CALLBACK * CTransportRequestCallback)(void * handle, RNBO::MillisecondTime time, bool* running, RNBO::number* bpm, RNBO::number* beatTime, int32_t *timeSigNum, int32_t *timeSigDenom);
typedef void (UNITY_AUDIODSP_CALLBACK * CTransportRequestCallback)(void * handle, RNBO::MillisecondTime time, uint8_t* running, RNBO::number* bpm, RNBO::number* beatTime, int32_t *timeSigNum, int32_t *timeSigDenom);
typedef void (UNITY_AUDIODSP_CALLBACK * CPresetCallback)(void * handle, const char * payload);
}

Expand Down Expand Up @@ -296,14 +296,15 @@ namespace RNBOUnity
transport = globalTransport;

if (transport != nullptr) {
bool running = false;
RNBO::number bpm = 0.0, beatTime = 0.0;
int32_t timeSigNum = 4, timeSigDenom = 4;

uint8_t runningByte = 0;
transport->callback<CTransportRequestCallback>()(
transport->handle(),
now, &running, &bpm, &beatTime, &timeSigNum, &timeSigDenom);
now, &runningByte, &bpm, &beatTime, &timeSigNum, &timeSigDenom);

bool running = runningByte != 0;
if (running != mTransportRunning) {
mTransportRunning = running;

Expand Down

0 comments on commit 93dbe9b

Please sign in to comment.