Mercurial > hg > beaglert
changeset 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 | 265a527f8be8 |
children | b128e3ea84ff |
files | projects/heavy/pd/hello-midi/_main.pd projects/heavy/pd/hello-midi/hv_ctlin.pd projects/heavy/pd/hello-midi/hv_notein.pd projects/heavy/pd/hello-midi/hv_pgmin.pd scripts/hvresources/render.cpp |
diffstat | 5 files changed, 304 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/projects/heavy/pd/hello-midi/_main.pd Fri Feb 05 06:17:35 2016 +0000 @@ -0,0 +1,66 @@ +#N canvas 1 58 1351 685 10; +#X obj 19 396 dac~ 1 2; +#X text 39 1 Hello world!; +#X text 37 11 ============; +#X obj 31 353 *~ 0.1; +#X text 329 309 ---------------------------------; +#X text 329 299 @krighxz / BELA / heavy / 12/2015; +#X text 353 318 beaglert.cc / enzienaudio.com; +#X obj 39 116 mtof; +#X text 140 29 <== the heavy equivalent of ==>; +#X obj 331 28 notein; +#X floatatom 79 59 5 0 0 0 - - -; +#X floatatom 122 59 5 0 0 0 - - -; +#X floatatom 41 63 5 0 0 0 - - -; +#X obj 59 328 / 127; +#X obj 38 147 phasor~ 440; +#X text 100 363 (the harsh sound of success); +#X obj 88 192 lop~ 20; +#X obj 256 74 * 20; +#X obj 257 103 + 200; +#X obj 29 224 vcf~ 1; +#X obj 132 85 loadbang; +#X msg 131 111 1000; +#X obj 125 166 sig~; +#X text 483 121 <== the heavy equivalent of ==>; +#X text 359 64 <== the heavy equivalent of ==>; +#X obj 557 64 ctlin; +#X text 682 122 [pgmin]; +#X obj 218 209 + 50; +#X obj 218 178 * 10; +#X obj 30 250 hip~; +#X obj 26 275 hip~; +#X obj 20 302 hip~; +#X obj 19 323 hip~; +#X obj 40 28 hv_notein 0; +#X obj 408 122 hv_pgmin 3; +#X obj 256 51 hv_ctlin 5 0; +#X obj 220 151 hv_ctlin 6 0; +#X connect 3 0 0 1; +#X connect 3 0 0 0; +#X connect 7 0 14 0; +#X connect 10 0 13 0; +#X connect 12 0 7 0; +#X connect 13 0 3 1; +#X connect 14 0 19 0; +#X connect 16 0 19 1; +#X connect 17 0 18 0; +#X connect 18 0 22 0; +#X connect 19 0 29 0; +#X connect 20 0 21 0; +#X connect 21 0 22 0; +#X connect 22 0 16 0; +#X connect 27 0 29 1; +#X connect 27 0 30 1; +#X connect 27 0 31 1; +#X connect 27 0 32 1; +#X connect 28 0 27 0; +#X connect 29 0 30 0; +#X connect 30 0 31 0; +#X connect 31 0 32 0; +#X connect 32 0 3 0; +#X connect 33 0 12 0; +#X connect 33 1 10 0; +#X connect 33 2 11 0; +#X connect 35 0 17 0; +#X connect 36 0 28 0;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/projects/heavy/pd/hello-midi/hv_ctlin.pd Fri Feb 05 06:17:35 2016 +0000 @@ -0,0 +1,84 @@ +#N canvas 554 204 703 475 10; +#X obj -107 -439 outlet; +#X obj -52 -441 outlet; +#X obj -61 -743 r ctlin; +#X obj -68 -719 unpack f f f; +#X obj -6 -441 outlet; +#X obj -74 -548 spigot; +#X text -109 -420 value; +#X text -55 -420 number; +#X obj 51 -732 loadbang; +#X obj 17 -677 \$1; +#X obj -34 -656 == \$1; +#X obj -41 -571 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 +0 1; +#X obj -76 -521 unpack f f f; +#X obj -17 -623 ||; +#X obj 17 -653 == 0; +#X text -90 -859 Emulates ctlin \, except number of outlets is fixed. +; +#X obj 68 -623 ||; +#X obj 102 -653 == 0; +#X obj 52 -656 == \$2; +#X obj 102 -677 \$2; +#X obj 17 -593 &&; +#X obj 51 -707 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 +-1 -1; +#X text 13 -571 If (inputController==\$1 || \$1==0) && (inputChannel==\$2 +|| \$2==0); +#X text 37 -818 Known issue: trying to select inputController 0 will +result i accepting all controllers (because a pd external cannot tell +the difference between \$1 been explicitely set to 0 and the patch +not having any argument); +#X text 2 -420 channel; +#X obj -104 -678 pack f f f; +#X obj -80 -462 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 +-1 -1; +#X floatatom -79 -488 5 0 0 0 - - -; +#X obj -39 -458 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 +-1 -1; +#X floatatom -38 -484 5 0 0 0 - - -; +#X obj 12 -464 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 +-1 -1; +#X floatatom 13 -490 5 0 0 0 - - -; +#X msg -44 -818 1 2 3; +#X msg -6 -805 1 5 7; +#X msg -97 -815 1 5 6; +#X msg -100 -776 1 4 7; +#X obj -96 -841 r hv_ctlin; +#X obj -38 -778 s ctlin; +#X connect 2 0 3 0; +#X connect 3 0 25 0; +#X connect 3 1 10 0; +#X connect 3 1 25 1; +#X connect 3 2 18 0; +#X connect 3 2 25 2; +#X connect 5 0 12 0; +#X connect 8 0 21 0; +#X connect 9 0 14 0; +#X connect 10 0 13 0; +#X connect 11 0 5 1; +#X connect 12 0 0 0; +#X connect 12 0 27 0; +#X connect 12 1 1 0; +#X connect 12 1 29 0; +#X connect 12 2 4 0; +#X connect 12 2 31 0; +#X connect 13 0 20 0; +#X connect 14 0 13 1; +#X connect 16 0 20 1; +#X connect 17 0 16 1; +#X connect 18 0 16 0; +#X connect 19 0 17 0; +#X connect 20 0 11 0; +#X connect 21 0 9 0; +#X connect 21 0 19 0; +#X connect 25 0 5 0; +#X connect 27 0 26 0; +#X connect 29 0 28 0; +#X connect 31 0 30 0; +#X connect 32 0 37 0; +#X connect 33 0 37 0; +#X connect 34 0 37 0; +#X connect 35 0 37 0; +#X connect 36 0 37 0;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/projects/heavy/pd/hello-midi/hv_notein.pd Fri Feb 05 06:17:35 2016 +0000 @@ -0,0 +1,63 @@ +#N canvas 730 58 629 685 10; +#X obj 84 -361 outlet; +#X obj 155 -367 outlet; +#X obj 131 -658 unpack f f f; +#X obj 211 -370 outlet; +#X obj 133 -477 spigot; +#X obj 258 -661 loadbang; +#X obj 224 -606 \$1; +#X obj 173 -585 == \$1; +#X obj 166 -500 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 +0 1; +#X obj 133 -450 unpack f f f; +#X obj 190 -552 ||; +#X obj 224 -582 == 0; +#X obj 258 -636 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 +-1 -1; +#X text 150 -777 Emulates notein \, except number of outlets is fixed. +; +#X text 82 -343 notenumber; +#X text 151 -353 velocity; +#X text 210 -356 channel; +#X text 219 -531 If (inputChannel==\$1 || \$1==0); +#X msg 50 -758 123 46 3; +#X obj 105 -610 pack f f f; +#X msg 8 -739 123 46 2; +#X obj 72 -414 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 +-1 -1; +#X floatatom 74 -432 5 0 0 0 - - -; +#X obj 135 -394 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 +-1 -1; +#X floatatom 137 -412 5 0 0 0 - - -; +#X obj 188 -391 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 +-1 -1; +#X floatatom 190 -409 5 0 0 0 - - -; +#X obj 121 -730 s notein; +#X obj 130 -693 r notein; +#X obj 125 -758 r hv_notein; +#X connect 2 0 19 0; +#X connect 2 1 19 1; +#X connect 2 2 7 0; +#X connect 2 2 19 2; +#X connect 4 0 9 0; +#X connect 5 0 12 0; +#X connect 6 0 11 0; +#X connect 7 0 10 0; +#X connect 8 0 4 1; +#X connect 9 0 0 0; +#X connect 9 0 22 0; +#X connect 9 1 1 0; +#X connect 9 1 24 0; +#X connect 9 2 3 0; +#X connect 9 2 26 0; +#X connect 10 0 8 0; +#X connect 11 0 10 1; +#X connect 12 0 6 0; +#X connect 18 0 27 0; +#X connect 19 0 4 0; +#X connect 20 0 27 0; +#X connect 22 0 21 0; +#X connect 24 0 23 0; +#X connect 26 0 25 0; +#X connect 28 0 2 0; +#X connect 29 0 27 0;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/projects/heavy/pd/hello-midi/hv_pgmin.pd Fri Feb 05 06:17:35 2016 +0000 @@ -0,0 +1,57 @@ +#N canvas 623 197 587 546 10; +#X obj 108 68 outlet; +#X obj 209 66 outlet; +#X obj 141 -41 spigot; +#X obj 232 -219 loadbang; +#X obj 232 -170 \$1; +#X obj 181 -149 == \$1; +#X obj 174 -64 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0 +1; +#X obj 198 -116 ||; +#X obj 232 -146 == 0; +#X obj 232 -194 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 +-1 -1; +#X obj 124 -234 unpack f f; +#X obj 141 -13 unpack f f; +#X text 87 91 program number; +#X text 217 87 channel; +#X text 228 -64 If (channel==\$1 || \$1==0); +#X text 202 -300 emulates pgmin except it always has 2 outlets and +requires the input parameters to be explicitely set. Set them to 0 +to avoid filtering; +#X text 297 -213 It'd be nicer with [t l l] but have to compensate +for the fact that it is not supported by heavy; +#X obj 112 -162 pack f f; +#X floatatom 107 10 5 0 0 0 - - -; +#X msg 80 -270 2 3; +#X msg 63 -292 2 1; +#X obj 98 34 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 +-1; +#X floatatom 185 16 5 0 0 0 - - -; +#X obj 176 40 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 +-1; +#X obj 124 -303 r hv_pgmin; +#X obj 126 -282 s pgmin; +#X obj 128 -258 r pgmin; +#X connect 2 0 11 0; +#X connect 3 0 9 0; +#X connect 4 0 8 0; +#X connect 5 0 7 0; +#X connect 6 0 2 1; +#X connect 7 0 6 0; +#X connect 8 0 7 1; +#X connect 9 0 4 0; +#X connect 10 0 17 0; +#X connect 10 1 5 0; +#X connect 10 1 17 1; +#X connect 11 0 0 0; +#X connect 11 0 18 0; +#X connect 11 1 1 0; +#X connect 11 1 22 0; +#X connect 17 0 2 0; +#X connect 18 0 21 0; +#X connect 19 0 25 0; +#X connect 20 0 25 0; +#X connect 22 0 23 0; +#X connect 24 0 25 0; +#X connect 26 0 10 0;
--- a/scripts/hvresources/render.cpp Fri Feb 05 06:16:35 2016 +0000 +++ b/scripts/hvresources/render.cpp Fri Feb 05 06:17:35 2016 +0000 @@ -12,13 +12,13 @@ */ #include <BeagleRT.h> +#include <Midi.h> #include <cmath> #include "../include/Utilities.h" #include "Heavy_bbb.h" #include <string.h> #include <stdlib.h> #include <string.h> - /* * HEAVY CONTEXT & BUFFERS */ @@ -53,6 +53,7 @@ * SETUP, RENDER LOOP & CLEANUP */ +Midi midi; bool setup(BeagleRTContext *context, void *userData) { /* HEAVY */ @@ -79,6 +80,9 @@ // Set heavy send hook hv_setSendHook(gHeavyContext, sendHook); + midi.readFrom(0); + midi.writeTo(0); + midi.enableParser(true); return true; } @@ -111,6 +115,35 @@ // replacement for bang~ object //hv_vscheduleMessageForReceiver(gHeavyContext, "bbb_bang", 0.0f, "b"); + { + int num; + while((num = midi.getParser()->numAvailableMessages()) > 0){ + static MidiChannelMessage message; + message = midi.getParser()->getNextChannelMessage(); + switch(message.getType()){ + case kmmNoteOn: { +// message.prettyPrint(); + float noteNumber = message.getDataByte(0); + float velocity = message.getDataByte(1); + float channel = message.getChannel(); +// rt_printf("message: noteNumber: %f, velocity: %f, channel: %f\n", noteNumber, velocity, channel); + hv_vscheduleMessageForReceiver(gHeavyContext, "hv_notein", 0, "fff", noteNumber, velocity, channel); + } + break; + case kmmControlChange: { + hv_vscheduleMessageForReceiver(gHeavyContext, "hv_ctlin", 0, "fff", + (float)message.getDataByte(1), (float)message.getDataByte(0), (float)message.getChannel()); + } + break; + case kmmProgramChange: + hv_vscheduleMessageForReceiver(gHeavyContext, "hv_pgmin", 0, "ff", + (float)message.getDataByte(0), (float)message.getChannel()); + break; + } + } + } +// hv_sendFloatToReceiver(gHeavyContext, "notein", 1.123f); + hv_bbb_process_inline(gHeavyContext, gHvInputBuffers, gHvOutputBuffers, context->audioFrames);