comparison scripts/hvresources/render.cpp @ 198:62f6269f4b3e

Added support for MidiIn to heavy (with example patch and subpatches).
author Giulio Moro <giuliomoro@yahoo.it>
date Fri, 05 Feb 2016 06:17:35 +0000
parents 3b8a28edae41
children c768ed1055b0
comparison
equal deleted inserted replaced
197:265a527f8be8 198:62f6269f4b3e
10 * Christian Heinrichs 10 * Christian Heinrichs
11 * 11 *
12 */ 12 */
13 13
14 #include <BeagleRT.h> 14 #include <BeagleRT.h>
15 #include <Midi.h>
15 #include <cmath> 16 #include <cmath>
16 #include "../include/Utilities.h" 17 #include "../include/Utilities.h"
17 #include "Heavy_bbb.h" 18 #include "Heavy_bbb.h"
18 #include <string.h> 19 #include <string.h>
19 #include <stdlib.h> 20 #include <stdlib.h>
20 #include <string.h> 21 #include <string.h>
21
22 /* 22 /*
23 * HEAVY CONTEXT & BUFFERS 23 * HEAVY CONTEXT & BUFFERS
24 */ 24 */
25 25
26 Hv_bbb *gHeavyContext; 26 Hv_bbb *gHeavyContext;
51 51
52 /* 52 /*
53 * SETUP, RENDER LOOP & CLEANUP 53 * SETUP, RENDER LOOP & CLEANUP
54 */ 54 */
55 55
56 Midi midi;
56 bool setup(BeagleRTContext *context, void *userData) { 57 bool setup(BeagleRTContext *context, void *userData) {
57 58
58 /* HEAVY */ 59 /* HEAVY */
59 60
60 gHeavyContext = hv_bbb_new(context->audioSampleRate); 61 gHeavyContext = hv_bbb_new(context->audioSampleRate);
77 // Set heavy print hook 78 // Set heavy print hook
78 hv_setPrintHook(gHeavyContext, &printHook); 79 hv_setPrintHook(gHeavyContext, &printHook);
79 // Set heavy send hook 80 // Set heavy send hook
80 hv_setSendHook(gHeavyContext, sendHook); 81 hv_setSendHook(gHeavyContext, sendHook);
81 82
83 midi.readFrom(0);
84 midi.writeTo(0);
85 midi.enableParser(true);
82 return true; 86 return true;
83 } 87 }
84 88
85 89
86 void render(BeagleRTContext *context, void *userData) 90 void render(BeagleRTContext *context, void *userData)
109 } 113 }
110 } 114 }
111 115
112 // replacement for bang~ object 116 // replacement for bang~ object
113 //hv_vscheduleMessageForReceiver(gHeavyContext, "bbb_bang", 0.0f, "b"); 117 //hv_vscheduleMessageForReceiver(gHeavyContext, "bbb_bang", 0.0f, "b");
118 {
119 int num;
120 while((num = midi.getParser()->numAvailableMessages()) > 0){
121 static MidiChannelMessage message;
122 message = midi.getParser()->getNextChannelMessage();
123 switch(message.getType()){
124 case kmmNoteOn: {
125 // message.prettyPrint();
126 float noteNumber = message.getDataByte(0);
127 float velocity = message.getDataByte(1);
128 float channel = message.getChannel();
129 // rt_printf("message: noteNumber: %f, velocity: %f, channel: %f\n", noteNumber, velocity, channel);
130 hv_vscheduleMessageForReceiver(gHeavyContext, "hv_notein", 0, "fff", noteNumber, velocity, channel);
131 }
132 break;
133 case kmmControlChange: {
134 hv_vscheduleMessageForReceiver(gHeavyContext, "hv_ctlin", 0, "fff",
135 (float)message.getDataByte(1), (float)message.getDataByte(0), (float)message.getChannel());
136 }
137 break;
138 case kmmProgramChange:
139 hv_vscheduleMessageForReceiver(gHeavyContext, "hv_pgmin", 0, "ff",
140 (float)message.getDataByte(0), (float)message.getChannel());
141 break;
142 }
143 }
144 }
145 // hv_sendFloatToReceiver(gHeavyContext, "notein", 1.123f);
146
114 147
115 hv_bbb_process_inline(gHeavyContext, gHvInputBuffers, gHvOutputBuffers, context->audioFrames); 148 hv_bbb_process_inline(gHeavyContext, gHvInputBuffers, gHvOutputBuffers, context->audioFrames);
116 149
117 // Interleave the output data 150 // Interleave the output data
118 if(gHvOutputBuffers != NULL) { 151 if(gHvOutputBuffers != NULL) {