Skip to content

Commit

Permalink
dmx module
Browse files Browse the repository at this point in the history
  • Loading branch information
JerrySievert committed Jan 27, 2018
1 parent 6719460 commit d69f8bc
Show file tree
Hide file tree
Showing 7 changed files with 28,174 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SLUG = DrumKit
VERSION = 0.5.0
VERSION = 0.5.1

# FLAGS will be passed to both the C and C++ compiler
FLAGS +=
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ A work in progress.

14 open high hats.

### DMX

Full DMX Kit, starting at Octave 5, C#, and continuing for 12 steps.

Anything above/below this will not trigger a note. If a note is triggered, it
will not trigger again until a note out of range is sent.

This is a very expiremental module.

## Building

Building requires [SynthDevKit](https://github.com/JerrySievert/SynthDevKit),
Expand Down
139 changes: 139 additions & 0 deletions res/DMX.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
104 changes: 104 additions & 0 deletions src/DMX.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#include <stdint.h>

#include "DrumKit.hpp"
#include "dmx.h"

struct DMXContainer {
float *sample;
unsigned int length;
int current;
};

struct DMXContainer dmxsamples[ 12 ] = {
{ (float *)dmx1, dmx1_len, 0 },
{ (float *)dmx2, dmx2_len, 1 },
{ (float *)dmx3, dmx3_len, 2 },
{ (float *)dmx4, dmx4_len, 3 },
{ (float *)dmx5, dmx5_len, 4 },
{ (float *)dmx6, dmx6_len, 5 },
{ (float *)dmx7, dmx7_len, 6 },
{ (float *)dmx8, dmx8_len, 7 },
{ (float *)dmx9, dmx9_len, 8 },
{ (float *)dmx10, dmx10_len, 9 },
{ (float *)dmx11, dmx11_len, 10 },
{ (float *)dmx12, dmx12_len, 11 },
};

float dmxnotes[12] = { 0.08, 0.17, 0.25, 0.33, 0.42, 0.5, 0.58, 0.67, 0.75, 0.83, 0.92, 1.0 };


struct DMXContainer *getNote(float current) {
for (int i = 0; i < 12; i++) {
if ((dmxnotes[i] - 0.02) <= current && (dmxnotes[i] + 0.02) >= current) {
return &dmxsamples[i];
}
}

return NULL;
}

struct DMXModule : Module {
enum ParamIds { NUM_PARAMS };
enum InputIds { NOTE1_INPUT, NUM_INPUTS };
enum OutputIds { AUDIO1_OUTPUT, NUM_OUTPUTS };
enum LightIds { NUM_LIGHTS };

DMXModule( ) : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {
currentStep = 0;
last = -1;
}

void step( ) override;

uint32_t currentStep;
int last;
};

void DMXModule::step( ) {
float in1 = inputs[ NOTE1_INPUT ].value;
struct DMXContainer *note;

// check the first note
note = getNote(in1);

if (note == NULL) {
currentStep = 0;
outputs[ AUDIO1_OUTPUT ].value = 0;
last = -1;
} else {
if (last != note->current) {
last = note->current;
currentStep = 0;
}

if (currentStep >= note->length) {
outputs[ AUDIO1_OUTPUT ].value = 0;
} else {
outputs[ AUDIO1_OUTPUT ].value = note->sample[currentStep];
currentStep++;
}
}
}

DMXWidget::DMXWidget( ) {
DMXModule *module = new DMXModule( );
setModule(module);
box.size = Vec(3 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT);

{
SVGPanel *panel = new SVGPanel( );
panel->box.size = box.size;
panel->setBackground(SVG::load(assetPlugin(plugin, "res/DMX.svg")));
addChild(panel);
}

addChild(createScrew<ScrewSilver>(Vec(RACK_GRID_WIDTH, 0)));
addChild(createScrew<ScrewSilver>(
Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));

addInput(createInput<PJ301MPort>(Vec(10, 45), module,
DMXModule::NOTE1_INPUT));
addOutput(createOutput<PJ301MPort>(Vec(10, 92), module,
DMXModule::AUDIO1_OUTPUT));

}
3 changes: 3 additions & 0 deletions src/DrumKit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ void init(rack::Plugin *p) {
p->addModel(
createModel<OpenHHWidget>("DrumKit", "Open HiHat", "Open HiHat"));

p->addModel(
createModel<DMXWidget>("DrumKit", "DMX", "DMX"));

// Any other plugin initialization may go here.
// As an alternative, consider lazy-loading assets and lookup tables when your
// module is created to reduce startup times of Rack.
Expand Down
4 changes: 4 additions & 0 deletions src/DrumKit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ struct ClosedHHWidget : ModuleWidget {
struct OpenHHWidget : ModuleWidget {
OpenHHWidget( );
};

struct DMXWidget : ModuleWidget {
DMXWidget( );
};
Loading

0 comments on commit d69f8bc

Please sign in to comment.