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 20, 2024
1 parent 0546514 commit 61cf23e
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 159 deletions.
44 changes: 29 additions & 15 deletions GlitchSprinkler/source/dsp/dspcore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,31 +346,44 @@ void DSPCore::noteOn(NoteInfo &info)

template<size_t length>
double getPitchRatioFromArray(
int semitone, double octave, double cent, const std::array<double, length> &tuningTable)
int semitone,
int rootShift,
double octave,
double cent,
const std::array<double, length> &tuningTable)
{
int size = int(tuningTable.size());
int index = semitone % size;
if (index < 0) index += size;

octave += double((semitone - index) / size);
int rootIndex = rootShift % size;
if (rootIndex < 0) rootIndex += size;

return tuningTable[index] * std::exp2(octave + cent / double(1200));
semitone += rootIndex;
int stIndex = semitone % size;
if (stIndex < 0) stIndex += size;

octave += double((semitone - stIndex) / size);

return std::exp2(octave + cent / double(1200)) * tuningTable[stIndex]
/ tuningTable[rootIndex];
}

inline double getPitchRatio(int semitone, double octave, double cent, Tuning tuning)
inline double
getPitchRatio(int semitone, int rootShift, double octave, double cent, Tuning tuning)
{
switch (tuning) {
default:
case Tuning::et12:
return getPitchRatioFromArray(semitone, octave, cent, tuningRatioEt12);
return getPitchRatioFromArray(semitone, rootShift, octave, cent, tuningRatioEt12);
case Tuning::et5:
return getPitchRatioFromArray(semitone, octave, cent, tuningRatioEt5);
return getPitchRatioFromArray(semitone, rootShift, octave, cent, tuningRatioEt5);
case Tuning::just5Major:
return getPitchRatioFromArray(semitone, octave, cent, tuningRatioJust5Major);
return getPitchRatioFromArray(
semitone, rootShift, octave, cent, tuningRatioJust5Major);
case Tuning::just5Minor:
return getPitchRatioFromArray(semitone, octave, cent, tuningRatioJust5Minor);
return getPitchRatioFromArray(
semitone, rootShift, octave, cent, tuningRatioJust5Minor);
case Tuning::just7:
return getPitchRatioFromArray(semitone, octave, cent, tuningRatioJust7);
return getPitchRatioFromArray(semitone, rootShift, octave, cent, tuningRatioJust7);
}
// Shouldn't reach here.
}
Expand Down Expand Up @@ -412,17 +425,18 @@ void Voice::updateNote()
}

// Pitch & phase.
const auto tuning = static_cast<Tuning>(pv[ID::tuning]->getInt());
const auto tuning = static_cast<Tuning>(pv[ID::tuningType]->getInt());
const auto transposeOctave
= int(pv[ID::transposeOctave]->getInt()) - transposeOctaveOffset;
const auto transposeSemitone
= int(pv[ID::transposeSemitone]->getInt()) - transposeSemitoneOffset;
const auto transposeCent = pv[ID::transposeCent]->getDouble();
const auto unisonDetuneCent = unisonRatio * pv[ID::unisonDetuneCent]->getDouble();
const auto tuningRootSemitone = int(pv[ID::tuningRootSemitone]->getInt());

