mirror of
https://github.com/jhbruhn/eurorack.git
synced 2025-03-15 02:55:49 +00:00
Implement setting storage, location of data values has to change though...
This commit is contained in:
parent
8f4cb4f4f3
commit
abf9769e18
9 changed files with 170 additions and 8 deletions
|
@ -109,6 +109,20 @@ class UInt32MenuItem : public NumberMenuItem<uint32_t> {
|
||||||
UInt32MenuItem() {};
|
UInt32MenuItem() {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class UInt8MenuItem : public NumberMenuItem<uint8_t> {
|
||||||
|
private:
|
||||||
|
protected:
|
||||||
|
const char* get_format_string()
|
||||||
|
{
|
||||||
|
return "%u";
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
UInt8MenuItem(const char* _label, uint8_t* _value, uint8_t _minimumValue, uint8_t _maximumValue, uint8_t _step)
|
||||||
|
: NumberMenuItem(_label, _value, _minimumValue, _maximumValue, _step) {};
|
||||||
|
UInt8MenuItem() {};
|
||||||
|
};
|
||||||
|
|
||||||
class Int32MenuItem : public NumberMenuItem<int32_t> {
|
class Int32MenuItem : public NumberMenuItem<int32_t> {
|
||||||
private:
|
private:
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include "menu/menu.h"
|
#include "menu/menu.h"
|
||||||
#include "menu/menu_items.h"
|
#include "menu/menu_items.h"
|
||||||
#include "part.h"
|
#include "part.h"
|
||||||
|
#include "settings.h"
|
||||||
#include "stmlib/system/system_clock.h"
|
#include "stmlib/system/system_clock.h"
|
||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
|
|
||||||
|
@ -16,6 +17,8 @@ GPIO gpio;
|
||||||
Display display;
|
Display display;
|
||||||
Encoder encoder;
|
Encoder encoder;
|
||||||
|
|
||||||
|
Settings settings;
|
||||||
|
|
||||||
Part parts[PART_COUNT];
|
Part parts[PART_COUNT];
|
||||||
Part* part_pointers[PART_COUNT] = { &parts[0], &parts[1], &parts[2], &parts[3] };
|
Part* part_pointers[PART_COUNT] = { &parts[0], &parts[1], &parts[2], &parts[3] };
|
||||||
UI ui(part_pointers);
|
UI ui(part_pointers);
|
||||||
|
|
|
@ -40,14 +40,14 @@ typedef enum : uint32_t {
|
||||||
GATE_TRIGGER = 3
|
GATE_TRIGGER = 3
|
||||||
} GateOutputType_t;
|
} GateOutputType_t;
|
||||||
|
|
||||||
typedef enum : uint32_t {
|
typedef enum : uint8_t {
|
||||||
VOICE_COUNT_1 = 1,
|
VOICE_COUNT_1 = 1,
|
||||||
VOICE_COUNT_2 = 2,
|
VOICE_COUNT_2 = 2,
|
||||||
VOICE_COUNT_3 = 3,
|
VOICE_COUNT_3 = 3,
|
||||||
VOICE_COUNT_4 = 4
|
VOICE_COUNT_4 = 4
|
||||||
} PartVoiceCount_t;
|
} PartVoiceCount_t;
|
||||||
|
|
||||||
typedef enum : uint32_t {
|
typedef enum : uint8_t {
|
||||||
VOICE_DETAIL_S = 0,
|
VOICE_DETAIL_S = 0,
|
||||||
VOICE_DETAIL_M = 1,
|
VOICE_DETAIL_M = 1,
|
||||||
VOICE_DETAIL_L = 2,
|
VOICE_DETAIL_L = 2,
|
||||||
|
|
31
midi2cv/settings.cc
Normal file
31
midi2cv/settings.cc
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
#include "settings.h"
|
||||||
|
#include "midi2cv/part.h"
|
||||||
|
|
||||||
|
Settings::Settings()
|
||||||
|
{
|
||||||
|
persistent_data_.honor = 1;
|
||||||
|
|
||||||
|
for (int i = 0; i < PART_COUNT; i++) {
|
||||||
|
PartState* part = &state_.part_states[i];
|
||||||
|
|
||||||
|
part->midi_filter_channel = 1;
|
||||||
|
part->midi_filter_channel_enabled = true;
|
||||||
|
part->midi_filter_lowest_note = 0;
|
||||||
|
part->midi_filter_highest_note = 127;
|
||||||
|
part->midi_filter_input = MIDI_INPUT_OMNI;
|
||||||
|
part->part_voice_count = VOICE_COUNT_1;
|
||||||
|
part->part_voice_detail = VOICE_DETAIL_S;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*bool success =*/chunk_storage_.Init(&persistent_data_, &state_);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Settings::SavePersistentData()
|
||||||
|
{
|
||||||
|
chunk_storage_.SavePersistentData();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Settings::SaveState()
|
||||||
|
{
|
||||||
|
chunk_storage_.SaveState();
|
||||||
|
}
|
83
midi2cv/settings.h
Normal file
83
midi2cv/settings.h
Normal file
|
@ -0,0 +1,83 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
#include "part.h"
|
||||||
|
#include "stmlib/stmlib.h"
|
||||||
|
#include "stmlib/system/storage.h"
|
||||||
|
|
||||||
|
struct PersistentData {
|
||||||
|
uint8_t honor;
|
||||||
|
uint8_t padding[15];
|
||||||
|
enum { tag = 0x494C4143 }; // CALI
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PartState { // 8 bytes, TODO: can these be pointers to the actual values, or can we do some other copying magic?
|
||||||
|
PartVoiceCount_t part_voice_count;
|
||||||
|
PartVoiceDetail_t part_voice_detail;
|
||||||
|
uint8_t midi_filter_channel_enabled;
|
||||||
|
uint8_t midi_filter_channel;
|
||||||
|
uint8_t midi_filter_lowest_note;
|
||||||
|
uint8_t midi_filter_highest_note;
|
||||||
|
MIDIInput_t midi_filter_input;
|
||||||
|
MIDIThruMode_t midi_thru_mode;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct State {
|
||||||
|
PartState part_states[PART_COUNT]; // 4 * 8 bytes
|
||||||
|
//uint8_t padding[4];
|
||||||
|
enum { tag = 0x54415453 }; // STAT
|
||||||
|
};
|
||||||
|
|
||||||
|
class Settings {
|
||||||
|
public:
|
||||||
|
Settings();
|
||||||
|
~Settings() {}
|
||||||
|
|
||||||
|
void SavePersistentData();
|
||||||
|
void SaveState();
|
||||||
|
|
||||||
|
/*inline const ChannelCalibrationData& calibration_data(int channel) const
|
||||||
|
{
|
||||||
|
return persistent_data_.channel_calibration_data[channel];
|
||||||
|
}
|
||||||
|
|
||||||
|
inline ChannelCalibrationData* mutable_calibration_data(int channel)
|
||||||
|
{
|
||||||
|
return &persistent_data_.channel_calibration_data[channel];
|
||||||
|
}*/
|
||||||
|
|
||||||
|
inline const State& state() const
|
||||||
|
{
|
||||||
|
return state_;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline State* mutable_state()
|
||||||
|
{
|
||||||
|
return &state_;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const PartState& part(int i) const
|
||||||
|
{
|
||||||
|
return state_.part_states[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
inline PartState* mutable_part(int i)
|
||||||
|
{
|
||||||
|
return &state_.part_states[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
PersistentData persistent_data_;
|
||||||
|
State state_;
|
||||||
|
|
||||||
|
stmlib::ChunkStorage<
|
||||||
|
0x08004000,
|
||||||
|
0x08008000,
|
||||||
|
PersistentData,
|
||||||
|
State>
|
||||||
|
chunk_storage_;
|
||||||
|
|
||||||
|
DISALLOW_COPY_AND_ASSIGN(Settings);
|
||||||
|
};
|
||||||
|
|
||||||
|
extern Settings settings;
|
|
@ -1,20 +1,26 @@
|
||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
#include "ui/main_menu.h"
|
|
||||||
#include "drivers/display.h"
|
#include "drivers/display.h"
|
||||||
#include "midi2cv/drivers/encoder.h"
|
#include "midi2cv/drivers/encoder.h"
|
||||||
#include "midi2cv/menu/menu.h"
|
#include "midi2cv/menu/menu.h"
|
||||||
#include "midi2cv/menu/menu_items.h"
|
#include "midi2cv/menu/menu_items.h"
|
||||||
#include "part.h"
|
#include "part.h"
|
||||||
|
#include "settings.h"
|
||||||
#include "stmlib/utils/random.h"
|
#include "stmlib/utils/random.h"
|
||||||
#include <u8g2.h>
|
#include "ui/main_menu.h"
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <u8g2.h>
|
||||||
|
|
||||||
using namespace stmlib;
|
using namespace stmlib;
|
||||||
|
|
||||||
const uint32_t kEncoderLongPressTime = 600;
|
const uint32_t kEncoderLongPressTime = 600;
|
||||||
|
|
||||||
UI::UI(Part** part_pointers) : main_menu(part_pointers)
|
UI::UI(Part** part_pointers)
|
||||||
|
: main_menu(part_pointers)
|
||||||
|
, parts(part_pointers)
|
||||||
{
|
{
|
||||||
this->input_queue.Init();
|
this->input_queue.Init();
|
||||||
|
|
||||||
|
LoadState();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UI::Poll()
|
void UI::Poll()
|
||||||
|
@ -53,6 +59,26 @@ void UI::Draw()
|
||||||
display.Swap();
|
display.Swap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UI::LoadState()
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < PART_COUNT; i++) {
|
||||||
|
parts[i]->midi_filter_channel = settings.part(i).midi_filter_channel;
|
||||||
|
parts[i]->midi_filter_channel_enabled = settings.part(i).midi_filter_channel_enabled;
|
||||||
|
parts[i]->midi_filter_lowest_note = settings.part(i).midi_filter_lowest_note;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UI::SaveState()
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < PART_COUNT; i++) {
|
||||||
|
settings.mutable_part(i)->midi_filter_channel = this->parts[i]->midi_filter_channel;
|
||||||
|
settings.mutable_part(i)->midi_filter_channel_enabled = this->parts[i]->midi_filter_channel_enabled;
|
||||||
|
settings.mutable_part(i)->midi_filter_lowest_note = this->parts[i]->midi_filter_lowest_note;
|
||||||
|
}
|
||||||
|
|
||||||
|
settings.SaveState();
|
||||||
|
}
|
||||||
|
|
||||||
void UI::Flush()
|
void UI::Flush()
|
||||||
{
|
{
|
||||||
display.Flush();
|
display.Flush();
|
||||||
|
@ -99,4 +125,6 @@ void UI::OnIncrement(Event& e)
|
||||||
main_menu.down();
|
main_menu.down();
|
||||||
else
|
else
|
||||||
main_menu.up();
|
main_menu.up();
|
||||||
|
|
||||||
|
SaveState();
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,10 @@ class UI {
|
||||||
uint32_t encoder_press_time_;
|
uint32_t encoder_press_time_;
|
||||||
|
|
||||||
MainMenu<PART_COUNT> main_menu;
|
MainMenu<PART_COUNT> main_menu;
|
||||||
|
Part** parts;
|
||||||
|
|
||||||
|
void LoadState();
|
||||||
|
void SaveState();
|
||||||
|
|
||||||
void Draw();
|
void Draw();
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ static const char* kMidiThruStrings[] = { "off", "on", "polychain" };
|
||||||
|
|
||||||
PartMenu::PartMenu(Part* _part)
|
PartMenu::PartMenu(Part* _part)
|
||||||
: part(_part)
|
: part(_part)
|
||||||
, item_voice_count("voice count", (uint32_t*)&_part->part_voice_count, 1, 4, 1)
|
, item_voice_count("voice count", (uint8_t*)&_part->part_voice_count, 1, 4, 1)
|
||||||
, item_voice_detail("voice detail", (uint8_t*)&_part->part_voice_detail, kVoiceDetailStrings, 4)
|
, item_voice_detail("voice detail", (uint8_t*)&_part->part_voice_detail, kVoiceDetailStrings, 4)
|
||||||
, item_midi_filter_enabled("MIDI filter", &_part->midi_filter_channel_enabled, "on", "off")
|
, item_midi_filter_enabled("MIDI filter", &_part->midi_filter_channel_enabled, "on", "off")
|
||||||
, item_midi_channel("MIDI channel", (uint8_t*)&_part->midi_filter_channel, kMidiChannelStrings, 17)
|
, item_midi_channel("MIDI channel", (uint8_t*)&_part->midi_filter_channel, kMidiChannelStrings, 17)
|
||||||
|
@ -51,7 +51,6 @@ bool PartMenu::back()
|
||||||
bool PartMenu::enter()
|
bool PartMenu::enter()
|
||||||
{
|
{
|
||||||
menu.enter();
|
menu.enter();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ class PartMenu {
|
||||||
Part* part;
|
Part* part;
|
||||||
|
|
||||||
Menu menu;
|
Menu menu;
|
||||||
UInt32MenuItem item_voice_count;
|
UInt8MenuItem item_voice_count;
|
||||||
StringListMenuItem item_voice_detail;
|
StringListMenuItem item_voice_detail;
|
||||||
BoolMenuItem item_midi_filter_enabled;
|
BoolMenuItem item_midi_filter_enabled;
|
||||||
StringListMenuItem item_midi_channel;
|
StringListMenuItem item_midi_channel;
|
||||||
|
|
Loading…
Reference in a new issue