Skip to content

Commit

Permalink
Add randomization button to GenericDrum
Browse files Browse the repository at this point in the history
  • Loading branch information
ryukau committed Oct 20, 2023
1 parent fa65058 commit 6900427
Show file tree
Hide file tree
Showing 4 changed files with 266 additions and 47 deletions.
79 changes: 40 additions & 39 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,46 +16,47 @@ add_subdirectory(common)
add_subdirectory(lib/vst3sdk)
smtg_enable_vst3_sdk()

add_subdirectory(AccumulativeRingMod)
add_subdirectory(BasicLimiter)
add_subdirectory(BasicLimiterAutoMake)
add_subdirectory(ClangCymbal)
add_subdirectory(ClangSynth)
add_subdirectory(CollidingCombSynth)
add_subdirectory(CombDistortion)
add_subdirectory(CubicPadSynth)
add_subdirectory(EnvelopedSine)
add_subdirectory(EsPhaser)
add_subdirectory(FDN64Reverb)
add_subdirectory(FDNCymbal)
add_subdirectory(FeedbackPhaser)
add_subdirectory(FoldShaper)
# add_subdirectory(AccumulativeRingMod)
# add_subdirectory(BasicLimiter)
# add_subdirectory(BasicLimiterAutoMake)
# add_subdirectory(ClangCymbal)
# add_subdirectory(ClangSynth)
# add_subdirectory(CollidingCombSynth)
# add_subdirectory(CombDistortion)
# add_subdirectory(CubicPadSynth)
# add_subdirectory(EnvelopedSine)
# add_subdirectory(EsPhaser)
# add_subdirectory(FDN64Reverb)
# add_subdirectory(FDNCymbal)
# add_subdirectory(FeedbackPhaser)
# add_subdirectory(FoldShaper)
add_subdirectory(GenericDrum)
add_subdirectory(IterativeSinCluster)
add_subdirectory(L3Reverb)
add_subdirectory(L4Reverb)
add_subdirectory(LatticeReverb)
add_subdirectory(LightPadSynth)
add_subdirectory(LongPhaser)
add_subdirectory(MatrixShifter)
add_subdirectory(MaybeSnare)
add_subdirectory(MembraneSynth)
add_subdirectory(MiniCliffEQ)
add_subdirectory(ModuloShaper)
add_subdirectory(NarrowingDelay)
add_subdirectory(OddPowShaper)
add_subdirectory(OrdinaryPhaser)
add_subdirectory(ParallelComb)
add_subdirectory(ParallelDetune)
add_subdirectory(PitchShiftDelay)
add_subdirectory(RingModSpacer)
add_subdirectory(SevenDelay)
add_subdirectory(SoftClipper)
add_subdirectory(SyncSawSynth)
add_subdirectory(TrapezoidSynth)
add_subdirectory(UltraSynth)
add_subdirectory(UltrasonicRingMod)
add_subdirectory(WaveCymbal)

# add_subdirectory(IterativeSinCluster)
# add_subdirectory(L3Reverb)
# add_subdirectory(L4Reverb)
# add_subdirectory(LatticeReverb)
# add_subdirectory(LightPadSynth)
# add_subdirectory(LongPhaser)
# add_subdirectory(MatrixShifter)
# add_subdirectory(MaybeSnare)
# add_subdirectory(MembraneSynth)
# add_subdirectory(MiniCliffEQ)
# add_subdirectory(ModuloShaper)
# add_subdirectory(NarrowingDelay)
# add_subdirectory(OddPowShaper)
# add_subdirectory(OrdinaryPhaser)
# add_subdirectory(ParallelComb)
# add_subdirectory(ParallelDetune)
# add_subdirectory(PitchShiftDelay)
# add_subdirectory(RingModSpacer)
# add_subdirectory(SevenDelay)
# add_subdirectory(SoftClipper)
# add_subdirectory(SyncSawSynth)
# add_subdirectory(TrapezoidSynth)
# add_subdirectory(UltraSynth)
# add_subdirectory(UltrasonicRingMod)
# add_subdirectory(WaveCymbal)

# ## Below are prototype plugins. Breaking changes will be introduced.
# add_subdirectory(TestBedSynth)
Expand Down
19 changes: 15 additions & 4 deletions GenericDrum/source/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "editor.hpp"
#include "../../lib/pcg-cpp/pcg_random.hpp"
#include "gui/randomizebutton.hpp"
#include "version.hpp"

