diff --git a/CMakeLists.txt b/CMakeLists.txt index ede812b..cafd384 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,7 +51,7 @@ target_compile_definitions(Trommelkiste PRIVATE JUCE_WEB_BROWSER=0 JUCE_USE_CURL=0 JUCE_VST3_CAN_REPLACE_VST2=0 - JUCE_DISPLAY_SPLASH_SCREEN=0 + ) target_link_libraries(Trommelkiste diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index 9e81ddd..2a2a59b 100644 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -9,7 +9,7 @@ static const char* trackNames[] = {"BD", "RS", "SN", "CL", "CH", "PH", "OH", "R static const char* noteNames[] = {"C4","C#4","D4","D#4","E4","F4","F#4","G4","G#4","A4"}; static constexpr int ROW_H = 52; -static constexpr int TOP = 100; +static constexpr int TOP = 82; static constexpr int COL_LBL = 8; static constexpr int COL_KNOB = 44; static constexpr int KNOB_W = 44; @@ -22,7 +22,7 @@ static constexpr int COL_REVERB = COL_DELAY + KNOB_W + KNOB_GAP; static constexpr int COL_RINGMOD = COL_REVERB + KNOB_W + KNOB_GAP; static constexpr int COL_DESTR = COL_RINGMOD + KNOB_W + KNOB_GAP; static constexpr int COL_SHUFFLE = COL_DESTR + KNOB_W + KNOB_GAP; -static constexpr int TOTAL_W = COL_SHUFFLE + KNOB_W + 8; +static constexpr int TOTAL_W = COL_SHUFFLE + KNOB_W; // Header knob x positions (compact layout) static constexpr int HDR_KNOB = 36; @@ -60,30 +60,13 @@ void TrommelkisteLookAndFeel::drawRotarySlider(Graphics& g, int x, int y, int w, // Main body — vertical gradient (light top, dark bottom) for 3D cylinder feel { - ColourGradient grad(Colour(0xFF444444), cx, cy - radius, - Colour(0xFF2C2C2C), cx, cy + radius, true); - grad.addColour(0.35, Colour(0xFF3D3D3D)); + ColourGradient grad(Colour(0xFF323232), cx, cy - radius, + Colour(0xFF1C1C1C), cx, cy + radius, true); + grad.addColour(0.10, Colour(0x883D3D3D)); g.setGradientFill(grad); g.fillEllipse(cx - radius, cy - radius, radius * 2.0f, radius * 2.0f); } - // Top highlight ring (specular edge) - { - Path ring; - ring.addCentredArc(cx, cy, radius - 0.5f, radius - 0.5f, 0.0f, 0.0f, MathConstants::pi, true); - g.setColour(Colour(0x1EFFFFFF)); - g.strokePath(ring, PathStrokeType(1.5f, PathStrokeType::curved, PathStrokeType::rounded)); - } - - // Bottom dark ring - { - Path ring; - ring.addCentredArc(cx, cy, radius - 0.5f, radius - 0.5f, 0.0f, - MathConstants::pi, MathConstants::pi * 2.0f, true); - g.setColour(Colour(0x1E000000)); - g.strokePath(ring, PathStrokeType(1.5f, PathStrokeType::curved, PathStrokeType::rounded)); - } - // Subtle specular highlight blob (top-left) { ColourGradient spec(Colour(0x18FFFFFF), cx - radius * 0.35f, cy - radius * 0.5f, @@ -207,7 +190,7 @@ TrommelkisteEditor::TrommelkisteEditor(TrommelkisteProcessor& p) setLookAndFeel(&lnf); lnf.fontScale = 1.5f; uiScale = 1.5f; - setSize(scaled(TOTAL_W), scaled(TOP + NUM_TRACKS * ROW_H + 12)); + setSize(scaled(TOTAL_W), scaled(TOP + NUM_TRACKS * ROW_H)); setResizable(false, false); setWantsKeyboardFocus(false); @@ -388,7 +371,7 @@ TrommelkisteEditor::TrommelkisteEditor(TrommelkisteProcessor& p) globalShuffleDiv.setRange(0, 4, 1); globalShuffleDiv.setScrollWheelEnabled(false); globalShuffleDiv.formatFn = [](double v) { - static const char* labels[] = { "1", "4", "8", "16", "32" }; + static const char* labels[] = { "OFF", "4", "8", "16", "32" }; return labels[juce::jlimit(0, 4, (int)v)]; }; addAndMakeVisible(globalShuffleDiv); @@ -433,7 +416,7 @@ void TrommelkisteEditor::timerCallback() const double now = juce::Time::getMillisecondCounterHiRes() / 1000.0; for (int i = 0; i < NUM_TRACKS; ++i) { - if (proc.trackActive[i]) + if (proc.trackActive[i].exchange(false)) trackActivatedTime[i] = now; } repaint(); @@ -447,7 +430,7 @@ void TrommelkisteEditor::scaleChanged() { uiScale = scales[selId - 1]; lnf.fontScale = uiScale; - setSize(scaled(TOTAL_W), scaled(TOP + NUM_TRACKS * ROW_H + 12)); + setSize(scaled(TOTAL_W), scaled(TOP + NUM_TRACKS * ROW_H)); } } @@ -479,52 +462,71 @@ void TrommelkisteEditor::paint(Graphics& g) g.setFont(fontBold(16.0f, uiScale)); g.drawText("TROMMELKISTE", scaled(10), scaled(4), scaled(400), scaled(20), Justification::centredLeft); - g.setColour(lnf.accent.withAlpha(0.3f)); - g.fillRect(scaled(10), scaled(71), scaled(getWidth() - 20), scaled(1)); + // VU meter + { + const float level = proc.outputLevel.load(std::memory_order_relaxed); + const float meterX = 10.0f; + const float meterY = 30.0f; + const float meterW = 134.0f; + const float meterH = 6.0f; - // Section labels - g.setColour(Colours::green.brighter(0.6f)); - g.setFont(font(8.0f, uiScale)); - int masterCenter = (HDR_VOL + HDR_DLYSYNC + HDR_KNOB) / 2; - int shuffleCenter = (HDR_DIV + HDR_GRV + HDR_KNOB) / 2; - g.drawText("MASTER", scaled(masterCenter - 20), scaled(0), scaled(40), scaled(8), Justification::centred); - g.drawText("SHUFFLE", scaled(shuffleCenter - 20), scaled(0), scaled(40), scaled(8), Justification::centred); + // Background + g.setColour(Colour(0xFF111111)); + g.fillRect(scaled((int) meterX), scaled((int) meterY), scaled((int) meterW), scaled((int) meterH)); + + // Level bar (dB normalized: -40 dB..0 dB maps to 0..1) + float norm = 0.0f; + if (level > 0.001f) + { + float db = 20.0f * std::log10(level); + norm = jlimit(0.0f, 1.0f, (db + 40.0f) / 40.0f); + } + float barW = meterW * norm; + g.setColour(lnf.accent); + g.fillRect(scaled((int) meterX), scaled((int) meterY), scaled((int) barW), scaled((int) meterH)); + } + + g.setColour(lnf.accent.withAlpha(0.3f)); + g.fillRect(scaled(10), scaled(60), getWidth() - scaled(15), scaled(1)); g.setColour(Colours::white.withAlpha(0.9f)); g.setFont(font(8.0f, uiScale)); - g.drawText("VOL", scaled(HDR_VOL), scaled(51), scaled(HDR_KNOB), scaled(10), Justification::centred); - g.drawText("PAN", scaled(HDR_PAN), scaled(51), scaled(HDR_KNOB), scaled(10), Justification::centred); - g.drawText("RING", scaled(HDR_RING), scaled(51), scaled(HDR_KNOB), scaled(10), Justification::centred); - g.drawText("DEST", scaled(HDR_DEST), scaled(51), scaled(HDR_KNOB), scaled(10), Justification::centred); - g.drawText("DLY", scaled(HDR_DELAY), scaled(51), scaled(HDR_KNOB), scaled(10), Justification::centred); - g.drawText("REV", scaled(HDR_REVERB), scaled(51), scaled(HDR_KNOB), scaled(10), Justification::centred); - g.drawText("SYNC", scaled(HDR_DLYSYNC), scaled(51), scaled(HDR_KNOB), scaled(10), Justification::centred); + g.drawText("VOL", scaled(HDR_VOL), scaled(46), scaled(HDR_KNOB), scaled(10), Justification::centred); + g.drawText("PAN", scaled(HDR_PAN), scaled(46), scaled(HDR_KNOB), scaled(10), Justification::centred); + g.drawText("RING", scaled(HDR_RING), scaled(46), scaled(HDR_KNOB), scaled(10), Justification::centred); + g.drawText("DEST", scaled(HDR_DEST), scaled(46), scaled(HDR_KNOB), scaled(10), Justification::centred); + g.drawText("DLY", scaled(HDR_DELAY), scaled(46), scaled(HDR_KNOB), scaled(10), Justification::centred); + g.drawText("REV", scaled(HDR_REVERB), scaled(46), scaled(HDR_KNOB), scaled(10), Justification::centred); + g.drawText("SYNC", scaled(HDR_DLYSYNC), scaled(46), scaled(HDR_KNOB), scaled(10), Justification::centred); // Shuffle section separator g.setColour(lnf.accent.withAlpha(0.5f)); - g.fillRect(scaled(HDR_DIV - 8), scaled(6), scaled(1), scaled(65)); + g.fillRect(scaled(HDR_DIV - 8), scaled(6), scaled(1), scaled(46)); + + g.setColour(Colour(0xFF3A3A1E).withAlpha(0.4f)); + g.fillRect(scaled(HDR_RING), scaled(8), scaled(HDR_KNOB), scaled(HDR_KNOB)); g.setColour(Colours::white.withAlpha(0.9f)); g.setFont(font(8.0f, uiScale)); - g.drawText("EVERY", scaled(HDR_DIV), scaled(51), scaled(HDR_KNOB), scaled(10), Justification::centred); - g.drawText("AMT", scaled(HDR_SHFL), scaled(51), scaled(HDR_KNOB), scaled(10), Justification::centred); - g.drawText("GROOVE", scaled(HDR_GRV), scaled(51), scaled(HDR_KNOB), scaled(10), Justification::centred); + g.drawText("DIV", scaled(HDR_DIV), scaled(46), scaled(HDR_KNOB), scaled(10), Justification::centred); + g.drawText("SHFL", scaled(HDR_SHFL), scaled(46), scaled(HDR_KNOB), scaled(10), Justification::centred); + g.drawText("GRV", scaled(HDR_GRV), scaled(46), scaled(HDR_KNOB), scaled(10), Justification::centred); g.setColour(Colours::white.withAlpha(0.9f)); g.setFont(font(9.0f, uiScale)); - g.drawText("LVL", scaled(COL_KNOB), scaled(78), scaled(KNOB_W), scaled(12), Justification::centred); - g.drawText("LEN", scaled(COL_KNOB + 1*(KNOB_W + KNOB_GAP)), scaled(78), scaled(KNOB_W), scaled(12), Justification::centred); - g.drawText("VEL", scaled(COL_KNOB + 2*(KNOB_W + KNOB_GAP)), scaled(78), scaled(KNOB_W), scaled(12), Justification::centred); - g.drawText("PIT", scaled(COL_KNOB + 3*(KNOB_W + KNOB_GAP)), scaled(78), scaled(KNOB_W), scaled(12), Justification::centred); - g.drawText("TONE", scaled(COL_KNOB + 4*(KNOB_W + KNOB_GAP)), scaled(78), scaled(KNOB_W), scaled(12), Justification::centred); - g.drawText("PAN", scaled(COL_KNOB + 5*(KNOB_W + KNOB_GAP)), scaled(78), scaled(KNOB_W), scaled(12), Justification::centred); - g.drawText("DECAY", scaled(COL_DECAY), scaled(78), scaled(68), scaled(12), Justification::centred); - g.drawText("SAMPLE", scaled(COL_FILE), scaled(78), scaled(SAMPLE_W), scaled(12), Justification::centred); - g.drawText("DELAY", scaled(COL_DELAY), scaled(78), scaled(KNOB_W), scaled(12), Justification::centred); - g.drawText("REVERB", scaled(COL_REVERB), scaled(78), scaled(KNOB_W), scaled(12), Justification::centred); - g.drawText("RING", scaled(COL_RINGMOD), scaled(78), scaled(KNOB_W), scaled(12), Justification::centred); - g.drawText("DESTR", scaled(COL_DESTR), scaled(78), scaled(KNOB_W), scaled(12), Justification::centred); - g.drawText("SHFL", scaled(COL_SHUFFLE), scaled(78), scaled(KNOB_W), scaled(12), Justification::centred); + g.drawText("LVL", scaled(COL_KNOB), scaled(65), scaled(KNOB_W), scaled(12), Justification::centred); + g.drawText("LEN", scaled(COL_KNOB + 1*(KNOB_W + KNOB_GAP)), scaled(65), scaled(KNOB_W), scaled(12), Justification::centred); + g.drawText("VEL", scaled(COL_KNOB + 2*(KNOB_W + KNOB_GAP)), scaled(65), scaled(KNOB_W), scaled(12), Justification::centred); + g.drawText("PIT", scaled(COL_KNOB + 3*(KNOB_W + KNOB_GAP)), scaled(65), scaled(KNOB_W), scaled(12), Justification::centred); + g.drawText("TONE", scaled(COL_KNOB + 4*(KNOB_W + KNOB_GAP)), scaled(65), scaled(KNOB_W), scaled(12), Justification::centred); + g.drawText("PAN", scaled(COL_KNOB + 5*(KNOB_W + KNOB_GAP)), scaled(65), scaled(KNOB_W), scaled(12), Justification::centred); + g.drawText("DECAY", scaled(COL_DECAY), scaled(65), scaled(68), scaled(12), Justification::centred); + g.drawText("SAMPLE", scaled(COL_FILE), scaled(65), scaled(SAMPLE_W), scaled(12), Justification::centred); + g.drawText("DELAY", scaled(COL_DELAY), scaled(65), scaled(KNOB_W), scaled(12), Justification::centred); + g.drawText("REVERB", scaled(COL_REVERB), scaled(65), scaled(KNOB_W), scaled(12), Justification::centred); + g.drawText("RING", scaled(COL_RINGMOD), scaled(65), scaled(KNOB_W), scaled(12), Justification::centred); + g.drawText("DESTR", scaled(COL_DESTR), scaled(65), scaled(KNOB_W), scaled(12), Justification::centred); + g.drawText("SHFL", scaled(COL_SHUFFLE), scaled(65), scaled(KNOB_W), scaled(12), Justification::centred); const double now = juce::Time::getMillisecondCounterHiRes() / 1000.0; for (int i = 0; i < NUM_TRACKS; ++i) @@ -559,11 +561,11 @@ void TrommelkisteEditor::paint(Graphics& g) g.setColour(Colours::white); g.setFont(fontBold(12.0f, uiScale)); - g.drawText(trackNames[i], scaled(COL_LBL), scaled(ry + 6), scaled(32), scaled(16), Justification::centredLeft); + g.drawText(trackNames[i], scaled(COL_LBL), scaled(ry + 14), scaled(32), scaled(16), Justification::centredLeft); g.setColour(Colour(0xFF666666)); g.setFont(font(9.0f, uiScale)); - g.drawText(noteNames[i], scaled(COL_LBL), scaled(ry + 24), scaled(32), scaled(14), Justification::centredLeft); + g.drawText(noteNames[i], scaled(COL_LBL), scaled(ry + 28), scaled(32), scaled(14), Justification::centredLeft); const double elapsed = now - trackActivatedTime[i]; if (elapsed < 0.4) @@ -585,16 +587,16 @@ void TrommelkisteEditor::resized() // Header knobs const int hk = HDR_KNOB; - masterVolume.setBounds(scaled(HDR_VOL), scaled(13), scaled(hk), scaled(hk)); - masterPan.setBounds(scaled(HDR_PAN), scaled(13), scaled(hk), scaled(hk)); - globalRingFreq.setBounds(scaled(HDR_RING), scaled(13), scaled(hk), scaled(hk)); - globalDestruction.setBounds(scaled(HDR_DEST), scaled(13), scaled(hk), scaled(hk)); - masterDelay.setBounds(scaled(HDR_DELAY), scaled(13), scaled(hk), scaled(hk)); - masterReverb.setBounds(scaled(HDR_REVERB), scaled(13), scaled(hk), scaled(hk)); - delaySyncDiv.setBounds(scaled(HDR_DLYSYNC), scaled(13), scaled(hk), scaled(hk)); - globalShuffleDiv.setBounds(scaled(HDR_DIV), scaled(13), scaled(hk), scaled(hk)); - globalShuffleAmt.setBounds(scaled(HDR_SHFL), scaled(13), scaled(hk), scaled(hk)); - globalGroove.setBounds(scaled(HDR_GRV), scaled(13), scaled(hk), scaled(hk)); + masterVolume.setBounds(scaled(HDR_VOL), scaled(8), scaled(hk), scaled(hk)); + masterPan.setBounds(scaled(HDR_PAN), scaled(8), scaled(hk), scaled(hk)); + globalRingFreq.setBounds(scaled(HDR_RING), scaled(8), scaled(hk), scaled(hk)); + globalDestruction.setBounds(scaled(HDR_DEST), scaled(8), scaled(hk), scaled(hk)); + masterDelay.setBounds(scaled(HDR_DELAY), scaled(8), scaled(hk), scaled(hk)); + masterReverb.setBounds(scaled(HDR_REVERB), scaled(8), scaled(hk), scaled(hk)); + delaySyncDiv.setBounds(scaled(HDR_DLYSYNC), scaled(8), scaled(hk), scaled(hk)); + globalShuffleDiv.setBounds(scaled(HDR_DIV), scaled(8), scaled(hk), scaled(hk)); + globalShuffleAmt.setBounds(scaled(HDR_SHFL), scaled(8), scaled(hk), scaled(hk)); + globalGroove.setBounds(scaled(HDR_GRV), scaled(8), scaled(hk), scaled(hk)); for (int i = 0; i < NUM_TRACKS; ++i) { diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index 9f77825..f42e88f 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -65,16 +65,20 @@ void TrommelkisteProcessor::processBlock(juce::AudioBuffer& buffer, juce: static constexpr int shuffleDivBars[] = { 0, 4, 8, 16, 32 }; const int divBars = shuffleDivBars[juce::jlimit(0, 4, shuffleDivIdx)]; - // Try to get bar position from play head + // Try to get transport info from play head bool hasTransport = false; int64_t currentBar = 0; + double ppq = 0.0; + double bpm = 120.0; if (auto* ph = getPlayHead()) { auto info = ph->getPosition(); if (info.hasValue() && info->getPpqPosition().hasValue()) { hasTransport = true; - double ppq = *info->getPpqPosition(); + ppq = *info->getPpqPosition(); + if (info->getBpm().hasValue()) + bpm = *info->getBpm(); double beatsPerBar = 4.0; if (info->getTimeSignature().hasValue()) beatsPerBar = (double)(*info->getTimeSignature()).numerator; @@ -84,8 +88,14 @@ void TrommelkisteProcessor::processBlock(juce::AudioBuffer& buffer, juce: const bool barAllowed = (divBars == 0) || !hasTransport || (currentBar % divBars == 0); + // 16th note grid quantization (DAW shuffle is reflected in PPQ) + const double ppqPerSample = bpm / (60.0 * currentSampleRate); + const double sixteenthPpq = 0.25; + auto nextGridPpq = [&](double fromPpq) -> double { + return std::ceil((fromPpq + 0.0001) / sixteenthPpq) * sixteenthPpq; + }; + // Process pending shuffle events - const int baseDelay = (int)(currentSampleRate * 0.05 * globalGroove); // up to 50ms at max groove for (int i = numPendingShuffle - 1; i >= 0; --i) { pendingShuffle[i].delaySamples -= numSamples; @@ -96,18 +106,18 @@ void TrommelkisteProcessor::processBlock(juce::AudioBuffer& buffer, juce: } } - // Independent shuffle: generate events even without MIDI input + // Independent shuffle: generate events even without MIDI input, on the same track std::uniform_real_distribution dist(0.0f, 1.0f); - if (globalShuffleAmt > 0.0f && barAllowed) + if (globalShuffleAmt > 0.0f && barAllowed && lastTriggeredTrack >= 0) { - std::uniform_int_distribution trackDist(0, NUM_TRACKS - 1); - float prob = globalShuffleAmt * 0.15f; // base probability per block + float prob = globalShuffleAmt * 0.15f; if (dist(rng) < prob && numPendingShuffle < MAX_PENDING_SHUFFLE) { - int target = trackDist(rng); float vel = (0.3f + dist(rng) * 0.5f) * globalShuffleAmt; - int delay = (int)(baseDelay * (0.5f + dist(rng) * 0.5f)); - pendingShuffle[numPendingShuffle++] = { target, vel, delay }; + int stepsAhead = std::uniform_int_distribution(1, 4)(rng); + double gridPpq = nextGridPpq(ppq) + stepsAhead * sixteenthPpq; + int delay = juce::jmax(1, (int)((gridPpq - ppq) / ppqPerSample)); + pendingShuffle[numPendingShuffle++] = { lastTriggeredTrack, vel, delay }; } } @@ -120,6 +130,7 @@ void TrommelkisteProcessor::processBlock(juce::AudioBuffer& buffer, juce: if (t >= 0 && t < NUM_TRACKS) { handleNoteOn(t, msg.getFloatVelocity()); + lastTriggeredTrack = t; const float shuffleAmt = apvts.getRawParameterValue( "t" + juce::String(t) + "_shuffle")->load(); @@ -127,26 +138,17 @@ void TrommelkisteProcessor::processBlock(juce::AudioBuffer& buffer, juce: if (effShuffle > 0.0f && barAllowed) { - int maxEvents = juce::jmax(1, (int)(effShuffle * 3.0f + 0.5f)); - int numEvents = std::uniform_int_distribution(0, maxEvents)(rng); + int numEvents = juce::jmax(1, (int)(effShuffle * 3.0f + 0.5f)); + numEvents = std::uniform_int_distribution(0, numEvents)(rng); for (int e = 0; e < numEvents; ++e) { - bool sameTrack = dist(rng) < 0.35f; - int target = t; - if (!sameTrack) - { - target = std::uniform_int_distribution(0, NUM_TRACKS - 1)(rng); - if (target == t) - target = (t + 1 + std::uniform_int_distribution(0, NUM_TRACKS - 2)(rng)) % NUM_TRACKS; - } - float vel = msg.getFloatVelocity() * (0.3f + dist(rng) * 0.7f) * effShuffle; + int stepsAhead = std::uniform_int_distribution(1, 4)(rng); + double gridPpq = nextGridPpq(ppq) + stepsAhead * sixteenthPpq; + int delay = juce::jmax(1, (int)((gridPpq - ppq) / ppqPerSample)); if (numPendingShuffle < MAX_PENDING_SHUFFLE) - { - int delay = (int)(baseDelay * (0.5f + dist(rng) * 0.5f)); - pendingShuffle[numPendingShuffle++] = { target, vel, delay }; - } + pendingShuffle[numPendingShuffle++] = { t, vel, delay }; } } } @@ -822,7 +824,7 @@ juce::AudioProcessorValueTreeState::ParameterLayout TrommelkisteProcessor::creat layout.add(std::make_unique( "global_shuffleAmount", "Shuffle Amt", - NormalisableRange(0.0f, 1.0f, 0.01f), 1.0f)); + NormalisableRange(0.0f, 1.0f, 0.01f), 0.0f)); layout.add(std::make_unique( "global_groove", "Groove", diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h index 579d664..47f3f14 100644 --- a/Source/PluginProcessor.h +++ b/Source/PluginProcessor.h @@ -126,6 +126,7 @@ private: static constexpr int MAX_PENDING_SHUFFLE = 32; PendingShuffleEvent pendingShuffle[MAX_PENDING_SHUFFLE]; int numPendingShuffle = 0; + int lastTriggeredTrack = -1; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(TrommelkisteProcessor) };