Skip to content

Commit

Permalink
play
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre Piel committed Jan 13, 2024
1 parent 95b9a1b commit 8e7a571
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 27 deletions.
3 changes: 2 additions & 1 deletion plugins/components/GridSequencerComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,13 @@ class GridSequencerComponent : public Component {
std::vector<ComponentInterface*> components = getViewComponents();
for (ComponentInterface* component : components) {
if (component->id.find(paramId) == 0) {
paramKeyPressed = param;
// id end by _toggle
if (component->id.find("_button") != -1) {
// printf("toggle %s\n", component->id.c_str());
component->data(1);
} else if (component->id.find("_enc") != -1) {
// printf("enc %s\n", component->id.c_str());
paramKeyPressed = param;
componentParam = component;
}
}
Expand Down Expand Up @@ -494,6 +494,7 @@ class GridSequencerComponent : public Component {
}
} else {
if (paramKeyPressed != -1 && keys.params[paramKeyPressed] == key) {
onParamKeyReleased(paramKeyPressed);
paramKeyPressed = -1;
return;
}
Expand Down
Binary file added plugins/components/Play.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 35 additions & 24 deletions plugins/components/PlayComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
/*md
## Play
<img src="https://raw.githubusercontent.com/apiel/zicBox/main/plugins/components/Play.png" />
Play component toggle play and stop.
*/
class PlayComponent : public Component {
protected:
bool playing = false;
bool stopped = true;

Size iconSize = { 20, 20 };
Point iconPosition;
Expand Down Expand Up @@ -53,21 +56,29 @@ class PlayComponent : public Component {
{ size.w - 2 * margin, size.h - 2 * margin },
colors.background);

if (playing) {
// Draw triangle
if (stopped) {
// Stopped
draw.filledRect(iconPosition, iconSize, colors.icon);
draw.rect(iconPosition, iconSize, colors.border);
draw.rect({ iconPosition.x + 1, iconPosition.y + 1 }, { iconSize.w - 2, iconSize.h - 2 }, colors.border);
draw.textCentered(labelPosition, "Stopped", colors.title, 12);
} else if (playing) {
// Playing
std::vector<Point> points = {
{ iconPosition.x, iconPosition.y + iconSize.h },
{ iconPosition.x + iconSize.w, iconPosition.y },
{ iconPosition.x + iconSize.w, iconPosition.y + iconSize.h }
iconPosition,
{ iconPosition.x + iconSize.w, (int)(iconPosition.y + iconSize.h * 0.5) },
{ iconPosition.x, iconPosition.y + iconSize.h }
};
draw.filledPolygon(points, colors.icon);
draw.polygon(points, colors.border);
draw.textCentered(labelPosition, "Playing", colors.title, 12);
} else {
draw.filledRect(iconPosition, iconSize, colors.icon);
draw.rect(iconPosition, iconSize, colors.border);
draw.rect({ iconPosition.x + 1, iconPosition.y + 1 }, { iconSize.w - 2, iconSize.h - 2 }, colors.border);
draw.textCentered(labelPosition, "Stopped", colors.title, 12);
// Paused
draw.filledRect(iconPosition, { (int)(iconSize.w * 0.3), iconSize.h }, colors.icon);
draw.rect(iconPosition, { (int)(iconSize.w * 0.3), iconSize.h }, colors.border);
draw.filledRect({ iconPosition.x + (int)(iconSize.w * 0.7), iconPosition.y }, { (int)(iconSize.w * 0.3), iconSize.h }, colors.icon);
draw.rect({ iconPosition.x + (int)(iconSize.w * 0.7), iconPosition.y }, { (int)(iconSize.w * 0.3), iconSize.h }, colors.border);
draw.textCentered(labelPosition, "Paused", colors.title, 12);
}
}

Expand Down Expand Up @@ -95,21 +106,21 @@ class PlayComponent : public Component {
return false;
}

// TODO short press toggle play pause
// Long press stop...

// void* data(int id, void* userdata = NULL) override
// {
// if (id == 0) {
// if (value->get() == value->props().min) {
// value->set(value->props().max);
// } else {
// value->set(value->props().min);
// }
// return NULL;
// }
// return NULL;
// }
void* data(int id, void* userdata = NULL) override
{
if (id == 0) {
if (!playing) {
playing = true;
stopped = false;
renderNext();
} else {
playing = false;
renderNext();
}
return NULL;
}
return NULL;
}
};

#endif
Binary file added plugins/components/Toggle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 16 additions & 1 deletion plugins/components/ToggleComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
#include <math.h>
#include <string>

/*md
## Toggle
<img src="https://raw.githubusercontent.com/apiel/zicBox/main/plugins/components/Toggle.png" />
Toggle an audio plugin value parameter between his minimum and maximum value.
*/
class ToggleComponent : public Component {
protected:
const char* label = NULL;
Expand Down Expand Up @@ -104,45 +111,53 @@ class ToggleComponent : public Component {

bool config(char* key, char* value)
{
/*md - `VALUE: pluginName keyName` is used to set the value to control */
if (strcmp(key, "VALUE") == 0) {
char* pluginName = strtok(value, " ");
char* keyValue = strtok(NULL, " ");
set(pluginName, keyValue);
return true;
}

/*md - `ENCODER_ID: 0` is used to set the encoder id that will interract with this component. Rotating left will turn of the toggle, rotating right will turn it on. */
if (strcmp(key, "ENCODER_ID") == 0) {
encoderId = atoi(value);
return true;
}

/*md - `LABEL: custom_label` overwrite the value label */
if (strcmp(key, "LABEL") == 0) {
strcpy(labelBuffer, value);
label = labelBuffer;
return true;
}

/*md - `OFF_LABEL: custom_off_label` overwrite the label when status is off */
if (strcmp(key, "OFF_LABEL") == 0) {
strcpy(offLabelBuffer, value);
offLabel = offLabelBuffer;
return true;
}

/*md - `BACKGROUND_COLOR: #000000` set the background color */
if (strcmp(key, "BACKGROUND_COLOR") == 0) {
colors.background = draw.getColor(value);
return true;
}

/*md - `TEXT_COLOR: #ffffff` set the text color */
if (strcmp(key, "TEXT_COLOR") == 0) {
colors.title = draw.alpha(draw.getColor(value), 0.4);
return true;
}

/*md - `TOGGLE_COLOR: #888888` set the toggle button color */
if (strcmp(key, "TOGGLE_COLOR") == 0) {
colors.toggle = draw.getColor(value);
return true;
}

/*md - `SHOW_GROUP: TRUE` show group if the component is part of the current active group (default FALSE) */
if (strcmp(key, "SHOW_GROUP") == 0) {
showGroup = (strcmp(value, "TRUE") == 0);
return true;
Expand Down Expand Up @@ -171,7 +186,7 @@ class ToggleComponent : public Component {
// printf("current group: %d inccoming group: %d drawId: %d\n", group, index, drawId);
}


/*md **Data**: */
void* data(int id, void* userdata = NULL) override
{
if (id == 1) {
Expand Down
6 changes: 6 additions & 0 deletions ui_480x640/masterParams.view.ui
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
COMPONENT: Play $encX1 $encY1 $encSize $encSize
ICON_COLOR: #9dfe86
ID: Param0_button

# I would rather move the GAIN on another page
COMPONENT: Encoder2 $encX2 $encY1 $encSize $encSize
Expand All @@ -9,6 +10,7 @@
GROUP: 0
COLOR: #3791a1
VALUE: MasterVolume VOLUME
ID: Param1_enc

COMPONENT: Encoder2 $encX3 $encY1 $encSize $encSize
ENCODER_ID: 2
Expand All @@ -17,6 +19,7 @@
GROUP: 0
COLOR: #ff8d99
VALUE: MasterVolume GAIN
ID: Param2_enc

COMPONENT: Encoder2 $encX4 $encY1 $encSize $encSize
ENCODER_ID: 3
Expand All @@ -27,6 +30,7 @@
COLOR: #ff7700
TYPE: TWO_SIDED
# BACKGROUND_COLOR: #2b2c2e
ID: Param3_enc


COMPONENT: Rect $encX1 $encY2 $encSize $encSize
Expand All @@ -44,6 +48,7 @@
VALUE: MultiModeFilter RESONANCE
COLOR: #ff7700
# BACKGROUND_COLOR: #2b2c2e
ID: Param7_enc


COMPONENT: Rect $encX1 $encY3 $encSize $encSize
Expand All @@ -62,3 +67,4 @@
VALUE: SampleRateReducer SAMPLE_STEP
FONT_UNIT_SIZE: 8
# BACKGROUND_COLOR: #2b2c2e
ID: Param11_enc
2 changes: 1 addition & 1 deletion wiki
Submodule wiki updated from d06136 to 4748e9

0 comments on commit 8e7a571

Please sign in to comment.