#include <algorithm>
Expand All @@ -36,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(labelHeight * 3 / 2);
constexpr float splashHeight = int(2 * labelHeight + 2 * margin);

constexpr float barBoxWidth = groupLabelWidth;
constexpr float barBoxHeight = 5 * labelY - 2 * margin;
Expand Down Expand Up @@ -523,12 +524,22 @@ bool Editor::prepareUI()
secondaryLeft0, secondaryTop5, groupLabelWidth, labelHeight, uiTextSize,
"Membrane collision status.");

// Randomize button.
const auto randomButtonTop = top0 + 18 * labelY;
const auto randomButtonLeft = left0 + labelWidth + 2 * margin;
auto panicButton = new RandomizeButton(
CRect(
randomButtonLeft, randomButtonTop, randomButtonLeft + labelWidth,
randomButtonTop + splashHeight),
this, 0, "Random", getFont(pluginNameTextSize), palette, this);
frame->addView(panicButton);

// Plugin name.
constexpr auto splashMargin = uiMargin;
constexpr auto splashTop = top0 + 18 * labelY + int(labelHeight / 4) + 2 * margin;
constexpr auto splashLeft = left0 + int(labelWidth / 4);
constexpr auto splashTop = top0 + 18 * labelY;
constexpr auto splashLeft = left0;
addSplashScreen(
splashLeft, splashTop, splashWidth, splashHeight, splashMargin, splashMargin,
splashLeft, splashTop, labelWidth, splashHeight, splashMargin, splashMargin,
defaultWidth - 2 * splashMargin, defaultHeight - 2 * splashMargin, pluginNameTextSize,
"GenericDrum", false);

Expand Down
207 changes: 207 additions & 0 deletions GenericDrum/source/gui/randomizebutton.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
// (c) 2023 Takamitsu Endo
//
// This file is part of GenericDrum.
//
// GenericDrum is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GenericDrum is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with GenericDrum. If not, see <https://www.gnu.org/licenses/>.

#pragma once

#include "public.sdk/source/vst/vsteditcontroller.h"
#include "vstgui/vstgui.h"

#include "../../../common/gui/plugeditor.hpp"
#include "../../../common/gui/style.hpp"
#include "../parameter.hpp"

#include <algorithm>
#include <random>
#include <string>

