Skip to content

Commit

Permalink
shift register is working in SD now. that's a wrap!
Browse files Browse the repository at this point in the history
  • Loading branch information
nw2s committed Jul 13, 2014
1 parent 46deb22 commit 7ae76d0
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 52 deletions.
48 changes: 30 additions & 18 deletions flash/programs/alan.b
Original file line number Diff line number Diff line change
Expand Up @@ -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
}


]

}
}
11 changes: 6 additions & 5 deletions flash/programs/varclock.b
Original file line number Diff line number Diff line change
Expand Up @@ -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" : [
Expand Down
7 changes: 7 additions & 0 deletions sketches/libraries/nw2s/JSONUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
1 change: 1 addition & 0 deletions sketches/libraries/nw2s/JSONUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions sketches/libraries/nw2s/SDFirmware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
144 changes: 117 additions & 27 deletions sketches/libraries/nw2s/ShiftRegister.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

#include "ShiftRegister.h"
#include "Entropy.h"
#include "aJson.h"
#include "../aJSON/aJSON.h"
#include "JSONUtil.h"

//using namepsace nw2s;

Expand All @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions sketches/libraries/nw2s/ShiftRegister.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "Clock.h"
#include "Trigger.h"
#include "Gate.h"
#include "../aJSON/aJSON.h"

namespace nw2s
{
Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit 7ae76d0

Please sign in to comment.