Skip to content

Commit

Permalink
Update GlitchSprinkler (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryukau committed Jul 1, 2024
1 parent 58f0d81 commit a68e6d2
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 42 deletions.
19 changes: 12 additions & 7 deletions GlitchSprinkler/source/dsp/dspcore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,15 @@
#include <numbers>
#include <numeric>

static constexpr bool isPolyphonic__ = true; // TODO
static constexpr bool doRelease = true; // TODO

void DSPCore::setup(double sampleRate)
void DSPCore::setup(double sampleRate_)
{
activeNote.reserve(1024);
activeNote.resize(0);

activeModifier.reserve(1024);
activeModifier.resize(0);

sampleRate = sampleRate;
sampleRate = sampleRate_;

SmootherCommon<double>::setTime(double(0.2));

Expand All @@ -48,8 +45,16 @@ void DSPCore::setup(double sampleRate)
using ID = ParameterID::ID; \
const auto &pv = param.value; \
\
isPolyphonic = isPolyphonic__; \
noteOffState = doRelease ? Voice::State::release : Voice::State::terminate; \
isPolyphonic = pv[ID::polyphonic]->getInt(); \
\
auto newNoteOffState \
= pv[ID::release]->getInt() ? Voice::State::release : Voice::State::terminate; \
if (noteOffState != newNoteOffState) { \
for (auto &x : voices) { \
if (x.state == noteOffState) x.state = newNoteOffState; \
} \
} \
noteOffState = newNoteOffState; \
\
const auto samplesPerBeat = (double(60) * sampleRate) / tempo; \
const auto arpeggioNotesPerBeat = pv[ID::arpeggioNotesPerBeat]->getInt() + 1; \
Expand Down
76 changes: 41 additions & 35 deletions GlitchSprinkler/source/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,34 +126,21 @@ bool Editor::prepareUI()
mixLeft1, mixTop6, labelWidth, labelHeight, uiTextSize, ID::saturationGain,
Scales::gain, true, 5);

addLabel(mixLeft0, mixTop7, labelWidth, labelHeight, uiTextSize, "Random FM Index");
addLabel(mixLeft0, mixTop8, labelWidth, labelHeight, uiTextSize, "Octave");
addTextKnob(
mixLeft1, mixTop7, labelWidth, labelHeight, uiTextSize, ID::randomizeFmIndex,
Scales::randomizeFmIndex, false, 5);

addLabel(mixLeft0, mixTop8, labelWidth, labelHeight, uiTextSize, "Seed");
auto seedTextKnob = addTextKnob(
mixLeft1, mixTop8, labelWidth, labelHeight, uiTextSize, ID::seed, Scales::seed, false,
0);
if (seedTextKnob) {
seedTextKnob->sensitivity = 2048.0 / double(1 << 24);
seedTextKnob->lowSensitivity = 1.0 / double(1 << 24);
}
addLabel(mixLeft0, mixTop9, labelWidth, labelHeight, uiTextSize, "Octave");
addTextKnob(
mixLeft1, mixTop9, labelWidth, labelHeight, uiTextSize, ID::transposeOctave,
mixLeft1, mixTop8, labelWidth, labelHeight, uiTextSize, ID::transposeOctave,
Scales::transposeOctave, false, 0, -transposeOctaveOffset);
addLabel(mixLeft0, mixTop10, labelWidth, labelHeight, uiTextSize, "Semitone");
addLabel(mixLeft0, mixTop9, labelWidth, labelHeight, uiTextSize, "Semitone");
addTextKnob(
mixLeft1, mixTop10, labelWidth, labelHeight, uiTextSize, ID::transposeSemitone,
mixLeft1, mixTop9, labelWidth, labelHeight, uiTextSize, ID::transposeSemitone,
Scales::transposeSemitone, false, 0, -transposeSemitoneOffset);
addLabel(mixLeft0, mixTop11, labelWidth, labelHeight, uiTextSize, "Cent");
addLabel(mixLeft0, mixTop10, labelWidth, labelHeight, uiTextSize, "Cent");
addTextKnob(
mixLeft1, mixTop11, labelWidth, labelHeight, uiTextSize, ID::transposeCent,
mixLeft1, mixTop10, labelWidth, labelHeight, uiTextSize, ID::transposeCent,
Scales::transposeCent, false, 5);
addLabel(mixLeft0, mixTop12, labelWidth, labelHeight, uiTextSize, "Tuning");
addLabel(mixLeft0, mixTop11, labelWidth, labelHeight, uiTextSize, "Tuning");
addOptionMenu(
mixLeft1, mixTop12, labelWidth, labelHeight, uiTextSize, ID::tuning,
mixLeft1, mixTop11, labelWidth, labelHeight, uiTextSize, ID::tuning,
{
"Equal Temperament 12", "Equal Temperament 5", "Just Intonation 5-limit Major",
"- Reserved 03 -", "- Reserved 04 -", "- Reserved 05 -",
Expand All @@ -168,6 +155,12 @@ bool Editor::prepareUI()
"- Reserved 30 -", "- Reserved 31 -", "- Reserved 32 -",
});

addCheckbox(
mixLeft0, mixTop12, labelWidth, labelHeight, uiTextSize, "Polyphonic",
ID::polyphonic);
addCheckbox(
mixLeft1, mixTop12, labelWidth, labelHeight, uiTextSize, "Release", ID::release);

// Waveform.
constexpr auto waveformTop0 = top0 + 0 * labelY;
constexpr auto waveformTop1 = waveformTop0 + 1 * labelY;
Expand Down Expand Up @@ -239,27 +232,35 @@ bool Editor::prepareUI()
addToggleButton(
arpLeft0, arpTop0, groupLabelWidth, labelHeight, uiTextSize, "Arpeggio",
ID::arpeggioSwitch);
addLabel(arpLeft0, arpTop1, labelWidth, labelHeight, uiTextSize, "Seed");
auto seedTextKnob = addTextKnob(
arpLeft1, arpTop1, labelWidth, labelHeight, uiTextSize, ID::seed, Scales::seed, false,
0);
if (seedTextKnob) {
seedTextKnob->sensitivity = 2048.0 / double(1 << 24);
seedTextKnob->lowSensitivity = 1.0 / double(1 << 24);
}

addLabel(arpLeft0, arpTop1, labelWidth, labelHeight, uiTextSize, "Note / Beat");
addLabel(arpLeft0, arpTop3, labelWidth, labelHeight, uiTextSize, "Note / Beat");
addTextKnob(
arpLeft1, arpTop1, labelWidth, labelHeight, uiTextSize, ID::arpeggioNotesPerBeat,
arpLeft1, arpTop3, labelWidth, labelHeight, uiTextSize, ID::arpeggioNotesPerBeat,
Scales::arpeggioNotesPerBeat, false, 0, 1);
addLabel(arpLeft0, arpTop2, labelWidth, labelHeight, uiTextSize, "Loop Length [beat]");
addLabel(arpLeft0, arpTop4, labelWidth, labelHeight, uiTextSize, "Loop Length [beat]");
addTextKnob(
arpLeft1, arpTop2, labelWidth, labelHeight, uiTextSize, ID::arpeggioLoopLengthInBeat,
arpLeft1, arpTop4, labelWidth, labelHeight, uiTextSize, ID::arpeggioLoopLengthInBeat,
Scales::arpeggioLoopLengthInBeat, false, 0, 0);
addLabel(arpLeft0, arpTop3, labelWidth, labelHeight, uiTextSize, "Duration Variation");
addLabel(arpLeft0, arpTop5, labelWidth, labelHeight, uiTextSize, "Duration Variation");
addTextKnob(
arpLeft1, arpTop3, labelWidth, labelHeight, uiTextSize, ID::arpeggioDurationVariation,
arpLeft1, arpTop5, labelWidth, labelHeight, uiTextSize, ID::arpeggioDurationVariation,
Scales::arpeggioDurationVariation, false, 0, 1);
addLabel(arpLeft0, arpTop4, labelWidth, labelHeight, uiTextSize, "Rest Chance");
addLabel(arpLeft0, arpTop6, labelWidth, labelHeight, uiTextSize, "Rest Chance");
addTextKnob(
arpLeft1, arpTop4, labelWidth, labelHeight, uiTextSize, ID::arpeggioRestChance,
arpLeft1, arpTop6, labelWidth, labelHeight, uiTextSize, ID::arpeggioRestChance,
Scales::defaultScale, false, 5);

addLabel(arpLeft0, arpTop7, labelWidth, labelHeight, uiTextSize, "Scale");
addLabel(arpLeft0, arpTop8, labelWidth, labelHeight, uiTextSize, "Scale");
addOptionMenu(
arpLeft1, arpTop7, labelWidth, labelHeight, uiTextSize, ID::arpeggioScale,
arpLeft1, arpTop8, labelWidth, labelHeight, uiTextSize, ID::arpeggioScale,
{
"Octave", "ET 5 Chromatic", "ET 12 Major", "ET 12 Minor",
"Overtone 32", "- Reserved 05 -", "- Reserved 06 -", "- Reserved 07 -",
Expand All @@ -271,15 +272,20 @@ bool Editor::prepareUI()
"- Reserved 28 -", "- Reserved 29 -", "- Reserved 30 -", "- Reserved 31 -",
"- Reserved 32 -",
});
addLabel(arpLeft0, arpTop8, labelWidth, labelHeight, uiTextSize, "Pitch Drift [cent]");
addLabel(arpLeft0, arpTop9, labelWidth, labelHeight, uiTextSize, "Pitch Drift [cent]");
addTextKnob(
arpLeft1, arpTop8, labelWidth, labelHeight, uiTextSize, ID::arpeggioPicthDriftCent,
arpLeft1, arpTop9, labelWidth, labelHeight, uiTextSize, ID::arpeggioPicthDriftCent,
Scales::arpeggioPicthDriftCent, false, 5);
addLabel(arpLeft0, arpTop9, labelWidth, labelHeight, uiTextSize, "Octave Range");
addLabel(arpLeft0, arpTop10, labelWidth, labelHeight, uiTextSize, "Octave Range");
addTextKnob(
arpLeft1, arpTop9, labelWidth, labelHeight, uiTextSize, ID::arpeggioOctave,
arpLeft1, arpTop10, labelWidth, labelHeight, uiTextSize, ID::arpeggioOctave,
Scales::arpeggioOctave, false, 0, 1);

addLabel(arpLeft0, arpTop12, labelWidth, labelHeight, uiTextSize, "Random FM Index");
addTextKnob(
arpLeft1, arpTop12, labelWidth, labelHeight, uiTextSize, ID::randomizeFmIndex,
Scales::randomizeFmIndex, false, 5);

// Randomize button.
const auto randomButtonTop = top0 + 18 * labelY;
const auto randomButtonLeft = left0 + labelWidth + 2 * margin;
Expand Down
8 changes: 8 additions & 0 deletions GlitchSprinkler/source/parameter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ enum ID {
transposeCent,
tuning,

polyphonic,
release,

polynomialPointX0,
polynomialPointY0 = polynomialPointX0 + nPolyOscControl,

Expand Down Expand Up @@ -177,6 +180,11 @@ struct GlobalParameter : public ParameterInterface {
value[ID::tuning]
= std::make_unique<UIntValue>(0, Scales::tuning, "tuning", Info::kCanAutomate);

value[ID::polyphonic] = std::make_unique<UIntValue>(
1, Scales::boolScale, "polyphonic", Info::kCanAutomate);
value[ID::release]
= std::make_unique<UIntValue>(1, Scales::boolScale, "release", Info::kCanAutomate);

for (size_t idx = 0; idx < nPolyOscControl; ++idx) {
auto indexStr = std::to_string(idx);
auto ratio = double(idx + 1) / double(nPolyOscControl + 1);
Expand Down

0 comments on commit a68e6d2

Please sign in to comment.