namespace VSTGUI {

class RandomizeButton : public CControl {
public:
std::string label;

RandomizeButton(
const CRect &size,
IControlListener *listener,
int32_t tag,
std::string label,
const SharedPointer<CFontDesc> &fontId,
Uhhyou::Palette &palette,
Steinberg::Vst::PlugEditor *editor)
: CControl(size, listener, tag)
, label(label)
, fontId(fontId)
, pal(palette)
, editor(editor)
{
if (editor) editor->remember();
}

~RandomizeButton()
{
if (editor) editor->forget();
}

void draw(CDrawContext *pContext) override
{
pContext->setDrawMode(CDrawMode(CDrawModeFlags::kAntiAliasing));
CDrawContext::Transform t(
*pContext, CGraphicsTransform().translate(getViewSize().getTopLeft()));

// Border.
const double borderW = isMouseEntered ? 2 * borderWidth : borderWidth;
const double halfBorderWidth = int(borderW / 2.0);
pContext->setFillColor(isPressed ? pal.highlightButton() : pal.boxBackground());
pContext->setFrameColor(
isMouseEntered && !isPressed ? pal.highlightButton() : pal.border());
pContext->setLineWidth(borderW);
pContext->drawRect(
CRect(
halfBorderWidth, halfBorderWidth, getWidth() - halfBorderWidth,
getHeight() - halfBorderWidth),
kDrawFilledAndStroked);

// Text
pContext->setFont(fontId);
pContext->setFontColor(pal.foreground());
pContext->drawString(
label.c_str(), CRect(0, 0, getWidth(), getHeight()), kCenterText);
}

void onMouseEnterEvent(MouseEnterEvent &event) override
{
isMouseEntered = true;
invalid();
event.consumed = true;
}

void onMouseExitEvent(MouseExitEvent &event) override
{
if (value == 1.0f) {
value = 0.0f;
}
isPressed = false;
isMouseEntered = false;
invalid();
event.consumed = true;
}

void onMouseDownEvent(MouseDownEvent &event) override
{
using ID = Steinberg::Synth::ParameterID::ID;

if (!event.buttonState.isLeft()) return;
isPressed = true;
value = 1.0f;

if (editor) {
using Rng = std::mt19937_64;

std::random_device source;
std::random_device::result_type
random_data[(Rng::state_size - 1) / sizeof(source()) + 1];
std::generate(std::begin(random_data), std::end(random_data), std::ref(source));
std::seed_seq seeds(std::begin(random_data), std::end(random_data));
Rng rng(seeds);

std::uniform_real_distribution<Steinberg::Vst::ParamValue> uniform{0.0, 1.0};
setParam(ID::seed, uniform(rng));
setParam(ID::noiseDecaySeconds, uniform(rng));
setParam(ID::noiseLowpassHz, uniform(rng));
setParam(ID::noiseAllpassMaxTimeHz, uniform(rng));

setParam(ID::impactWireMix, uniform(rng));
setParam(ID::membraneWireMix, uniform(rng));
setParam(ID::wireFrequencyHz, uniform(rng));
setParam(ID::wireDecaySeconds, uniform(rng));
setParam(ID::wireDistance, uniform(rng));
setParam(ID::wireCollisionTypeMix, uniform(rng));

// setParam(ID::crossFeedbackGain, uniform(rng));
for (int idx = 0; idx < maxFdnSize; ++idx) {
setParam(ID::crossFeedbackRatio0 + idx, uniform(rng));
}

setParam(ID::delayTimeSpread, uniform(rng));
setParam(ID::bandpassCutSpread, uniform(rng));
setParam(ID::pitchRandomCent, uniform(rng));

setParam(ID::envelopeAttackSeconds, uniform(rng));
setParam(ID::envelopeDecaySeconds, uniform(rng));
setParam(ID::envelopeModAmount, uniform(rng));

// setParam(ID::pitchType, uniform(rng));
setParam(ID::delayTimeHz, uniform(rng));
setParam(ID::delayTimeModAmount, uniform(rng));
setParam(ID::bandpassCutRatio, uniform(rng));
setParam(ID::bandpassQ, uniform(rng));

setParam(ID::secondaryFdnMix, uniform(rng));
setParam(ID::secondaryPitchOffset, uniform(rng));
setParam(ID::secondaryQOffset, uniform(rng));
setParam(ID::secondaryDistance, uniform(rng));
}

invalid();
event.consumed = true;
}

void onMouseUpEvent(MouseUpEvent &event) override
{
if (isPressed) {
isPressed = false;
value = 0.0f;
invalid();
}
event.consumed = true;
}

void onMouseCancelEvent(MouseCancelEvent &event) override
{
if (isPressed) {
isPressed = false;
value = 0;
invalid();
}
isMouseEntered = false;
event.consumed = true;
}

void setBorderWidth(CCoord width) { borderWidth = width < 0 ? 0 : width; }

CLASS_METHODS(RandomizeButton, CControl);

private:
// Before calling check if `editor` is not nullptr.
inline void setParam(Steinberg::Vst::ParamID id, Steinberg::Vst::ParamValue value)
{
editor->valueChanged(id, value);
editor->updateUI(id, value);
}

Steinberg::Vst::PlugEditor *editor = nullptr;

SharedPointer<CFontDesc> fontId;
Uhhyou::Palette &pal;

CCoord borderWidth = 1.0;

bool isPressed = false;
bool isMouseEntered = false;
};

} // namespace VSTGUI
8 changes: 4 additions & 4 deletions GenericDrum/source/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
#define SUB_VERSION_STR "1"
#define SUB_VERSION_INT 1

#define RELEASE_NUMBER_STR "0"
#define RELEASE_NUMBER_INT 0
#define RELEASE_NUMBER_STR "1"
#define RELEASE_NUMBER_INT 1

#define BUILD_NUMBER_STR "5"
#define BUILD_NUMBER_INT 5
#define BUILD_NUMBER_STR "6"
#define BUILD_NUMBER_INT 6

#define FULL_VERSION_STR \
MAJOR_VERSION_STR "." SUB_VERSION_STR "." RELEASE_NUMBER_STR "." BUILD_NUMBER_STR
Expand Down

0 comments on commit 6900427

Please sign in to comment.