Skip to content

Commit db21bd5

Browse files
committed
RTTTLOutput: provide reference for callback
1 parent 32ce9d5 commit db21bd5

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/AudioTools/Sandbox/RTTTLOutput.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,15 @@ class RTTTLOutput : public AudioOutput {
188188
/// milliseconds
189189
/// - midiNote: MIDI note number (0-127)
190190
void setNoteCallback(
191-
std::function<void(float freqHz, int durationMs, int midiNote)> cb) {
191+
std::function<void(float freqHz, int durationMs, int midiNote, void*ref)> cb) {
192192
noteCallback = cb;
193193
}
194194

195+
// Provide reference for callback
196+
void setReference(void* ref) {
197+
reference = ref;
198+
}
199+
195200
protected:
196201
MusicalNotes m_notes;
197202
SoundGenerator<T>* p_generator = nullptr;
@@ -205,12 +210,13 @@ class RTTTLOutput : public AudioOutput {
205210
int m_duration{4};
206211
int m_bpm{120};
207212
float m_msec_semi{750};
208-
std::function<void(float, int, int)> noteCallback;
213+
void *reference = nullptr;
214+
std::function<void(float, int, int, void*)> noteCallback;
209215

210216
void play_note(float freq, int msec, int midi = -1) {
211217
// invoke the optional callback first
212218
LOGI("play_note: freq=%.2f Hz, msec=%d, midi=%d", freq, msec, midi);
213-
if (noteCallback) noteCallback(freq, msec, midi);
219+
if (noteCallback) noteCallback(freq, msec, midi, reference);
214220
if (p_print == nullptr || p_generator == nullptr) return;
215221
p_generator->setFrequency(freq);
216222
AudioInfo info = audioInfo();

0 commit comments

Comments
 (0)