Skip to content

Commit

Permalink
Refactoring; show applet names in Preset picker
Browse files Browse the repository at this point in the history
  • Loading branch information
djphazer committed Jan 19, 2024
1 parent b81a6bc commit 57a63cd
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 50 deletions.
77 changes: 45 additions & 32 deletions software/src/APP_HEMISPHERE.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,26 @@ ClockManager *ClockManager::instance = 0;

#include "hemisphere_config.h"
namespace HS {
Applet available_applets[] = HEMISPHERE_APPLETS;
Applet clock_setup_applet = DECLARE_APPLET(9999, 0x01, ClockSetup);
const Applet available_applets[] = HEMISPHERE_APPLETS;
const Applet clock_setup_applet = DECLARE_APPLET(9999, 0x01, ClockSetup);
static constexpr int HEMISPHERE_AVAILABLE_APPLETS = ARRAY_SIZE(HS::available_applets);

int get_applet_index_by_id(int id) {
int index = 0;
for (int i = 0; i < HEMISPHERE_AVAILABLE_APPLETS; i++)
{
if (available_applets[i].id == id) index = i;
}
return index;
}

int get_next_applet_index(int index, int dir) {
index += dir;
if (index >= HEMISPHERE_AVAILABLE_APPLETS) index = 0;
if (index < 0) index = HEMISPHERE_AVAILABLE_APPLETS - 1;

return index;
}
}

// The settings specify the selected applets, and 64 bits of data for each applet,
Expand All @@ -65,8 +83,7 @@ enum HEMISPHERE_SETTINGS {
HEMISPHERE_SETTING_LAST
};

static constexpr int HEMISPHERE_AVAILABLE_APPLETS = ARRAY_SIZE(HS::available_applets);
static const int HEM_NR_OF_PRESETS = 8;
static constexpr int HEM_NR_OF_PRESETS = 8;

static const char * hem_preset_name[HEM_NR_OF_PRESETS] = { "A", "B", "C", "D", "E", "F", "G", "H" };

Expand All @@ -80,6 +97,10 @@ class HemispherePreset : public SystemExclusiveHandler,
return (h == LEFT_HEMISPHERE) ? values_[HEMISPHERE_SELECTED_LEFT_ID]
: values_[HEMISPHERE_SELECTED_RIGHT_ID];
}
HemisphereApplet* GetApplet(int h) {
int idx = HS::get_applet_index_by_id( GetAppletId(h) );
return HS::available_applets[idx].instance[h];
}
void SetAppletId(int h, int id) {
apply_value(h, id);
}
Expand Down Expand Up @@ -196,8 +217,8 @@ class HemisphereManager : public HSApplication {
quantizer[i].Configure(OC::Scales::GetScale(quant_scale[i]), 0xffff);
}

SetApplet(0, get_applet_index_by_id(18)); // DualTM
SetApplet(1, get_applet_index_by_id(15)); // EuclidX
SetApplet(0, HS::get_applet_index_by_id(18)); // DualTM
SetApplet(1, HS::get_applet_index_by_id(15)); // EuclidX
}

