Skip to content

Commit

Permalink
Replace applet declaration macros with template
Browse files Browse the repository at this point in the history
  • Loading branch information
qiemem committed Aug 8, 2024
1 parent 52a6986 commit 2fc3816
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 217 deletions.
3 changes: 3 additions & 0 deletions software/res/progname.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@
extras += "_flipped"

env.Replace(PROGNAME=f"o_C-phazerville-{version}{extras}-{git_rev}")

# include toolchain paths in compiledb for clangd lsp
env.Replace(COMPILATIONDB_INCLUDE_TOOLCHAIN=True)
50 changes: 28 additions & 22 deletions software/src/APP_HEMISPHERE.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ class HemispherePreset : public SystemExclusiveHandler,
return (h == LEFT_HEMISPHERE) ? values_[HEMISPHERE_SELECTED_LEFT_ID]
: values_[HEMISPHERE_SELECTED_RIGHT_ID];
}
HemisphereApplet* GetApplet(int h) {
HemisphereApplet& GetApplet(int h) {
int idx = HS::get_applet_index_by_id( GetAppletId(h) );
return HS::available_applets[idx].instance[h];
return HS::available_applets[idx]->GetInstance(h);
}
void SetAppletId(int h, int id) {
apply_value(h, id);
Expand Down Expand Up @@ -267,11 +267,11 @@ class HemisphereManager : public HSApplication {
for (int h = 0; h < 2; h++)
{
int index = my_applet[h];
if (hem_active_preset->GetAppletId(HEM_SIDE(h)) != HS::available_applets[index].id)
if (hem_active_preset->GetAppletId(HEM_SIDE(h)) != HS::available_applets[index]->id)
doSave = 1;
hem_active_preset->SetAppletId(HEM_SIDE(h), HS::available_applets[index].id);
hem_active_preset->SetAppletId(HEM_SIDE(h), HS::available_applets[index]->id);

uint64_t data = HS::available_applets[index].instance[h]->OnDataRequest();
uint64_t data = HS::available_applets[index]->GetInstance(h).OnDataRequest();
if (data != applet_data[h]) doSave = 1;
applet_data[h] = data;
hem_active_preset->SetData(HEM_SIDE(h), data);
Expand Down Expand Up @@ -319,7 +319,7 @@ class HemisphereManager : public HSApplication {
int index = HS::get_applet_index_by_id( hem_active_preset->GetAppletId(h) );
applet_data[h] = hem_active_preset->GetData(HEM_SIDE(h));
SetApplet(HEM_SIDE(h), index);
HS::available_applets[index].instance[h]->OnDataReceive(applet_data[h]);
HS::available_applets[index]->GetInstance(h).OnDataReceive(applet_data[h]);
}


Expand All @@ -331,13 +331,19 @@ class HemisphereManager : public HSApplication {
LoadFromPreset(queued_preset);
}

HemisphereApplet& GetApplet(HEM_SIDE hemisphere) {
return HS::available_applets[my_applet[hemisphere]]->GetInstance(hemisphere);
}
// does not modify the preset, only the manager
void SetApplet(HEM_SIDE hemisphere, int index) {
//if (my_applet[hemisphere]) // TODO: special case for first load?
HS::available_applets[my_applet[hemisphere]].instance[hemisphere]->Unload();
GetApplet(hemisphere).Unload();
next_applet[hemisphere] = my_applet[hemisphere] = index;
HS::available_applets[index].instance[hemisphere]->BaseStart(hemisphere);
HemisphereApplet& selected_applet = HS::available_applets[index]->GetInstance(hemisphere);
selected_applet.BaseStart(hemisphere);

}

void ChangeApplet(HEM_SIDE h, int dir) {
int index = HS::get_next_applet_index(next_applet[h], dir);
next_applet[h] = index;
Expand Down Expand Up @@ -423,7 +429,7 @@ class HemisphereManager : public HSApplication {
int index = my_applet[h];

// MIDI signals mixed with inputs to applets
if (HS::available_applets[index].id != 150) // not MIDI In
if (HS::available_applets[index]->id != 150) // not MIDI In
{
ForEachChannel(ch) {
int chan = h*2 + ch;
Expand All @@ -448,7 +454,7 @@ class HemisphereManager : public HSApplication {
}
}
}
HS::available_applets[index].instance[h]->BaseController();
HS::available_applets[index]->GetInstance(h).BaseController();
}

#ifdef ARDUINO_TEENSY41
Expand Down Expand Up @@ -514,15 +520,15 @@ class HemisphereManager : public HSApplication {
}

if (draw_applets) {
// either zoomed or split view

if (help_hemisphere > -1) {
int index = my_applet[help_hemisphere];
HS::available_applets[index].instance[help_hemisphere]->BaseView(true);
draw_applets = false;
GetApplet(static_cast<HEM_SIDE>(help_hemisphere)).BaseView(true);
} else {
for (int h = 0; h < 2; h++)
{
int index = my_applet[h];
HS::available_applets[index].instance[h]->BaseView();
HS::available_applets[index]->GetInstance(h).BaseView();
}

if (select_mode == LEFT_HEMISPHERE) graphics.drawFrame(0, 0, 64, 64);
Expand Down Expand Up @@ -576,7 +582,7 @@ class HemisphereManager : public HSApplication {
} else if (!clock_setup) {
// regular applets get button release
int index = my_applet[h];
HS::available_applets[index].instance[h]->OnButtonPress();
HS::available_applets[index]->GetInstance(h).OnButtonPress();
}
}

Expand Down Expand Up @@ -678,11 +684,11 @@ class HemisphereManager : public HSApplication {
// -- button release
if (!clock_setup) {
const int index = my_applet[hemisphere];
HemisphereApplet* applet = HS::available_applets[index].instance[hemisphere];
HemisphereApplet& applet = HS::available_applets[index]->GetInstance(hemisphere);

if (applet->EditMode()) {
if (applet.EditMode()) {
// select button becomes aux button while editing a param
applet->AuxButton();
applet.AuxButton();
} else {
// Select Mode
if (hemisphere == select_mode) select_mode = -1; // Exit Select Mode if same button is pressed
Expand Down Expand Up @@ -724,7 +730,7 @@ class HemisphereManager : public HSApplication {
ChangeApplet(HEM_SIDE(h), event.value);
} else {
int index = my_applet[h];
HS::available_applets[index].instance[h]->OnEncoderMove(event.value);
HS::available_applets[index]->GetInstance(h).OnEncoderMove(event.value);
}
}

Expand Down Expand Up @@ -1087,7 +1093,7 @@ class HemisphereManager : public HSApplication {
++current, y += LineH) {

gfxIcon(1, y + 1, HS::applet_is_hidden(current) ? CHECK_OFF_ICON : CHECK_ON_ICON);
gfxPrint( 11, y + 2, HS::available_applets[current].instance[0]->applet_name());
gfxPrint( 11, y + 2, HS::available_applets[current]->GetInstance(0).applet_name());

if (current == showhide_cursor.cursor_pos())
gfxInvert(0, y, 127, LineH - 1);
Expand Down Expand Up @@ -1163,9 +1169,9 @@ class HemisphereManager : public HSApplication {
if (!hem_presets[i].is_valid())
gfxPrint(18, y, "(empty)");
else {
gfxPrint(18, y, hem_presets[i].GetApplet(0)->applet_name());
gfxPrint(18, y, hem_presets[i].GetApplet(0).applet_name());
gfxPrint(", ");
gfxPrint(hem_presets[i].GetApplet(1)->applet_name());
gfxPrint(hem_presets[i].GetApplet(1).applet_name());
}

y += 10;
Expand Down
20 changes: 10 additions & 10 deletions software/src/APP_QUADRANTS.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ class QuadrantsPreset : public SystemExclusiveHandler,
int GetAppletId(HEM_SIDE h) {
return values_[QUADRANTS_SELECTED_LEFT_ID + h];
}
HemisphereApplet* GetApplet(HEM_SIDE h) {
HemisphereApplet& GetApplet(HEM_SIDE h) {
int idx = HS::get_applet_index_by_id( GetAppletId(h) );
return HS::available_applets[idx].instance[h];
return HS::available_applets[idx]->GetInstance(h);
}
void SetAppletId(HEM_SIDE h, int id) {
apply_value(h, id);
Expand Down Expand Up @@ -273,11 +273,11 @@ class QuadAppletManager : public HSApplication {
for (int h = 0; h < APPLET_SLOTS; h++)
{
int index = active_applet_index[h];
if (quad_active_preset->GetAppletId(HEM_SIDE(h)) != HS::available_applets[index].id)
if (quad_active_preset->GetAppletId(HEM_SIDE(h)) != HS::available_applets[index]->id)
doSave = 1;
quad_active_preset->SetAppletId(HEM_SIDE(h), HS::available_applets[index].id);
quad_active_preset->SetAppletId(HEM_SIDE(h), HS::available_applets[index]->id);

uint64_t data = HS::available_applets[index].instance[h]->OnDataRequest();
uint64_t data = HS::available_applets[index]->GetInstance(h).OnDataRequest();
if (data != applet_data[h]) doSave = 1;
applet_data[h] = data;
quad_active_preset->SetData(HEM_SIDE(h), data);
Expand Down Expand Up @@ -328,7 +328,7 @@ class QuadAppletManager : public HSApplication {
int index = HS::get_applet_index_by_id( quad_active_preset->GetAppletId(HEM_SIDE(h)) );
applet_data[h] = quad_active_preset->GetData(HEM_SIDE(h));
SetApplet(HEM_SIDE(h), index);
HS::available_applets[index].instance[h]->OnDataReceive(applet_data[h]);
HS::available_applets[index]->GetInstance(h).OnDataReceive(applet_data[h]);
}
}
preset_id = id;
Expand All @@ -352,7 +352,7 @@ class QuadAppletManager : public HSApplication {
active_applet[hemisphere]->Unload();

next_applet_index[hemisphere] = active_applet_index[hemisphere] = index;
active_applet[hemisphere] = HS::available_applets[index].instance[hemisphere];
active_applet[hemisphere] = &HS::available_applets[index]->GetInstance(hemisphere);
active_applet[hemisphere]->BaseStart(hemisphere);
}
void ChangeApplet(HEM_SIDE h, int dir) {
Expand Down Expand Up @@ -404,7 +404,7 @@ class QuadAppletManager : public HSApplication {
}

// MIDI signals mixed with inputs to applets
if (HS::available_applets[ active_applet_index[h] ].id != 150) // not MIDI In
if (HS::available_applets[ active_applet_index[h] ]->id != 150) // not MIDI In
{
ForEachChannel(ch) {
int chan = h*2 + ch;
Expand Down Expand Up @@ -1120,9 +1120,9 @@ class QuadAppletManager : public HSApplication {
if (!quad_presets[i].is_valid())
gfxPrint(18, y, "(empty)");
else {
gfxPrint(18, y, quad_presets[i].GetApplet(LEFT_HEMISPHERE)->applet_name());
gfxPrint(18, y, quad_presets[i].GetApplet(LEFT_HEMISPHERE).applet_name());
gfxPrint(", ");
gfxPrint(quad_presets[i].GetApplet(RIGHT_HEMISPHERE)->applet_name());
gfxPrint(quad_presets[i].GetApplet(RIGHT_HEMISPHERE).applet_name());
}

y += 10;
Expand Down
24 changes: 19 additions & 5 deletions software/src/HemisphereApplet.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
////////////////////////////////////////////////////////////////////////////////

#pragma once
#include <optional>
#ifndef _HEM_APPLET_H_
#define _HEM_APPLET_H_

Expand All @@ -48,11 +49,24 @@ class HemisphereApplet;

namespace HS {

typedef struct Applet {
const int id;
const uint8_t categories;
HemisphereApplet* instance[APPLET_SLOTS];
} Applet;
class BaseApplet {
public:
BaseApplet(const int id, const uint8_t categories) : id(id), categories(categories) {}
const int id;
const uint8_t categories;
virtual HemisphereApplet & GetInstance(int slot) = 0;
};

template<class A, int Id, uint8_t Categories>
class StaticApplet : public BaseApplet {
public:
StaticApplet() : BaseApplet(Id, Categories) {}
A instance[APPLET_SLOTS];

HemisphereApplet & GetInstance(int slot) override {
return instance[slot];
}
};

extern IOFrame frame;

Expand Down
Loading

0 comments on commit 2fc3816

Please sign in to comment.