Mercurial > hg > beaglert
comparison projects/basic_midi/render.cpp @ 226:af1e662400fc mergingClockSync
Added argument to callback
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Sun, 13 Mar 2016 03:31:19 +0000 |
parents | 97faaf985164 |
children |
comparison
equal
deleted
inserted
replaced
225:444f6028d6b1 | 226:af1e662400fc |
---|---|
16 float gPhaseIncrement = 0; | 16 float gPhaseIncrement = 0; |
17 bool gIsNoteOn = 0; | 17 bool gIsNoteOn = 0; |
18 int gVelocity = 0; | 18 int gVelocity = 0; |
19 float gSamplingPeriod = 0; | 19 float gSamplingPeriod = 0; |
20 | 20 |
21 void midiMessageCallback(MidiChannelMessage message){ | 21 void midiMessageCallback(MidiChannelMessage message, void* arg){ |
22 if(arg != NULL){ | |
23 rt_printf("Message from midi port %d: ", *(int*)arg); | |
24 } | |
22 message.prettyPrint(); | 25 message.prettyPrint(); |
23 if(message.getType() == kmmNoteOn){ | 26 if(message.getType() == kmmNoteOn){ |
24 gFreq = powf(2, (message.getDataByte(0)-69)/12.0f) * 440; | 27 gFreq = powf(2, (message.getDataByte(0)-69)/12.0f) * 440; |
25 gVelocity = message.getDataByte(1); | 28 gVelocity = message.getDataByte(1); |
26 gPhaseIncrement = 2 * M_PI * gFreq * gSamplingPeriod; | 29 gPhaseIncrement = 2 * M_PI * gFreq * gSamplingPeriod; |
35 // userData holds an opaque pointer to a data structure that was passed | 38 // userData holds an opaque pointer to a data structure that was passed |
36 // in from the call to initAudio(). | 39 // in from the call to initAudio(). |
37 // | 40 // |
38 // Return true on success; returning false halts the program. | 41 // Return true on success; returning false halts the program. |
39 Midi midi; | 42 Midi midi; |
43 int gMidiPort0 = 0; | |
40 bool setup(BeagleRTContext *context, void *userData) | 44 bool setup(BeagleRTContext *context, void *userData) |
41 { | 45 { |
42 midi.readFrom(0); | 46 midi.readFrom(gMidiPort0); |
43 midi.writeTo(0); | 47 midi.writeTo(gMidiPort0); |
44 midi.enableParser(true); | 48 midi.enableParser(true); |
45 midi.setParserCallback(midiMessageCallback); | 49 midi.setParserCallback(midiMessageCallback, &gMidiPort0); |
46 if(context->analogFrames == 0) { | 50 if(context->analogFrames == 0) { |
47 rt_printf("Error: this example needs the matrix enabled\n"); | 51 rt_printf("Error: this example needs the analog I/O to be enabled\n"); |
48 return false; | 52 return false; |
49 } | 53 } |
50 gSamplingPeriod = 1/context->audioSampleRate; | 54 gSamplingPeriod = 1/context->audioSampleRate; |
51 return true; | 55 return true; |
52 } | 56 } |