void Resume() {
Expand Down Expand Up @@ -256,7 +277,7 @@ class HemisphereManager : public HSApplication {

for (int h = 0; h < 2; h++)
{
int index = get_applet_index_by_id( hem_active_preset->GetAppletId(h) );
int index = HS::get_applet_index_by_id( hem_active_preset->GetAppletId(h) );
applet_data[h] = hem_active_preset->GetData(h);
SetApplet(h, index);
HS::available_applets[index].instance[h]->OnDataReceive(applet_data[h]);
Expand All @@ -273,7 +294,7 @@ class HemisphereManager : public HSApplication {
}

void ChangeApplet(int h, int dir) {
int index = get_next_applet_index(my_applet[h], dir);
int index = HS::get_next_applet_index(my_applet[h], dir);
SetApplet(select_mode, index);
}

Expand Down Expand Up @@ -652,7 +673,7 @@ class HemisphereManager : public HSApplication {
}

// --- Config Selection
gfxHeader("Hemisphere Config");
gfxHeader("Config");
gfxPrint(1, 15, "Preset: ");
gfxPrint(48, 15, "Load");
gfxIcon(100, 15, HS::auto_save_enabled ? CHECK_ON_ICON : CHECK_OFF_ICON );
Expand Down Expand Up @@ -700,41 +721,33 @@ class HemisphereManager : public HSApplication {
}

void DrawPresetSelector() {
gfxHeader("Hemisphere Presets");
gfxHeader((config_cursor == SAVE_PRESET) ? "Save" : "Load");
gfxPrint(30, 1, "Preset");
gfxDottedLine(16, 11, 16, 63);

int y = 5 + constrain(preset_cursor,1,5)*10;
gfxPrint(1, y, (config_cursor == SAVE_PRESET) ? "Save" : "Load");
gfxIcon(26, y, RIGHT_ICON);
gfxIcon(0, y, RIGHT_ICON);
const int top = constrain(preset_cursor - 4, 1, HEM_NR_OF_PRESETS) - 1;
y = 15;
for (int i = top; i < HEM_NR_OF_PRESETS && i < top + 5; ++i)
{
gfxPrint(35, y, hem_preset_name[i]);
if (i == preset_id)
gfxIcon(8, y, ZAP_ICON);
else
gfxPrint(8, y, hem_preset_name[i]);

if (!hem_presets[i].is_valid())
gfxPrint(" (empty)");
else if (i == preset_id)
gfxIcon(45, y, ZAP_ICON);
gfxPrint(18, y, "(empty)");
else {
gfxPrint(18, y, hem_presets[i].GetApplet(0)->applet_name());
gfxPrint(", ");
gfxPrint(hem_presets[i].GetApplet(1)->applet_name());
}

y += 10;
}
}

int get_applet_index_by_id(int id) {
int index = 0;
for (int i = 0; i < HEMISPHERE_AVAILABLE_APPLETS; i++)
{
if (HS::available_applets[i].id == id) index = i;
}
return index;
}

int get_next_applet_index(int index, int dir) {
index += dir;
if (index >= HEMISPHERE_AVAILABLE_APPLETS) index = 0;
if (index < 0) index = HEMISPHERE_AVAILABLE_APPLETS - 1;

return index;
}
};

// TOTAL EEPROM SIZE: 4 * 26 bytes
Expand Down
4 changes: 2 additions & 2 deletions software/src/HSApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ class HSApplication {
if (CursorBlink()) gfxLine(x, y, x + w - 1, y);
}
void gfxHeader(const char *str) {
gfxPrint(1, 2, str);
gfxPrint(1, 1, str);
gfxLine(0, 10, 127, 10);
gfxLine(0, 12, 127, 12);
gfxLine(0, 11, 127, 11);
}

protected:
Expand Down
26 changes: 10 additions & 16 deletions software/src/HemisphereApplet.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
#include "HSicons.h"
#include "HSClockManager.h"

#define LEFT_HEMISPHERE 0
#define RIGHT_HEMISPHERE 1
#ifdef BUCHLA_4U
#define PULSE_VOLTAGE 8
#define HEMISPHERE_MAX_CV 15360
Expand All @@ -66,6 +64,11 @@
#define HEMISPHERE_ADC_LAG 33
#define HEMISPHERE_CHANGE_THRESHOLD 32

enum HEM_SIDE {
LEFT_HEMISPHERE = 0,
RIGHT_HEMISPHERE = 1,
};

// Codes for help system sections
enum HEM_HELP_SECTIONS {
HEMISPHERE_HELP_DIGITALS = 0,
Expand All @@ -82,10 +85,10 @@ static const char * HEM_HELP_SECTION_NAMES[4] = {"Dig", "CV", "Out", "Enc"};
#define gfx_offset (hemisphere * 64) // Graphics offset, based on the side
#define io_offset (hemisphere * 2) // Input/Output offset, based on the side

#define HEMISPHERE_SIM_CLICK_TIME 1000
#define HEMISPHERE_DOUBLE_CLICK_TIME 8000
#define HEMISPHERE_PULSE_ANIMATION_TIME 500
#define HEMISPHERE_PULSE_ANIMATION_TIME_LONG 1200
static constexpr uint32_t HEMISPHERE_SIM_CLICK_TIME = 1000;
static constexpr uint32_t HEMISPHERE_DOUBLE_CLICK_TIME = 8000;
static constexpr uint32_t HEMISPHERE_PULSE_ANIMATION_TIME = 500;
static constexpr uint32_t HEMISPHERE_PULSE_ANIMATION_TIME_LONG = 1200;

#include "OC_scales.h"
#include "HSUtils.h"
Expand All @@ -99,16 +102,6 @@ typedef struct Applet {
int id;
uint8_t categories;
HemisphereApplet* instance[2];
/*
void (*Start)(bool); // Initialize when selected
void (*Controller)(bool, bool); // Interrupt Service Routine
void (*View)(bool); // Draw main view
void (*OnButtonPress)(bool); // Encoder button has been pressed
void (*OnEncoderMove)(bool, int); // Encoder has been rotated
void (*ToggleHelpScreen)(bool); // Help Screen has been requested
uint64_t (*OnDataRequest)(bool); // Get a data int from the applet
void (*OnDataReceive)(bool, uint64_t); // Send a data int to the applet
*/
} Applet;

// editable by cursor, and CV assignable
Expand All @@ -129,6 +122,7 @@ class HemisphereApplet {
static int cursor[2];

virtual const char* applet_name() = 0; // Maximum of 9 characters

virtual void Start() = 0;
virtual void Controller() = 0;
virtual void View() = 0;
Expand Down

0 comments on commit 57a63cd

Please sign in to comment.