-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move host transport events to separate template and allow without mid…
…i input
- Loading branch information
Showing
6 changed files
with
74 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// ------------------------------------------------------------------- | ||
// Host Transport Events handler | ||
|
||
void {{class_name}}::hostTransportEvents(uint32_t frames) | ||
{ | ||
// Realtime events | ||
const TimePosition& timePos(getTimePosition()); | ||
bool reset = false; | ||
|
||
if (timePos.playing) | ||
{ | ||
if (timePos.frame == 0) | ||
{ | ||
_context->sendMessageToReceiverV(HV_HASH_MIDIREALTIMEIN, 0, | ||
"ff", (float) MIDI_RT_RESET, 0); | ||
reset = true; | ||
} | ||
|
||
if (! this->wasPlaying) | ||
{ | ||
if (timePos.frame == 0) | ||
{ | ||
_context->sendMessageToReceiverV(HV_HASH_MIDIREALTIMEIN, 0, | ||
"ff", (float) MIDI_RT_START, 0); | ||
} | ||
if (! reset) | ||
{ | ||
_context->sendMessageToReceiverV(HV_HASH_MIDIREALTIMEIN, 0, | ||
"ff", (float) MIDI_RT_CONTINUE, 0); | ||
} | ||
} | ||
} | ||
else if (this->wasPlaying) | ||
{ | ||
_context->sendMessageToReceiverV(HV_HASH_MIDIREALTIMEIN, 0, | ||
"ff", (float) MIDI_RT_STOP, 0); | ||
} | ||
this->wasPlaying = timePos.playing; | ||
|
||
// sending clock ticks | ||
if (timePos.playing && timePos.bbt.valid) | ||
{ | ||
float samplesPerBeat = 60 * getSampleRate() / timePos.bbt.beatsPerMinute; | ||
float samplesPerTick = samplesPerBeat / 24.0; | ||
|
||
/* get state */ | ||
double nextClockTick = this->nextClockTick; | ||
double sampleAtCycleStart = this->sampleAtCycleStart; | ||
double sampleAtCycleEnd = sampleAtCycleStart + frames; | ||
|
||
if (nextClockTick >= 0 && sampleAtCycleStart >= 0 && sampleAtCycleEnd > sampleAtCycleStart) { | ||
while (nextClockTick < sampleAtCycleEnd) { | ||
double delayMs = 1000*(nextClockTick - sampleAtCycleStart)/getSampleRate(); | ||
if (delayMs >= 0.0) { | ||
_context->sendMessageToReceiverV(HV_HASH_MIDIREALTIMEIN, delayMs, | ||
"ff", (float) MIDI_RT_CLOCK, 0); | ||
} | ||
nextClockTick += samplesPerTick; | ||
} | ||
} | ||
|
||
/* save variables for next cycle */ | ||
this->sampleAtCycleStart = sampleAtCycleEnd; | ||
this->nextClockTick = nextClockTick; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
#N canvas 951 312 204 190 12; | ||
#X obj 87 127 outlet; | ||
#X obj 86 148 outlet; | ||
#X obj 20 148 outlet; | ||
#X text 23 13 data port; | ||
#X obj 20 61 unpack f f; | ||
#X obj 87 94 + 1; | ||
#X obj 20 37 r __hv_midirealtimein; | ||
#X connect 3 0 1 0; | ||
#X connect 3 1 4 0; | ||
#X connect 4 0 0 0; | ||
#X connect 5 0 3 0; | ||
#X connect 3 1 0 0; | ||
#X connect 4 0 3 0; |