Skip to content
This repository was archived by the owner on Oct 4, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
# this flag selects the rack version to compile against.
#
# possible values are v040 v_050_dev
SLUG = dekstop
VERSION = 0.6.0dev

# FLAGS += -D v040
FLAGS += -D v_050_dev
RACK_DIR ?= ../..

FLAGS += -Iportaudio
LDFLAGS += -lsamplerate

SOURCES = $(wildcard src/*.cpp portaudio/*.c)

include ../../plugin.mk
include $(RACK_DIR)/plugin.mk

FLAGS += -Iportaudio
DISTRIBUTABLES += $(wildcard LICENSE*) res

dist: all
mkdir -p dist/dekstop
cp LICENSE* dist/dekstop/
cp plugin.* dist/dekstop/
cp -R res dist/dekstop/
67 changes: 35 additions & 32 deletions src/GateSeq8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const int NUM_CHANNELS = 8;
const int NUM_GATES = NUM_STEPS * NUM_CHANNELS;

struct GateSEQ8 : Module {

enum ParamIds {
CLOCK_PARAM,
RUN_PARAM,
Expand Down Expand Up @@ -45,9 +45,9 @@ struct GateSEQ8 : Module {
float stepLights[NUM_GATES] = {};

GateSEQ8() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {}
void step();
void step() override;

json_t *toJson() {
json_t *toJson() override {
json_t *rootJ = json_object();

// Clock multiplier
Expand All @@ -65,7 +65,7 @@ struct GateSEQ8 : Module {
return rootJ;
}

void fromJson(json_t *rootJ) {
void fromJson(json_t *rootJ) override {
// Clock multiplier
json_t *multiplierJ = json_object_get(rootJ, "multiplier");
if (!multiplierJ) {
Expand All @@ -82,24 +82,22 @@ struct GateSEQ8 : Module {
}
}

void reset() {
void reset() override {
for (int i = 0; i < NUM_GATES; i++) {
gateState[i] = false;
}
}

void randomize() {
void randomize() override {
for (int i = 0; i < NUM_GATES; i++) {
gateState[i] = (randomf() > 0.5);
gateState[i] = (randomUniform() > 0.5);
}
}
};


void GateSEQ8::step() {
#ifdef v_050_dev
float gSampleRate = engineGetSampleRate();
#endif
const float lightLambda = 0.1;
// Run
if (runningTrigger.process(params[RUN_PARAM].value)) {
Expand Down Expand Up @@ -139,7 +137,7 @@ void GateSEQ8::step() {

if (nextStep) {
// Advance step
int numSteps = clampi(roundf(params[STEPS_PARAM].value + inputs[STEPS_INPUT].value), 1, NUM_STEPS);
int numSteps = clamp(static_cast<int>(roundf(params[STEPS_PARAM].value + inputs[STEPS_INPUT].value)), 1, NUM_STEPS);
index += 1;
if (index >= numSteps) {
index = 0;
Expand Down Expand Up @@ -181,10 +179,10 @@ struct ClockMultiplierChoice : ChoiceButton {
menu->box.pos = getAbsoluteOffset(Vec(0, box.size.y));
menu->box.size.x = box.size.x;

const float multipliers[12] = {0.25, 0.3, 0.5, 0.75,
const float multipliers[12] = {0.25, 0.3, 0.5, 0.75,
1.0, 1.5, 2.0, 3.0,
4.0, 6.0, 8.0, 12.0};
const std::string labels[12] = {"1/4", "1/3", "1/2", "3/4",
const std::string labels[12] = {"1/4", "1/3", "1/2", "3/4",
"1/1", "3/2", "2/1", "3/1",
"4/1", "6/1", "8/1", "12/1"};
int multipliersLen = sizeof(multipliers) / sizeof(multipliers[0]);
Expand All @@ -201,9 +199,12 @@ struct ClockMultiplierChoice : ChoiceButton {
}
};

GateSEQ8Widget::GateSEQ8Widget() {
GateSEQ8 *module = new GateSEQ8();
setModule(module);

struct GateSEQ8Widget : ModuleWidget {
GateSEQ8Widget(GateSEQ8 *module);
};

GateSEQ8Widget::GateSEQ8Widget(GateSEQ8 *module) : ModuleWidget(module) {
box.size = Vec(360, 380);

{
Expand All @@ -213,23 +214,23 @@ GateSEQ8Widget::GateSEQ8Widget() {
addChild(panel);
}

addChild(createScrew<ScrewSilver>(Vec(15, 0)));
addChild(createScrew<ScrewSilver>(Vec(box.size.x-30, 0)));
addChild(createScrew<ScrewSilver>(Vec(15, 365)));
addChild(createScrew<ScrewSilver>(Vec(box.size.x-30, 365)));
addChild(Widget::create<ScrewSilver>(Vec(15, 0)));
addChild(Widget::create<ScrewSilver>(Vec(box.size.x-30, 0)));
addChild(Widget::create<ScrewSilver>(Vec(15, 365)));
addChild(Widget::create<ScrewSilver>(Vec(box.size.x-30, 365)));

addParam(createParam<RoundSmallBlackKnob>(Vec(17, 56), module, GateSEQ8::CLOCK_PARAM, -2.0, 10.0, 2.0));
addParam(createParam<LEDButton>(Vec(60, 61-1), module, GateSEQ8::RUN_PARAM, 0.0, 1.0, 0.0));
addChild(createLight<SmallLight<GreenLight>>(Vec(60+6, 61+5), module, GateSEQ8::RUNNING_LIGHT));
addParam(createParam<LEDButton>(Vec(98, 61-1), module, GateSEQ8::RESET_PARAM, 0.0, 1.0, 0.0));
addChild(createLight<SmallLight<GreenLight>>(Vec(98+6, 61+5), module, GateSEQ8::RESET_LIGHT));
addParam(createParam<RoundSmallBlackSnapKnob>(Vec(132, 56), module, GateSEQ8::STEPS_PARAM, 1.0, NUM_STEPS, NUM_STEPS));
addParam(ParamWidget::create<RoundSmallBlackKnob>(Vec(17, 56), module, GateSEQ8::CLOCK_PARAM, -2.0, 10.0, 2.0));
addParam(ParamWidget::create<LEDButton>(Vec(60, 61-1), module, GateSEQ8::RUN_PARAM, 0.0, 1.0, 0.0));
addChild(ModuleLightWidget::create<SmallLight<GreenLight>>(Vec(60+6, 61+5), module, GateSEQ8::RUNNING_LIGHT));
addParam(ParamWidget::create<LEDButton>(Vec(98, 61-1), module, GateSEQ8::RESET_PARAM, 0.0, 1.0, 0.0));
addChild(ModuleLightWidget::create<SmallLight<GreenLight>>(Vec(98+6, 61+5), module, GateSEQ8::RESET_LIGHT));
addParam(ParamWidget::create<RoundSmallBlackSnapKnob>(Vec(132, 56), module, GateSEQ8::STEPS_PARAM, 1.0, NUM_STEPS, NUM_STEPS));

static const float portX[8] = {19, 57, 96, 134, 173, 211, 250, 288};
addInput(createInput<PJ301MPort>(Vec(portX[0]-1, 99-1), module, GateSEQ8::CLOCK_INPUT));
addInput(createInput<PJ301MPort>(Vec(portX[1]-1, 99-1), module, GateSEQ8::EXT_CLOCK_INPUT));
addInput(createInput<PJ301MPort>(Vec(portX[2]-1, 99-1), module, GateSEQ8::RESET_INPUT));
addInput(createInput<PJ301MPort>(Vec(portX[3]-1, 99-1), module, GateSEQ8::STEPS_INPUT));
addInput(Port::create<PJ301MPort>(Vec(portX[0]-1, 99-1), Port::INPUT, module, GateSEQ8::CLOCK_INPUT));
addInput(Port::create<PJ301MPort>(Vec(portX[1]-1, 99-1), Port::INPUT, module, GateSEQ8::EXT_CLOCK_INPUT));
addInput(Port::create<PJ301MPort>(Vec(portX[2]-1, 99-1), Port::INPUT, module, GateSEQ8::RESET_INPUT));
addInput(Port::create<PJ301MPort>(Vec(portX[3]-1, 99-1), Port::INPUT, module, GateSEQ8::STEPS_INPUT));

{
Label *label = new Label();
Expand All @@ -247,9 +248,11 @@ GateSEQ8Widget::GateSEQ8Widget() {
for (int y = 0; y < NUM_CHANNELS; y++) {
for (int x = 0; x < NUM_STEPS; x++) {
int i = y*NUM_STEPS+x;
addParam(createParam<LEDButton>(Vec(22 + x*25, 155+y*25+3), module, GateSEQ8::GATE1_PARAM + i, 0.0, 1.0, 0.0));
addChild(createLight<SmallLight<GreenLight>>(Vec(28 + x*25, 156+y*25+8), module, GateSEQ8::GATE_LIGHTS + i));
addParam(ParamWidget::create<LEDButton>(Vec(22 + x*25, 155+y*25+3), module, GateSEQ8::GATE1_PARAM + i, 0.0, 1.0, 0.0));
addChild(ModuleLightWidget::create<SmallLight<GreenLight>>(Vec(28 + x*25, 156+y*25+8), module, GateSEQ8::GATE_LIGHTS + i));
}
addOutput(createOutput<PJ301MPort>(Vec(320, 155+y*25), module, GateSEQ8::GATE1_OUTPUT + y));
addOutput(Port::create<PJ301MPort>(Vec(320, 155+y*25), Port::OUTPUT, module, GateSEQ8::GATE1_OUTPUT + y));
}
}

Model *modelGateSEQ8 = Model::create<GateSEQ8, GateSEQ8Widget>("dekstop", "GateSEQ8", "Gate SEQ-8", SEQUENCER_TAG);
40 changes: 17 additions & 23 deletions src/Recorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct Recorder : Module {
RECORDING_LIGHT,
NUM_LIGHTS
};

std::string filename;
WAV_Writer writer;
std::atomic_bool isRecording;
Expand All @@ -45,7 +45,7 @@ struct Recorder : Module {
isRecording = false;
}
~Recorder();
void step();
void step() override;
void clear();
void startRecording();
void stopRecording();
Expand Down Expand Up @@ -96,9 +96,7 @@ void Recorder<ChannelCount>::saveAsDialog() {

template <unsigned int ChannelCount>
void Recorder<ChannelCount>::openWAV() {
#ifdef v_050_dev
float gSampleRate = engineGetSampleRate();
#endif
if (!filename.empty()) {
fprintf(stdout, "Recording to %s\n", filename.c_str());
int result = Audio_WAV_OpenWriter(&writer, filename.c_str(), gSampleRate, ChannelCount);
Expand All @@ -108,7 +106,7 @@ void Recorder<ChannelCount>::openWAV() {
snprintf(msg, sizeof(msg), "Failed to open WAV file, result = %d\n", result);
osdialog_message(OSDIALOG_ERROR, OSDIALOG_OK, msg);
fprintf(stderr, "%s", msg);
}
}
}
}

Expand All @@ -128,9 +126,7 @@ void Recorder<ChannelCount>::closeWAV() {
// Run in a separate thread
template <unsigned int ChannelCount>
void Recorder<ChannelCount>::recorderRun() {
#ifdef v_050_dev
float gSampleRate = engineGetSampleRate();
#endif
while (isRecording) {
// Wake up a few times a second, often enough to never overflow the buffer.
float sleepTime = (1.0 * BUFFERSIZE / gSampleRate) / 2.0;
Expand Down Expand Up @@ -184,7 +180,7 @@ struct RecordButton : LEDButton {

Callback onPressCallback;
SchmittTrigger recordTrigger;

void onChange(EventChange &e) override {
if (recordTrigger.process(value)) {
onPress(e);
Expand All @@ -196,11 +192,16 @@ struct RecordButton : LEDButton {
}
};

template <unsigned int ChannelCount>
struct RecorderWidget : ModuleWidget {
RecorderWidget(Recorder<ChannelCount> *module);
json_t *toJsonData();
void fromJsonData(json_t *root);
};


template <unsigned int ChannelCount>
RecorderWidget<ChannelCount>::RecorderWidget() {
Recorder<ChannelCount> *module = new Recorder<ChannelCount>();
setModule(module);
RecorderWidget<ChannelCount>::RecorderWidget(Recorder<ChannelCount> *module) : ModuleWidget(module) {
box.size = Vec(15*6+5, 380);

{
Expand All @@ -223,7 +224,7 @@ RecorderWidget<ChannelCount>::RecorderWidget() {

xPos = 35;
yPos += 2*margin;
ParamWidget *recordButton = createParam<RecordButton>(Vec(xPos, yPos-1), module, Recorder<ChannelCount>::RECORD_PARAM, 0.0, 1.0, 0.0);
ParamWidget *recordButton = ParamWidget::create<RecordButton>(Vec(xPos, yPos-1), module, Recorder<ChannelCount>::RECORD_PARAM, 0.0, 1.0, 0.0);
RecordButton *btn = dynamic_cast<RecordButton*>(recordButton);
Recorder<ChannelCount> *recorder = dynamic_cast<Recorder<ChannelCount>*>(module);

Expand All @@ -236,7 +237,7 @@ RecorderWidget<ChannelCount>::RecorderWidget() {
}
};
addParam(recordButton);
addChild(createLight<SmallLight<RedLight>>(Vec(xPos+6, yPos+5), module, Recorder<ChannelCount>::RECORDING_LIGHT));
addChild(ModuleLightWidget::create<SmallLight<RedLight>>(Vec(xPos+6, yPos+5), module, Recorder<ChannelCount>::RECORDING_LIGHT));
xPos = margin;
yPos += recordButton->box.size.y + 3*margin;
}
Expand All @@ -252,7 +253,7 @@ RecorderWidget<ChannelCount>::RecorderWidget() {
yPos += 5;
xPos = 10;
for (unsigned int i = 0; i < ChannelCount; i++) {
addInput(createInput<PJ3410Port>(Vec(xPos, yPos), module, i));
addInput(Port::create<PJ3410Port>(Vec(xPos, yPos), Port::INPUT, module, i));
Label *label = new Label();
label->box.pos = Vec(xPos + 4, yPos + 28);
label->text = stringf("%d", i + 1);
Expand All @@ -267,12 +268,5 @@ RecorderWidget<ChannelCount>::RecorderWidget() {
}
}

Recorder2Widget::Recorder2Widget() :
RecorderWidget<2u>()
{
}

Recorder8Widget::Recorder8Widget() :
RecorderWidget<8u>()
{
}
Model *modelRecorder2 = Model::create<Recorder<2>, RecorderWidget<2>>("dekstop", "Recorder2", "Recorder 2", UTILITY_TAG);
Model *modelRecorder8 = Model::create<Recorder<8>, RecorderWidget<8>>("dekstop", "Recorder8", "Recorder 8", UTILITY_TAG);
Loading