auto getNaturalFreq = [&]() {
auto transposeRatio = getPitchRatio(
transposeSemitone + noteNumber - 69, transposeOctave,
transposeSemitone + noteNumber - 69, tuningRootSemitone, transposeOctave,
transposeCent + noteCent + unisonDetuneCent, tuning);
return core.pitchModifier * transposeRatio * double(440);
};
Expand Down Expand Up @@ -461,7 +475,7 @@ void Voice::updateNote()
if (arpeggioScale == PitchScale::et5Chromatic) {
arpRatio *= getRandomPitch(rngArpeggio, scaleEt5, tuningRatioEt5);
} else if (arpeggioScale == PitchScale::et12ChurchC) {
arpRatio *= getRandomPitch(rngArpeggio, scaleEt12ChurchC, tuningRatioEt12);
arpRatio *= getRandomPitch(rngArpeggio, scaleEt12ChurchC, tuningRatioJust5Major);
} else if (arpeggioScale == PitchScale::et12ChurchD) {
arpRatio *= getRandomPitch(rngArpeggio, scaleEt12ChurchD, tuningRatioEt12);
} else if (arpeggioScale == PitchScale::et12ChurchE) {
Expand All @@ -471,7 +485,7 @@ void Voice::updateNote()
} else if (arpeggioScale == PitchScale::et12ChurchG) {
arpRatio *= getRandomPitch(rngArpeggio, scaleEt12ChurchG, tuningRatioEt12);
} else if (arpeggioScale == PitchScale::et12ChurchA) {
arpRatio *= getRandomPitch(rngArpeggio, scaleEt12ChurchA, tuningRatioEt12);
arpRatio *= getRandomPitch(rngArpeggio, scaleEt12ChurchA, tuningRatioJust5Minor);
} else if (arpeggioScale == PitchScale::et12ChurchB) {
arpRatio *= getRandomPitch(rngArpeggio, scaleEt12ChurchB, tuningRatioEt12);
} else if (arpeggioScale == PitchScale::et12Sus2) {
Expand Down
20 changes: 10 additions & 10 deletions GlitchSprinkler/source/dsp/tuning.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,18 @@ console.log(cents.map(v => 2**(v / 1200)));
```
*/
std::array<double, 12> tuningRatioEt5{
double(1), // 0: 0 (exact)
double(1.0005777895065548), // 1: 1
double(1.148698354997035), // 2: 240 (exact)
double(1.149362060852749), // 3: 241
double(1), // 0: 0
double(1), // 1: 0
double(1.148698354997035), // 2: 240
double(1.148698354997035), // 3: 240
double(1.2599210498948732), // 4: 400
double(1.3195079107728942), // 5: 480 (exact)
double(1.320270308597555), // 6: 481
double(1.515716566510398), // 7: 720 (exact)
double(1.5165923316374392), // 8: 721
double(1.3195079107728942), // 5: 480
double(1.3195079107728942), // 6: 480
double(1.515716566510398), // 7: 720
double(1.515716566510398), // 8: 720
double(1.681792830507429), // 9: 900
double(1.7411011265922482), // 10: 960 (exact)
double(1.742107116553044), // 11: 961
double(1.7411011265922482), // 10: 960
double(1.7411011265922482), // 11: 960
};
std::array<size_t, 5> scaleEt5{0, 2, 5, 7, 10};

Expand Down
163 changes: 80 additions & 83 deletions GlitchSprinkler/source/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ constexpr float labelY = labelHeight + 2 * margin;
constexpr float labelWidth = 2 * knobWidth;
constexpr float groupLabelWidth = 2 * labelWidth + 2 * margin;
constexpr float splashWidth = int(labelWidth * 3 / 2) + 2 * margin;
constexpr float splashHeight = int(2 * labelHeight + 2 * margin);
constexpr float splashHeight = int(labelHeight + 2 * margin);

constexpr float barBoxWidth = groupLabelWidth;
constexpr float barBoxHeight = 5 * labelY - 2 * margin;
Expand Down Expand Up @@ -113,58 +113,41 @@ bool Editor::prepareUI()
addTextKnob(
mixLeft1, mixTop3, labelWidth, labelHeight, uiTextSize, ID::decayTargetGain,
Scales::decayTargetGain, true, 5);
addLabel(mixLeft0, mixTop4, labelWidth, labelHeight, uiTextSize, "Osc. Sync.");
addTextKnob(
mixLeft1, mixTop4, labelWidth, labelHeight, uiTextSize, ID::oscSync,
Scales::defaultScale, false, 5);
addLabel(mixLeft0, mixTop5, labelWidth, labelHeight, uiTextSize, "FM Index");
addTextKnob(
mixLeft1, mixTop5, labelWidth, labelHeight, uiTextSize, ID::fmIndex, Scales::fmIndex,
false, 5);
addLabel(mixLeft0, mixTop6, labelWidth, labelHeight, uiTextSize, "Saturation [dB]");
addTextKnob(
mixLeft1, mixTop6, labelWidth, labelHeight, uiTextSize, ID::saturationGain,
Scales::gain, true, 5);

addLabel(mixLeft0, mixTop8, labelWidth, labelHeight, uiTextSize, "Octave");
addLabel(mixLeft0, mixTop5, labelWidth, labelHeight, uiTextSize, "Octave");
addTextKnob(
mixLeft1, mixTop8, labelWidth, labelHeight, uiTextSize, ID::transposeOctave,
mixLeft1, mixTop5, labelWidth, labelHeight, uiTextSize, ID::transposeOctave,
Scales::transposeOctave, false, 0, -transposeOctaveOffset);
addLabel(mixLeft0, mixTop9, labelWidth, labelHeight, uiTextSize, "Semitone");
addLabel(mixLeft0, mixTop6, labelWidth, labelHeight, uiTextSize, "Semitone");
addTextKnob(
mixLeft1, mixTop9, labelWidth, labelHeight, uiTextSize, ID::transposeSemitone,
mixLeft1, mixTop6, labelWidth, labelHeight, uiTextSize, ID::transposeSemitone,
Scales::transposeSemitone, false, 0, -transposeSemitoneOffset);
addLabel(mixLeft0, mixTop10, labelWidth, labelHeight, uiTextSize, "Cent");
addLabel(mixLeft0, mixTop7, labelWidth, labelHeight, uiTextSize, "Cent");
addTextKnob(
mixLeft1, mixTop10, labelWidth, labelHeight, uiTextSize, ID::transposeCent,
mixLeft1, mixTop7, labelWidth, labelHeight, uiTextSize, ID::transposeCent,
Scales::transposeCent, false, 5);
addLabel(mixLeft0, mixTop11, labelWidth, labelHeight, uiTextSize, "Tuning");

addLabel(mixLeft0, mixTop8, labelWidth, labelHeight, uiTextSize, "Tuning");
std::vector<std::string> tuningItems{
"ET 12", "ET 5", "Just 5 Major", "Just 5 Minor", "Just 7",
"Discrete 2", "Discrete 3", "Discrete 5", "Discrete 7",
};
for (size_t idx = tuningItems.size(); idx <= Scales::tuningType.getMax(); ++idx) {
tuningItems.push_back("- Reserved " + std::to_string(idx) + " -");
}
addOptionMenu(
mixLeft1, mixTop11, labelWidth, labelHeight, uiTextSize, ID::tuning,
{
"ET 12", "ET 5",
"Just 5 Major", "Just 5 Minor",
"Just 7", "Discrete 2",
"Discrete 3", "Discrete 5",
"Discrete 7", "- Reserved 09 -",
"- Reserved 10 -", "- Reserved 11 -",
"- Reserved 12 -", "- Reserved 13 -",
"- Reserved 14 -", "- Reserved 15 -",
"- Reserved 16 -", "- Reserved 17 -",
"- Reserved 18 -", "- Reserved 19 -",
"- Reserved 20 -", "- Reserved 21 -",
"- Reserved 22 -", "- Reserved 23 -",
"- Reserved 24 -", "- Reserved 25 -",
"- Reserved 26 -", "- Reserved 27 -",
"- Reserved 28 -", "- Reserved 29 -",
"- Reserved 30 -", "- Reserved 31 -",
});
mixLeft1, mixTop8, labelWidth, labelHeight, uiTextSize, ID::tuningType, tuningItems);

addLabel(mixLeft0, mixTop9, labelWidth, labelHeight, uiTextSize, "Tuning Root [st.]");
addTextKnob(
mixLeft1, mixTop9, labelWidth, labelHeight, uiTextSize, ID::tuningRootSemitone,
Scales::tuningRootSemitone, false, 0);

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

// Filter.
constexpr auto filterLabelWidth = 100.0f;
Expand Down Expand Up @@ -222,6 +205,9 @@ bool Editor::prepareUI()
constexpr auto waveformTop0 = top0 + 0 * labelY;
constexpr auto waveformTop1 = waveformTop0 + 1 * labelY;
constexpr auto waveformTop2 = waveformTop1 + barBoxWidth;
constexpr auto waveformTop3 = waveformTop2 + 2 * labelY;
constexpr auto waveformTop4 = waveformTop2 + 3 * labelY;
constexpr auto waveformTop5 = waveformTop2 + 4 * labelY;
constexpr auto waveformLeft0 = left4;
constexpr auto waveformLeft1 = left4 + labelWidth + 2 * margin;
addGroupLabel(
Expand Down Expand Up @@ -270,6 +256,21 @@ bool Editor::prepareUI()
frame->addView(polyXYPad);
}

addLabel(
waveformLeft0, waveformTop3, labelWidth, labelHeight, uiTextSize, "Osc. Sync.");
addTextKnob(
waveformLeft1, waveformTop3, labelWidth, labelHeight, uiTextSize, ID::oscSync,
Scales::defaultScale, false, 5);
addLabel(waveformLeft0, waveformTop4, labelWidth, labelHeight, uiTextSize, "FM Index");
addTextKnob(
waveformLeft1, waveformTop4, labelWidth, labelHeight, uiTextSize, ID::fmIndex,
Scales::fmIndex, false, 5);
addLabel(
waveformLeft0, waveformTop5, labelWidth, labelHeight, uiTextSize, "Saturation [dB]");
addTextKnob(
waveformLeft1, waveformTop5, labelWidth, labelHeight, uiTextSize, ID::saturationGain,
Scales::gain, true, 5);

// Arpeggio.
constexpr auto arpTop0 = top0;
constexpr auto arpTop1 = arpTop0 + 1 * labelY;
Expand Down Expand Up @@ -315,43 +316,40 @@ bool Editor::prepareUI()
arpLeft1, arpTop6, labelWidth, labelHeight, uiTextSize, ID::arpeggioRestChance,
Scales::defaultScale, false, 5);

std::vector<std::string> arpeggioScaleItems{
"Octave",
"ET 5 Chromatic",
"ET 12 Church C (Major Scale)",
"ET 12 Church D",
"ET 12 Church E",
"ET 12 Church F",
"ET 12 Church G",
"ET 12 Church A (Minor Scale)",
"ET 12 Church B",
"ET 12 Suspended 2",
"ET 12 Suspended 4",
"ET 12 Major 7",
"ET 12 Minor 7",
"ET 12 Major 7 Extended",
"ET 12 Minor 7 Extended",
"ET 12 Whole Tone 2",
"ET 12 Whole Tone 3",
"ET 12 Whole Tone 4",
"ET 12 Blues",
"Overtone 32",
"The 42 Melody",
"Overtone Odd 16",
};
for (size_t idx = arpeggioScaleItems.size(); idx <= Scales::arpeggioScale.getMax();
++idx)
{
arpeggioScaleItems.push_back("- Reserved " + std::to_string(idx) + " -");
}
addLabel(arpLeft0, arpTop8, labelWidth, labelHeight, uiTextSize, "Scale");
addOptionMenu(
arpLeft1, arpTop8, labelWidth, labelHeight, uiTextSize, ID::arpeggioScale,
{
"Octave",
"ET 5 Chromatic",
"ET 12 Church C (Major Scale)",
"ET 12 Church D",
"ET 12 Church E",
"ET 12 Church F",
"ET 12 Church G",
"ET 12 Church A (Minor Scale)",
"ET 12 Church B",
"ET 12 Suspended 2",
"ET 12 Suspended 4",
"ET 12 Major 7",
"ET 12 Minor 7",
"ET 12 Major 7 Extended",
"ET 12 Minor 7 Extended",
"ET 12 Whole Tone 2",
"ET 12 Whole Tone 3",
"ET 12 Whole Tone 4",
"ET 12 Blues",
"Overtone 32",
"The 42 Melody",
"Overtone Odd 16",
"- Reserved 22 -",
"- Reserved 23 -",
"- Reserved 24 -",
"- Reserved 25 -",
"- Reserved 26 -",
"- Reserved 27 -",
"- Reserved 28 -",
"- Reserved 29 -",
"- Reserved 30 -",
"- Reserved 31 -",
});
arpeggioScaleItems);

addLabel(arpLeft0, arpTop9, labelWidth, labelHeight, uiTextSize, "Pitch Drift [cent]");
addTextKnob(
arpLeft1, arpTop9, labelWidth, labelHeight, uiTextSize, ID::arpeggioPicthDriftCent,
Expand Down Expand Up @@ -400,16 +398,10 @@ bool Editor::prepareUI()
unisonLeft1, unisonTop4, labelWidth, labelHeight, uiTextSize, "Gain Sqrt.",
ID::unisonGainSqrt);

// Plugin name.
// Plugin name and randomize button.
constexpr auto splashMargin = uiMargin;
constexpr auto splashTop = top0 + 17 * labelY;
constexpr auto splashTop = top0 + 18 * labelY - 2 * margin;
constexpr auto splashLeft = left4;
addSplashScreen(
splashLeft, splashTop, labelWidth, splashHeight, splashMargin, splashMargin,
defaultWidth - 2 * splashMargin, defaultHeight - 2 * splashMargin, pluginNameTextSize,
"GlitchSprinkler", false);

// Randomize button.
const auto randomButtonTop = splashTop;
const auto randomButtonLeft = splashLeft + labelWidth + 2 * margin;
auto panicButton = new RandomizeButton(
Expand All @@ -419,6 +411,11 @@ bool Editor::prepareUI()
this, 0, "Randomize", getFont(pluginNameTextSize), palette, this);
frame->addView(panicButton);

addSplashScreen(
splashLeft, splashTop, labelWidth, splashHeight, splashMargin, splashMargin,
defaultWidth - 2 * splashMargin, defaultHeight - 2 * splashMargin, pluginNameTextSize,
"GlitchSprinkler", false);

return true;
}

Expand Down
2 changes: 1 addition & 1 deletion GlitchSprinkler/source/gui/polynomialxypad.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ class PolynomialXYPad : public ArrayControl {
[&](double ratio) {
return double(0.5) + double(0.5) * std::tanh(std::sin(twopi * ratio));
});
} else if (event.character == '0') { // Preset: saturated sine.
} else if (event.character == '0') { // Preset: Silent.
setControlPoints(
[&](double ratio) { return ratio; }, [&](double ratio) { return double(0.5); });
} else if (event.character == 'r') { // Randomize.
Expand Down
Loading

0 comments on commit 61cf23e

Please sign in to comment.