diff --git a/flash/programs/alan.b b/flash/programs/alan.b index 75faf7e..4c10824 100644 --- a/flash/programs/alan.b +++ b/flash/programs/alan.b @@ -3,29 +3,41 @@ { "name" : "Alanesque", - "description" : "blah blah", - "devices" : [ - - { - "type" : "VariableClock", - "id" : "vclock", - "minTempo" : 20, - "maxTempo" : 240, - "analogInput" : 1, - "ticksPerMeasure" : 16 - }, + "clock" : + + { + "type" : "VariableClock", + "minTempo" : 30, + "maxTempo" : 240, + "tempoInput" : 1, + "beats" : 16 + }, + + + "devices" : [ { "type" : "RandomLoopingShiftRegister", - "id" : "shiftregister", - "clock" : "vclock", - - + "size" : 32, + "division" : "sixteenth", + "controlInput" : 2, + "analogOutput" : 15, + "delayedOutput" : 16, + "delay" : 12, + "triggerOutput1" : 5, + "triggerOutput2" : 6, + "triggerOutput3" : 7, + "triggerOutput4" : 8, + "triggerOutput5" : 9, + "triggerOutput6" : 10, + "triggerOutput7" : 11, + "triggerOutput8" : 12, + "logicalAND1" : 13, + "logicalAND2" : 14, + "logicalAND3" : 15, + "logicalAND4" : 16 } - - ] - } } \ No newline at end of file diff --git a/flash/programs/varclock.b b/flash/programs/varclock.b index 9621361..3b8ed90 100644 --- a/flash/programs/varclock.b +++ b/flash/programs/varclock.b @@ -2,15 +2,16 @@ "program" : { - "name" : "Random Tempo Clock Demo 1", + "name" : "Variable Tempo Clock Demo 1", "clock" : { - "type" : "RandomTempoClock", - "minTempo" : 30, - "maxTempo" : 240, - "beats" : 16 + "type" : "VariableClock", + "minTempo" : 30, + "maxTempo" : 240, + "tempoInput" : 1, + "beats" : 16 }, "devices" : [ diff --git a/sketches/libraries/nw2s/JSONUtil.cpp b/sketches/libraries/nw2s/JSONUtil.cpp index 191f69f..be81243 100644 --- a/sketches/libraries/nw2s/JSONUtil.cpp +++ b/sketches/libraries/nw2s/JSONUtil.cpp @@ -90,6 +90,13 @@ PinAnalogOut nw2s::getAnalogOutputFromJSON(aJsonObject* data) } +PinAnalogOut nw2s::getAnalogOutputFromJSON(aJsonObject* data, const char* nodeName) +{ + int val = getIntFromJSON(data, nodeName, 0, 1, 16); + + return INDEX_ANALOG_OUT[val]; +} + PinAnalogIn nw2s::getAnalogInputFromJSON(aJsonObject* data) { static const char nodeName[] = "analogInput"; diff --git a/sketches/libraries/nw2s/JSONUtil.h b/sketches/libraries/nw2s/JSONUtil.h index a6e577f..eec43c6 100644 --- a/sketches/libraries/nw2s/JSONUtil.h +++ b/sketches/libraries/nw2s/JSONUtil.h @@ -36,6 +36,7 @@ namespace nw2s */ PinAudioOut getAudioOutputFromJSON(aJsonObject* data); + PinAnalogOut getAnalogOutputFromJSON(aJsonObject* data, const char* nodeName); PinAnalogOut getAnalogOutputFromJSON(aJsonObject* data); PinAnalogIn getAnalogInputFromJSON(aJsonObject* data); PinAnalogIn getAnalogInputFromJSON(aJsonObject* data, const char* nodeName); diff --git a/sketches/libraries/nw2s/SDFirmware.cpp b/sketches/libraries/nw2s/SDFirmware.cpp index a7126f4..51d22b7 100644 --- a/sketches/libraries/nw2s/SDFirmware.cpp +++ b/sketches/libraries/nw2s/SDFirmware.cpp @@ -234,6 +234,18 @@ void nw2s::initializeFirmware() Serial.println(String(nodeError)); } } + else if (strcmp(typeNode->valuestring, "RandomLoopingShiftRegister") == 0) + { + if (clockDevice != NULL) + { + clockDevice->registerDevice(RandomLoopingShiftRegister::create(deviceNode)); + } + else + { + static const char nodeError[] = "RandomLoopingShiftRegister defined with no clock, skipping."; + Serial.println(String(nodeError)); + } + } else if (strcmp(typeNode->valuestring, "TriggeredNoteSequencer") == 0) { EventManager::registerDevice(TriggeredNoteSequencer::create(deviceNode)); diff --git a/sketches/libraries/nw2s/ShiftRegister.cpp b/sketches/libraries/nw2s/ShiftRegister.cpp index eaa7d7a..d089ec8 100644 --- a/sketches/libraries/nw2s/ShiftRegister.cpp +++ b/sketches/libraries/nw2s/ShiftRegister.cpp @@ -20,7 +20,8 @@ #include "ShiftRegister.h" #include "Entropy.h" -#include "aJson.h" +#include "../aJSON/aJSON.h" +#include "JSONUtil.h" //using namepsace nw2s; @@ -29,32 +30,121 @@ RandomLoopingShiftRegister* RandomLoopingShiftRegister::create(int size, PinAnal return new RandomLoopingShiftRegister(size, control, clockdivision); } -// RandomLoopingShiftRegister* RandomLoopingShiftRegister::create(aJsonObject* data) -// { -// static const char sizeNodeName[] = "size"; -// static const char controlNodeName[] = "controlInput"; -// -// /* These are the required parameters */ -// PinAnalogIn control = getAnalogInputFromJSON(data, controlNodeName); -// int size = getIntFromJSON(data, sizeNodeName); -// int clockdivision = getDivisionFromJSON(data); -// -// /* These are the optional outputs */ -// Scale scale = getScaleFromJSON(data); -// PinDigitalIn triggerInput = getDigitalInputFromJSON(data, triggerInputNodeName); -// NoteName root = getRootFromJSON(data); -// PinDigitalOut gatePin = getDigitalOutputFromJSON(data, gateNodeName); -// int gateDuration = getIntFromJSON(data, durationNodeName, 20, 1, 1000); -// -// PinAnalogOut output = getAnalogOutputFromJSON(data); -// -// -// RandomLoopingShiftRegister* seq = new RandomLoopingShiftRegister(notes, root, scale, triggerInput, output, randomize); -// -// if (gatePin != DIGITAL_OUT_NONE) seq->setgate(Gate::create(gatePin, gateDuration)); -// -// return seq; -// } +RandomLoopingShiftRegister* RandomLoopingShiftRegister::create(aJsonObject* data) +{ + static const char sizeNodeName[] = "size"; + static const char controlNodeName[] = "controlInput"; + static const char delayedNodeName[] = "delayedOutput"; + static const char delayNodeName[] = "delay"; + static const char trigger1NodeName[] = "triggerOutput1"; + static const char trigger2NodeName[] = "triggerOutput2"; + static const char trigger3NodeName[] = "triggerOutput3"; + static const char trigger4NodeName[] = "triggerOutput4"; + static const char trigger5NodeName[] = "triggerOutput5"; + static const char trigger6NodeName[] = "triggerOutput6"; + static const char trigger7NodeName[] = "triggerOutput7"; + static const char trigger8NodeName[] = "triggerOutput8"; + static const char trigger9NodeName[] = "logicalAND1"; + static const char trigger10NodeName[] = "logicalAND2"; + static const char trigger11NodeName[] = "logicalAND3"; + static const char trigger12NodeName[] = "logicalAND4"; + + /* These are the required parameters */ + PinAnalogIn control = getAnalogInputFromJSON(data, controlNodeName); + int size = getIntFromJSON(data, sizeNodeName, 16, 8, 128); + int clockdivision = getDivisionFromJSON(data); + PinAnalogOut output = getAnalogOutputFromJSON(data); + + /* These are the optional outputs */ + PinAnalogOut delayedoutput = getAnalogOutputFromJSON(data, delayedNodeName); + int delay = getIntFromJSON(data, delayNodeName, 4, 0, 32); + PinDigitalOut trigger1 = getDigitalOutputFromJSON(data, trigger1NodeName); + PinDigitalOut trigger2 = getDigitalOutputFromJSON(data, trigger2NodeName); + PinDigitalOut trigger3 = getDigitalOutputFromJSON(data, trigger3NodeName); + PinDigitalOut trigger4 = getDigitalOutputFromJSON(data, trigger4NodeName); + PinDigitalOut trigger5 = getDigitalOutputFromJSON(data, trigger5NodeName); + PinDigitalOut trigger6 = getDigitalOutputFromJSON(data, trigger6NodeName); + PinDigitalOut trigger7 = getDigitalOutputFromJSON(data, trigger7NodeName); + PinDigitalOut trigger8 = getDigitalOutputFromJSON(data, trigger8NodeName); + PinDigitalOut logicalAndOutput1 = getDigitalOutputFromJSON(data, trigger9NodeName); + PinDigitalOut logicalAndOutput2 = getDigitalOutputFromJSON(data, trigger10NodeName); + PinDigitalOut logicalAndOutput3 = getDigitalOutputFromJSON(data, trigger11NodeName); + PinDigitalOut logicalAndOutput4 = getDigitalOutputFromJSON(data, trigger12NodeName); + + RandomLoopingShiftRegister* reg = new RandomLoopingShiftRegister(size, control, clockdivision); + + if (output != ANALOG_OUT_NONE) + { + reg->setCVOut(output); + } + + if (delayedoutput != ANALOG_OUT_NONE) + { + reg->setDelayedCVOut(delayedoutput, delay); + } + + if (trigger1 != DIGITAL_OUT_NONE) + { + reg->setTriggerOut(0, trigger1); + } + + if (trigger2 != DIGITAL_OUT_NONE) + { + reg->setTriggerOut(1, trigger2); + } + + if (trigger3 != DIGITAL_OUT_NONE) + { + reg->setTriggerOut(2, trigger3); + } + + if (trigger4 != DIGITAL_OUT_NONE) + { + reg->setTriggerOut(3, trigger4); + } + + if (trigger5 != DIGITAL_OUT_NONE) + { + reg->setTriggerOut(4, trigger5); + } + + if (trigger6 != DIGITAL_OUT_NONE) + { + reg->setTriggerOut(5, trigger6); + } + + if (trigger7 != DIGITAL_OUT_NONE) + { + reg->setTriggerOut(6, trigger7); + } + + if (trigger8 != DIGITAL_OUT_NONE) + { + reg->setTriggerOut(7, trigger8); + } + + if (logicalAndOutput1 != DIGITAL_OUT_NONE) + { + reg->setLogicalAndTrigger(logicalAndOutput1, 0, 2, -1, -1); + } + + if (logicalAndOutput2 != DIGITAL_OUT_NONE) + { + reg->setLogicalAndTrigger(logicalAndOutput2, 0, 3, -1, -1); + } + + if (logicalAndOutput3 != DIGITAL_OUT_NONE) + { + reg->setLogicalAndTrigger(logicalAndOutput3, 0, 2, 4, -1); + } + + if (logicalAndOutput4 != DIGITAL_OUT_NONE) + { + reg->setLogicalAndTrigger(logicalAndOutput4, 0, 1, 3, 7); + } + + return reg; +} RandomLoopingShiftRegister::RandomLoopingShiftRegister(int size, PinAnalogIn control, int clockdivision) diff --git a/sketches/libraries/nw2s/ShiftRegister.h b/sketches/libraries/nw2s/ShiftRegister.h index 39dd1c2..0e7cb1e 100644 --- a/sketches/libraries/nw2s/ShiftRegister.h +++ b/sketches/libraries/nw2s/ShiftRegister.h @@ -25,6 +25,7 @@ #include "Clock.h" #include "Trigger.h" #include "Gate.h" +#include "../aJSON/aJSON.h" namespace nw2s { @@ -35,6 +36,7 @@ class nw2s::RandomLoopingShiftRegister : public nw2s::BeatDevice { public: static RandomLoopingShiftRegister* create(int size, PinAnalogIn control, int clockdivision); + static RandomLoopingShiftRegister* create(aJsonObject* data); virtual void calculate(); virtual void timer(unsigned long t); virtual void reset(); @@ -43,8 +45,6 @@ class nw2s::RandomLoopingShiftRegister : public nw2s::BeatDevice void setKey(NoteName root, Scale scale); void setNoteOut(PinAnalogOut pinout); void setDelayedNoteOut(PinAnalogOut pinout, int ticks); - // void setWriteZero(PinDigitalIn pinin); - // void setWriteOne(PinDigitalIn pinin); void setTriggerOut(int position, PinDigitalOut pinout); void setGateOut(int position, PinDigitalOut pinout, int duration); void setLogicalOrTrigger(PinDigitalOut pinout, int p1, int p2, int p3 = -1, int p4 = -1); @@ -55,6 +55,8 @@ class nw2s::RandomLoopingShiftRegister : public nw2s::BeatDevice void setSequencerScaleInput(PinAnalogIn pin); void setSequencerCVOut(PinAnalogOut pinout); void setSequencerNoteOut(PinAnalogOut pinout); + // void setWriteZero(PinDigitalIn pinin); + // void setWriteOne(PinDigitalIn pinin); private: int nextCV;