mirror of
https://codeberg.org/armin/sm-26.git
synced 2026-10-11 17:01:53 +02:00
SM-26 synthesizer: initial implementation
This commit is contained in:
commit
8734ac25f1
18 changed files with 2619 additions and 0 deletions
66
Source/MenuSystem.h
Normal file
66
Source/MenuSystem.h
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
#pragma once
|
||||
|
||||
#include <JuceHeader.h>
|
||||
#include "SynthParams.h"
|
||||
|
||||
class MenuSystem;
|
||||
|
||||
struct MenuItem
|
||||
{
|
||||
enum Kind { Action, Value, Submenu, Separator };
|
||||
|
||||
juce::String label;
|
||||
Kind kind = Action;
|
||||
int paramId = -1;
|
||||
|
||||
std::function<void()> onEnter;
|
||||
std::function<void(float delta)> onAdjust;
|
||||
std::function<juce::String()> valueText;
|
||||
|
||||
MenuItem& action (std::function<void()> fn) { onEnter = fn; return *this; }
|
||||
MenuItem& param (int id, float lo, float hi) { paramId = id; return *this; }
|
||||
MenuItem& value (std::function<juce::String()> fn) { valueText = fn; kind = Value; return *this; }
|
||||
MenuItem& submenu() { kind = Submenu; return *this; }
|
||||
MenuItem& sep() { kind = Separator; return *this; }
|
||||
};
|
||||
|
||||
struct MenuScreen
|
||||
{
|
||||
juce::String title;
|
||||
std::vector<MenuItem> items;
|
||||
int selected = 0;
|
||||
};
|
||||
|
||||
class MenuSystem
|
||||
{
|
||||
public:
|
||||
MenuSystem();
|
||||
|
||||
void open();
|
||||
void close();
|
||||
bool isOpen() const { return ! stack.empty(); }
|
||||
|
||||
void up();
|
||||
void down();
|
||||
void left();
|
||||
void right();
|
||||
void enter();
|
||||
void escape();
|
||||
|
||||
const MenuScreen& current() const;
|
||||
|
||||
void pushScreen (const MenuScreen& screen);
|
||||
|
||||
using ScreenBuilder = std::function<MenuScreen()>;
|
||||
|
||||
void setRootScreenBuilder (ScreenBuilder fn);
|
||||
|
||||
void refreshCurrent();
|
||||
|
||||
private:
|
||||
std::vector<MenuScreen> stack;
|
||||
ScreenBuilder rootBuilder;
|
||||
bool wasOpen = false;
|
||||
|
||||
void rebuildRoot();
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue