diff --git a/SCClassLibrary/Common/Audio/bela/BELAUGens.sc b/SCClassLibrary/Common/Audio/bela/BELAUGens.sc index 79bd9fa7629..5ad86fdef26 100644 --- a/SCClassLibrary/Common/Audio/bela/BELAUGens.sc +++ b/SCClassLibrary/Common/Audio/bela/BELAUGens.sc @@ -92,3 +92,14 @@ DigitalIO : UGen { ^this.multiNew('control', digitalPin, output, pinMode ).madd(mul,add) } } + +/* input 1: max number of scope channels + * input 2: bus number + */ +BelaScopeUGen : UGen { + *ar { arg maxChannels, busnum; + ^super.performList('new1', 'audio', maxChannels, In.ar(busnum, maxChannels)); + } + numOutputs { ^0 } + writeOutputSpecs {} +} diff --git a/SCClassLibrary/Common/Audio/bela/BelaScope.sc b/SCClassLibrary/Common/Audio/bela/BelaScope.sc new file mode 100644 index 00000000000..eef7b5f3ef9 --- /dev/null +++ b/SCClassLibrary/Common/Audio/bela/BelaScope.sc @@ -0,0 +1,93 @@ +BelaScope { + + classvar 0) { maxChannels } { 8 }; + + if(serverScopes[server].isNil) { + serverScopes[server] = super.newCopyArgs(server, maxChannels).init; + }{ + // scope already exists, check maxChannels + }; + ^serverScopes[server]; + } + + scope { |channelOffset, signals| + + var ugens = signals.asArray.collect{ |item| + switch(item.rate) + { \audio }{ item } // pass + {\control}{ K2A.ar(item) } // convert kr to ar + {\scalar}{ + // convert numbers to ar UGens + if(item.isNumber) { DC.ar(item) } { nil } + } + { nil } + }; + + if(channelOffset + signals.size > this.maxChannels) { + "BelaScope: can't scope this signal, max number of channels (%) exceeded.\nSignal: %" + .format(this.maxChannels).warn; + ^signals; + }; + + if( ugens.every(_.isUGen) ){ + ^Out.ar(this.bus.index + channelOffset, ugens); + } { + "BelaScope: can't scope this signal, because not all of its elements are UGens.\nSignal: %" + .format(signals).warn; + ^signals + } + } + + init { + bootFunction = { this.prReserveScopeBus }; + treeFunction = { this.prStartScope }; + + ServerBoot.add(bootFunction, this.server); + ServerTree.add(treeFunction, this.server); + if(this.server.serverRunning){ + bootFunction.value(); + treeFunction.value(); + } + } + + prReserveScopeBus { + // TODO: check if bus is already reserved, or if maxChannels mismatch + bus = Bus.audio(server, maxChannels); + } + + prStartScope { + // TODO: check if node is already in place and running + node = { BelaScopeUGen.ar(this.maxChannels, this.bus); Silent.ar }.play(this.server, addAction: \addAfter); + } +} + ++ UGen { + belaScope { |scopeChannel, server| + ^BelaScope.scope(scopeChannel, this, server) + } +} + ++ Array { + belaScope { |scopeChannel, server| + ^BelaScope.scope(scopeChannel, this, server) + } +} diff --git a/server/plugins/BELAUGens.cpp b/server/plugins/BELAUGens.cpp index de8c902b702..9c3957be8f1 100644 --- a/server/plugins/BELAUGens.cpp +++ b/server/plugins/BELAUGens.cpp @@ -28,6 +28,7 @@ #include #include "Bela.h" +#include "libraries/Scope/Scope.h" // These functions are provided by xenomai int rt_printf(const char *format, ...); int rt_fprintf(FILE *stream, const char *format, ...); @@ -58,7 +59,7 @@ struct DigitalIn : public Unit int mDigitalPin; }; -// static digital pin, static function (out) - uses DigitalWrite and a check whether value changed +// static digital pin, static function (out) - uses DigitalWrite and a check whether value changed struct DigitalOut : public Unit { int mDigitalPin; @@ -80,10 +81,6 @@ struct DigitalIO : public Unit }; /* -struct BelaScope : public Unit -{ -}; - struct BelaScopeChannel : public Unit { int mScopeChannel; @@ -104,7 +101,7 @@ void MultiplexAnalogIn_next_aaa(MultiplexAnalogIn *unit, int inNumSamples) int analogPin = 0; int muxChannel = 0; float analogValue = 0; - + // context->audioFrames should be equal to inNumSamples // for(unsigned int n = 0; n < context->audioFrames; n++) { for(unsigned int n = 0; n < inNumSamples; n++) { @@ -138,7 +135,7 @@ void MultiplexAnalogIn_next_aak(MultiplexAnalogIn *unit, int inNumSamples) float *out = ZOUT(0); int analogPin = 0; float analogValue = 0; - + // context->audioFrames should be equal to inNumSamples // for(unsigned int n = 0; n < context->audioFrames; n++) { for(unsigned int n = 0; n < inNumSamples; n++) { @@ -171,7 +168,7 @@ void MultiplexAnalogIn_next_aka(MultiplexAnalogIn *unit, int inNumSamples) float *out = ZOUT(0); int muxChannel = 0; float analogValue = 0; - + // context->audioFrames should be equal to inNumSamples // for(unsigned int n = 0; n < context->audioFrames; n++) { for(unsigned int n = 0; n < inNumSamples; n++) { @@ -239,7 +236,7 @@ void MultiplexAnalogIn_next_kkk(MultiplexAnalogIn *unit, int inNumSamples) ZOUT0(0) = 0.0; } else if ( (muxChannel < 0) || ( muxChannel > context->multiplexerChannels) ) { rt_printf( "MultiplexAnalogIn warning: muxChannel must be between %i and %i, it is %i \n", 0, context->multiplexerChannels, muxChannel ); - ZOUT0(0) = 0.0; + ZOUT0(0) = 0.0; } else { ZOUT0(0) = multiplexerAnalogRead(context, analogPin, muxChannel); // is there something like NI? analogReadNI(context, 0, analogPin); } @@ -248,7 +245,7 @@ void MultiplexAnalogIn_next_kkk(MultiplexAnalogIn *unit, int inNumSamples) void MultiplexAnalogIn_Ctor(MultiplexAnalogIn *unit) { BelaContext *context = unit->mWorld->mBelaContext; - + if(context->analogFrames == 0 || context->analogFrames > context->audioFrames) { rt_printf("MultiplexAnalogIn Error: the UGen needs BELA analog enabled, with 4 or 8 channels\n"); return; @@ -259,7 +256,7 @@ void MultiplexAnalogIn_Ctor(MultiplexAnalogIn *unit) } // initiate first sample - MultiplexAnalogIn_next_kkk( unit, 1); + MultiplexAnalogIn_next_kkk( unit, 1); // set calculation method if (unit->mCalcRate == calc_FullRate) { if (INRATE(0) == calc_FullRate) { @@ -271,14 +268,14 @@ void MultiplexAnalogIn_Ctor(MultiplexAnalogIn *unit) } } else { if ( INRATE(1) == calc_FullRate ) { - SETCALC(MultiplexAnalogIn_next_aka); + SETCALC(MultiplexAnalogIn_next_aka); } else { // rt_printf("AnalogIn: ak\n"); SETCALC(MultiplexAnalogIn_next_akk); } } } else { - if ( (INRATE(0) == calc_FullRate) || (INRATE(1) == calc_FullRate) ) { + if ( (INRATE(0) == calc_FullRate) || (INRATE(1) == calc_FullRate) ) { rt_printf("MultiplexAnalogIn warning: output rate is control rate, so cannot change analog pin or multiplex channel at audio rate\n"); } // rt_printf("AnalogIn: kk\n"); @@ -298,7 +295,7 @@ void AnalogIn_next_aa(AnalogIn *unit, int inNumSamples) float *out = ZOUT(0); int analogPin = 0; float analogValue = 0; - + // context->audioFrames should be equal to inNumSamples // for(unsigned int n = 0; n < context->audioFrames; n++) { for(unsigned int n = 0; n < inNumSamples; n++) { @@ -361,7 +358,7 @@ void AnalogIn_next_kk(AnalogIn *unit, int inNumSamples) if ( (analogPin < 0) || (analogPin >= context->analogInChannels) ){ rt_printf( "AnalogIn warning: analog pin must be between %i and %i, it is %i \n", 0, context->analogInChannels, analogPin ); - ZOUT0(0) = 0.0; + ZOUT0(0) = 0.0; } else { ZOUT0(0) = analogReadNI(context, 0, analogPin); } @@ -370,14 +367,14 @@ void AnalogIn_next_kk(AnalogIn *unit, int inNumSamples) void AnalogIn_Ctor(AnalogIn *unit) { BelaContext *context = unit->mWorld->mBelaContext; - + if(context->analogFrames == 0 || context->analogFrames > context->audioFrames) { rt_printf("AnalogIn Error: the UGen needs BELA analog enabled, with 4 or 8 channels\n"); return; } // initiate first sample - AnalogIn_next_kk( unit, 1); + AnalogIn_next_kk( unit, 1); // set calculation method if (unit->mCalcRate == calc_FullRate) { if (INRATE(0) == calc_FullRate) { @@ -388,7 +385,7 @@ void AnalogIn_Ctor(AnalogIn *unit) SETCALC(AnalogIn_next_ak); } } else { - if (INRATE(0) == calc_FullRate) { + if (INRATE(0) == calc_FullRate) { rt_printf("AnalogIn warning: output rate is control rate, so cannot change analog pin at audio rate\n"); } // rt_printf("AnalogIn: kk\n"); @@ -406,7 +403,7 @@ void AnalogOut_next_aaa(AnalogOut *unit, int inNumSamples) float *fin = IN(0); // analog in pin, can be modulated float *in = IN(1); - + int analogPin = 0; float newinput = 0; for(unsigned int n = 0; n < inNumSamples; n++) { @@ -429,7 +426,7 @@ void AnalogOut_next_aka(AnalogOut *unit, int inNumSamples) int analogPin = (int) IN0(0); // analog in pin, can be modulated float *in = IN(1); - + float newinput = 0; if ( (analogPin < 0) || (analogPin >= context->analogOutChannels) ){ rt_printf( "AnalogOut warning: analog pin must be between %i and %i, it is %i \n", 0, context->analogOutChannels, analogPin ); @@ -449,7 +446,7 @@ void AnalogOut_next_aak(AnalogOut *unit, int inNumSamples) float *fin = IN(0); // analog in pin, can be modulated float in = IN0(1); - + int analogPin = 0; for(unsigned int n = 0; n < inNumSamples; n++) { // read input @@ -471,7 +468,7 @@ void AnalogOut_next_kk(AnalogOut *unit, int inNumSamples) int analogPin = (int) IN0(0); // analog in pin, can be modulated float in = IN0(1); - + if ( (analogPin < 0) || (analogPin >= context->analogOutChannels) ){ rt_printf( "AnalogOut warning: analog pin must be between %i and %i, it is %i \n", 0, context->analogOutChannels, analogPin ); } else { @@ -482,17 +479,17 @@ void AnalogOut_next_kk(AnalogOut *unit, int inNumSamples) void AnalogOut_Ctor(AnalogOut *unit) { BelaContext *context = unit->mWorld->mBelaContext; - + if(context->analogFrames == 0 ) { rt_printf("AnalogOut Error: the UGen needs BELA analog enabled\n"); return; } // initiate first sample - AnalogOut_next_kk( unit, 1); + AnalogOut_next_kk( unit, 1); if (unit->mCalcRate == calc_FullRate) { // ugen running at audio rate; - if (INRATE(0) == calc_FullRate) { // pin changed at audio rate + if (INRATE(0) == calc_FullRate) { // pin changed at audio rate if (INRATE(1) == calc_FullRate) { // output changed at audio rate SETCALC(AnalogOut_next_aaa); // rt_printf("AnalogOut: aaa\n"); @@ -531,11 +528,11 @@ void DigitalIn_next_a(DigitalIn *unit, int inNumSamples) int pinid = unit->mDigitalPin; int digitalValue; float *out = ZOUT(0); - + // context->audioFrames should be equal to inNumSamples // for(unsigned int n = 0; n < context->audioFrames; n++) { for(unsigned int n = 0; n < inNumSamples; n++) { - digitalValue=digitalRead(context, n, pinid); //read the value of the button + digitalValue=digitalRead(context, n, pinid); //read the value of the button *++out = (float) digitalValue; } } @@ -547,14 +544,14 @@ void DigitalIn_next_k(DigitalIn *unit, int inNumSamples) BelaContext *context = world->mBelaContext; int pinid = unit->mDigitalPin; - int digitalValue = digitalRead(context, 0, pinid); //read the value of the button - ZOUT0(0) = (float) digitalValue; + int digitalValue = digitalRead(context, 0, pinid); //read the value of the button + ZOUT0(0) = (float) digitalValue; } void DigitalIn_next_dummy_a(DigitalIn *unit, int inNumSamples) { float *out = ZOUT(0); - + for(unsigned int n = 0; n < inNumSamples; n++) { *++out = 0.0; } @@ -562,13 +559,13 @@ void DigitalIn_next_dummy_a(DigitalIn *unit, int inNumSamples) void DigitalIn_next_dummy_k(DigitalIn *unit, int inNumSamples) { - ZOUT0(0) = 0.0; + ZOUT0(0) = 0.0; } void DigitalIn_Ctor(DigitalIn *unit) { BelaContext *context = unit->mWorld->mBelaContext; - + float fDigitalIn = ZIN0(0); // digital in pin -- cannot change after construction unit->mDigitalPin = (int) fDigitalIn; // unit->mDigitalPin = (int) sc_clip( fDigitalIn, 0., 15.0 ); @@ -576,14 +573,14 @@ void DigitalIn_Ctor(DigitalIn *unit) rt_printf( "DigitalIn warning: digital pin must be between %i and %i, it is %i \n", 0, context->digitalChannels, unit->mDigitalPin ); // initiate first sample if (unit->mCalcRate == calc_FullRate) { // ugen running at audio rate; - DigitalIn_next_dummy_a( unit, 1); + DigitalIn_next_dummy_a( unit, 1); } else { - DigitalIn_next_dummy_k( unit, 1); + DigitalIn_next_dummy_k( unit, 1); } } else { pinMode(context, 0, unit->mDigitalPin, INPUT); // initiate first sample - DigitalIn_next_k( unit, 1); + DigitalIn_next_k( unit, 1); // set calculation method if (unit->mCalcRate == calc_FullRate) { // ugen running at audio rate; SETCALC(DigitalIn_next_a); @@ -593,7 +590,7 @@ void DigitalIn_Ctor(DigitalIn *unit) // rt_printf("DigitalIn: k\n"); } } - + } @@ -607,14 +604,14 @@ void DigitalOut_next_a_once(DigitalOut *unit, int inNumSamples) int pinid = unit->mDigitalPin; float *in = IN(1); - + float newinput = 0; //int lastOut = unit->mLastOut; for(unsigned int n = 0; n < inNumSamples; n++) { // read input newinput = in[n]; - if ( newinput > 0.5 ){ + if ( newinput > 0.5 ){ digitalWriteOnce(context, n, pinid, 1 ); } else { @@ -635,14 +632,14 @@ void DigitalOut_next_a(DigitalOut *unit, int inNumSamples) int pinid = unit->mDigitalPin; float *in = IN(1); - + float newinput = 0; int lastOut = unit->mLastOut; for(unsigned int n = 0; n < inNumSamples; n++) { // read input newinput = in[n]; - if ( newinput > 0.5 ){ + if ( newinput > 0.5 ){ if (lastOut == 0) { lastOut = 1; digitalWrite(context, n, pinid, 1 ); @@ -663,14 +660,14 @@ void DigitalOut_next_k(DigitalOut *unit, int inNumSamples) int pinid = unit->mDigitalPin; float in = IN0(1); - + int lastOut = unit->mLastOut; - if ( in > 0.5 ){ + if ( in > 0.5 ){ if (lastOut == 0) { lastOut = 1; digitalWrite(context, 0, pinid, 1 ); } - } + } else if ( lastOut == 1 ) { lastOut = 0; digitalWrite(context, 0, pinid, 0 ); @@ -697,8 +694,8 @@ void DigitalOut_Ctor(DigitalOut *unit) if ( (unit->mDigitalPin < 0) || (unit->mDigitalPin >= context->digitalChannels) ){ rt_printf( "DigitalOut warning: digital pin must be between %i and %i, it is %i \n", 0, context->digitalChannels, unit->mDigitalPin ); // initiate first sample - DigitalOut_next_dummy( unit, 1); - // set calculation method + DigitalOut_next_dummy( unit, 1); + // set calculation method SETCALC(DigitalOut_next_dummy); } else { pinMode(context, 0, unit->mDigitalPin, OUTPUT); @@ -741,10 +738,10 @@ void DigitalIO_next_aaaa_once(DigitalIO *unit, int inNumSamples) float *in = IN(1); // input value float *iomode = IN(2); // IO mode : < 0.5 = input, else output float *out = ZOUT(0); // output value = last output value - + int newpin; float newmode = 0; // input - + int newDigInInt = unit->mLastDigitalIn; float newDigIn = (float) newDigInInt; int newDigOut = unit->mLastDigitalOut; @@ -760,7 +757,7 @@ void DigitalIO_next_aaaa_once(DigitalIO *unit, int inNumSamples) if ( newmode < 0.5 ){ pinModeOnce( context, n, newpin, INPUT ); newDigInInt = digitalRead(context, n, newpin); - } else { + } else { pinModeOnce( context, n, newpin, OUTPUT ); digitalWriteOnce(context, n, newpin, newDigOut); } @@ -784,10 +781,10 @@ void DigitalIO_next_aaak_once(DigitalIO *unit, int inNumSamples) float *in = IN(1); // input value float iomode = IN0(2); // IO mode : < 0.5 = input, else output float *out = ZOUT(0); // output value = last output value - + int newDigInInt = unit->mLastDigitalIn; float newDigIn = (float) newDigInInt; - + int newDigOut = unit->mLastDigitalOut; // float newinput; @@ -816,7 +813,7 @@ void DigitalIO_next_aaak_once(DigitalIO *unit, int inNumSamples) } *++out = (float) newDigInInt; } - } + } unit->mLastDigitalIn = newDigInInt; unit->mLastDigitalOut = newDigOut; } @@ -832,10 +829,10 @@ void DigitalIO_next_aaka_once(DigitalIO *unit, int inNumSamples) float in = IN0(1); // input value float *iomode = IN(2); // IO mode : < 0.5 = input, else output float *out = ZOUT(0); // output value = last output value - + int newpin; float newmode = 0; // input - + int newDigInInt = unit->mLastDigitalIn; float newDigIn = (float) newDigInInt; // int newDigOut = unit->mLastDigitalOut; @@ -875,10 +872,10 @@ void DigitalIO_next_aakk_once(DigitalIO *unit, int inNumSamples) float in = IN0(1); // input value float iomode = IN0(2); // IO mode : < 0.5 = input, else output float *out = ZOUT(0); // output value = last output value - + int newpin; float newmode = 0; // input - + int newDigInInt = unit->mLastDigitalIn; float newDigIn = (float) newDigInInt; // int newDigOut = unit->mLastDigitalOut; @@ -907,10 +904,10 @@ void DigitalIO_next_aakk_once(DigitalIO *unit, int inNumSamples) } *++out = (float) newDigInInt; } - } + } unit->mLastDigitalIn = newDigInInt; unit->mLastDigitalOut = newDigOut; - + } @@ -925,14 +922,14 @@ void DigitalIO_next_akaa_once(DigitalIO *unit, int inNumSamples) float in = IN0(1); // input value float *iomode = IN(2); // IO mode : < 0.5 = input, else output float *out = ZOUT(0); // output value = last output value - + int newpin = (int) pinid; float newmode = 0; // input // float newinput; - + int newDigInInt = unit->mLastDigitalIn; float newDigIn = (float) newDigInInt; - + int newDigOut = (int) in; if ( (newpin < 0) || (newpin >= context->digitalChannels) ){ @@ -944,7 +941,7 @@ void DigitalIO_next_akaa_once(DigitalIO *unit, int inNumSamples) if ( newmode < 0.5 ){ pinModeOnce( context, n, newpin, INPUT ); newDigInInt = digitalRead(context, n, newpin); - } else { + } else { pinModeOnce( context, n, newpin, OUTPUT ); digitalWriteOnce(context, n, newpin, newDigOut); } @@ -967,14 +964,14 @@ void DigitalIO_next_akak_once(DigitalIO *unit, int inNumSamples) float *in = IN(1); // input value float iomode = IN0(2); // IO mode : < 0.5 = input, else output float *out = ZOUT(0); // output value = last output value - + int newpin = (int) pinid; float newmode = 0; // input // float newinput; - + int newDigInInt = unit->mLastDigitalIn; float newDigIn = (float) newDigInInt; - + int newDigOut = (int) in; if ( (newpin < 0) || (newpin >= context->digitalChannels) ){ @@ -997,7 +994,7 @@ void DigitalIO_next_akak_once(DigitalIO *unit, int inNumSamples) } } } - + unit->mLastDigitalIn = newDigInInt; unit->mLastDigitalOut = newDigOut; } @@ -1013,10 +1010,10 @@ void DigitalIO_next_akka_once(DigitalIO *unit, int inNumSamples) float in = IN0(1); // input value float *iomode = IN(2); // IO mode : < 0.5 = input, else output float *out = ZOUT(0); // output value = last output value - + int newpin = (int) pinid; float newinput = in; - + float newmode = 0; // input int newDigInInt = unit->mLastDigitalIn; @@ -1025,7 +1022,7 @@ void DigitalIO_next_akka_once(DigitalIO *unit, int inNumSamples) if ( (newpin < 0) || (newpin >= context->digitalChannels) ){ rt_printf( "DigitalIO warning: digital pin must be between %i and %i, it is %i \n", 0, context->digitalChannels, newpin ); } - + for(unsigned int n = 0; n < inNumSamples; n++) { newmode = iomode[n]; if ( newmode < 0.5 ){ // digital read @@ -1033,9 +1030,9 @@ void DigitalIO_next_akka_once(DigitalIO *unit, int inNumSamples) newDigInInt = digitalRead(context, n, newpin); } else { // digital write pinModeOnce( context, n, newpin, OUTPUT ); - if ( newinput > 0.5 ){ + if ( newinput > 0.5 ){ newDigOut = 1; - } else { + } else { newDigOut = 0; } digitalWriteOnce(context, n, newpin, newDigOut); @@ -1059,9 +1056,9 @@ void DigitalIO_next_ak(DigitalIO *unit, int inNumSamples) float in = IN0(1); // input value float iomode = IN0(2); // IO mode : < 0.5 = input, else output float *out = ZOUT(0); // output value = last output value - + int newpin = (int) pinid; - + int newDigInInt = unit->mLastDigitalIn; float newDigIn = (float) newDigInInt; int newDigOut = (int) in; @@ -1077,12 +1074,12 @@ void DigitalIO_next_ak(DigitalIO *unit, int inNumSamples) // always write to the output of the UGen *++out = (float) newDigInInt; } - } else { + } else { pinMode( context, 0, newpin, OUTPUT ); for(unsigned int n = 0; n < inNumSamples; n++) { - if ( in > 0.5 ){ + if ( in > 0.5 ){ newDigOut = 1; - } else { + } else { newDigOut = 0; } digitalWriteOnce(context, n, newpin, newDigOut); @@ -1106,7 +1103,7 @@ void DigitalIO_next_kk(DigitalIO *unit, int inNumSamples) float in = IN0(1); // input value float iomode = IN0(2); // IO mode : < 0.5 = input, else output // float *out = ZOUT(0); // output value = last output value - + int newDigInInt = unit->mLastDigitalIn; int newDigOut = unit->mLastDigitalOut; @@ -1116,11 +1113,11 @@ void DigitalIO_next_kk(DigitalIO *unit, int inNumSamples) if ( iomode < 0.5 ){ pinMode( context, 0, pinid, INPUT ); newDigInInt = digitalRead(context, 0, pinid); - } else { + } else { pinMode( context, 0, pinid, OUTPUT ); - if ( in > 0.5 ){ + if ( in > 0.5 ){ newDigOut = 1; - } else { + } else { newDigOut = 0; } digitalWrite(context, 0, pinid, newDigOut); @@ -1130,7 +1127,7 @@ void DigitalIO_next_kk(DigitalIO *unit, int inNumSamples) unit->mLastDigitalIn = newDigInInt; unit->mLastDigitalOut = newDigOut; - + } /* @@ -1144,7 +1141,7 @@ void DigitalIO_next(DigitalIO *unit, int inNumSamples) float *in = IN(1); // input value float *iomode = IN(2); // IO mode : < 0.5 = input, else output float *out = ZOUT(0); // output value = last output value - + int newpin; float newmode = 0; // input float newinput = 0; @@ -1165,12 +1162,12 @@ void DigitalIO_next(DigitalIO *unit, int inNumSamples) // pinModeOnce( context, n, newpin, INPUT ); pinMode( context, n, newpin, INPUT ); newoutput = digitalRead(context, n, newpin); - } else { + } else { // pinModeOnce( context, n, newpin, OUTPUT ); pinMode( context, n, newpin, OUTPUT ); - if ( newinput > 0.5 ){ + if ( newinput > 0.5 ){ newinputInt = 1; - } else { + } else { newinputInt = 0; } // digitalWriteOnce(context, n, newpin, newinputInt); @@ -1193,9 +1190,9 @@ void DigitalIO_Ctor(DigitalIO *unit) unit->mLastDigitalOut = 0; // int writeMode = (int) ZIN0(3); // method of writing; 1 = writeOnce; 0 = write on change - + // initiate first sample - DigitalIO_next_kk( unit, 1); + DigitalIO_next_kk( unit, 1); // set calculation method // SETCALC(DigitalIO_next); if (unit->mCalcRate == calc_FullRate) { // ugen running at audio rate; @@ -1275,11 +1272,15 @@ void DigitalIO_Ctor(DigitalIO *unit) ////////////////////////////////////////////////////////////////////////////////////////////////// -/* -int noScopeChannels = 0; -Scope * belaScope; +struct BelaScopeUGen : public Unit +{ + Scope* belaScope; + float* frameData; + unsigned int noScopeChannels = 0; +}; +/* void BelaScopeChannel_next( BelaScope *unit ) { int scopeChannel = unit->mScopeChannel; @@ -1289,12 +1290,12 @@ void BelaScopeChannel_next( BelaScope *unit ) belaScope->logChannel( scopeChannel, in[n] ); } } - + void BelaScopeChannel_Ctor(BelaScope *unit) { BelaContext *context = unit->mWorld->mBelaContext; - + // belaScope = Scope(); // which channel is an input variable // belaScope->setup(3, context->audioSampleRate); @@ -1305,53 +1306,60 @@ void BelaScopeChannel_Ctor(BelaScope *unit) // error } // initiate first sample - - BelaScopeChannel_next( unit, 1); + + BelaScopeChannel_next( unit, 1); // set calculation method SETCALC(BelaScopeChannel_next); } - -void BelaScope_next(BelaScope *unit) +*/ +void BelaScopeUGen_next(BelaScopeUGen *unit, unsigned int numSamples) { + unsigned int numChannels = unit->noScopeChannels; + float *frameData = unit->frameData; + float *inputPointers[numChannels]; + for(unsigned int ch = 0; ch < numChannels; ++ch) + inputPointers[ch] = ZIN(ch+1); + + LOOP1(numSamples, + for(unsigned int ch = 0; ch < numChannels; ++ch) + frameData[ch] = ZXP(inputPointers[ch]);//*(IN(1+ch)+n); + unit->belaScope->log(frameData); + ) } -void BelaScope_Ctor(BelaScope *unit) +void BelaScopeUGen_Ctor(BelaScopeUGen *unit) { BelaContext *context = unit->mWorld->mBelaContext; - - float fChan = ZIN0(0); // number of channels - noScopeChannels = (int) fChan; - - belaScope = Scope(); - // number of channels is a variable - belaScope->setup(noScopeChannels, context->audioSampleRate); - + unsigned int numChannels = static_cast(IN0(0)); + unit->frameData = (float*) RTAlloc(unit->mWorld, sizeof(float)*numChannels); + unit->belaScope = new Scope(); + unit->belaScope->setup(numChannels, context->audioSampleRate); + unit->noScopeChannels = numChannels; // initiate first sample - BelaScope_next( unit, 1); + BelaScopeUGen_next( unit, 1); // set calculation method - SETCALC(BelaScope_next); + SETCALC(BelaScopeUGen_next); } -void BelaScope_Dtor(BelaScope *unit) +void BelaScopeUGen_Dtor(BelaScopeUGen *unit) { - belaScope->stop(); - delete belaScope; - noScopeChannels = 0; + unit->belaScope->cleanup(); + delete unit->belaScope; + RTFree(unit->mWorld, unit->frameData); } -*/ ////////////////////////////////////////////////////////////////////////////////////////////////// // extern "C" // { -// -// +// +// // } // // the functions below are needed?? -// +// // void render(BelaContext *belaContext, void *userData) // { // // SC_BelaDriver *driver = (SC_BelaDriver*)userData; @@ -1371,10 +1379,10 @@ void BelaScope_Dtor(BelaScope *unit) // printf("BelaPLUGINS: error, setup() got no user data\n"); // return false; // } -// +// // return true; // } -// +// // // cleanup() is called once at the end, after the audio has stopped. // // Release any resources that were allocated in setup(). // void cleanup(BelaContext *belaContext, void *userData) @@ -1392,10 +1400,11 @@ PluginLoad(BELA) DefineSimpleUnit(DigitalIn); DefineSimpleUnit(DigitalOut); DefineSimpleUnit(DigitalIO); + DefineDtorUnit(BelaScopeUGen); } // C_LINKAGE SC_API_EXPORT void unload(InterfaceTable *inTable) // { -// +// // } diff --git a/server/plugins/CMakeLists.txt b/server/plugins/CMakeLists.txt index 0b17c6b2968..648b03510ff 100644 --- a/server/plugins/CMakeLists.txt +++ b/server/plugins/CMakeLists.txt @@ -99,13 +99,14 @@ if (BELA_FOUND) add_definitions("-DBELA" ${XENOMAI_DEFINITIONS} ${BELA_DEFINITIONS}) include_directories(${XENOMAI_INCLUDE_DIRS}) include_directories(${BELA_INCLUDE_DIRS}) + include_directories(${BELA_INCLUDE_DIRS}/../) # set(CMAKE_EXECUTABLE_RUNTIME_C_FLAG "-Wl,-wrap,clock_gettime,-rpath,") # set(CMAKE_EXECUTABLE_RUNTIME_CXX_FLAG "-Wl,-wrap,clock_gettime,-rpath,") # set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-wrap,clock_gettime,-rpath,") # set(CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG "-Wl,-wrap,clock_gettime,-rpath,") # target_link_libraries(BELAUGens ${XENOMAI_LIBRARIES} ${BELA_LIBRARIES} libscsynth.a) - target_link_libraries(BELAUGens libscsynth) + target_link_libraries(BELAUGens ${BELA_LIBRARIES} belaextra libscsynth) list(APPEND plugins BELAUGens) endif()