Skip to content

Commit

Permalink
keira: liltracker: implement reset button, set default waveforms to n…
Browse files Browse the repository at this point in the history
…on-silent
  • Loading branch information
and3rson committed Apr 12, 2024
1 parent 4a60aed commit ba7d7c0
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 13 deletions.
53 changes: 41 additions & 12 deletions firmware/keira/src/apps/liltracker/liltracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,16 @@ void LilTrackerApp::run() {

char str[64];

// // Testing serialization/deserialization
// uint8_t* buff = new uint8_t[track.calculateWriteBufferSize()];
// track.writeToBuffer(buff);
// File file = SD.open("/lilka_walks.lt", FILE_WRITE);
// file.write(buff, track.calculateWriteBufferSize());
// file.close();
// track.reset();
// track.readFromBuffer(buff);
// delete[] buff;

while (1) {
seq_state_t seqState = sequencer.getSeqState();

Expand Down Expand Up @@ -400,13 +410,12 @@ void LilTrackerApp::run() {
bool isFocused = activeBlock == ACTIVE_BLOCK_CONTROLS && controlCursorX == i && controlCursorY == 1;
const char* buttonText;
if (i == 0) {
buttonText = "Відкрити";
buttonText = "Load";
} else if (i == 1) {
buttonText = "Записати";
buttonText = "Save";
} else {
buttonText = "Скинути";
buttonText = "Reset";
}
canvas->setFont(FONT_8x13);
printText(
buttonText,
CONTROL_PADDING_LEFT + CONTROL_WIDTH * i,
Expand Down Expand Up @@ -593,13 +602,7 @@ void LilTrackerApp::run() {
}
}
} else if (controlCursorY == 1) {
if (controlCursorX == 0) {
// Load
} else if (controlCursorX == 1) {
// Save
} else if (controlCursorX == 2) {
// Reset
}
// Unreachable
} else if (controlCursorY == 2) {
// Select waveform for pattern's channel
Pattern* pattern = track.getPattern(page->patternIndices[controlCursorX]);
Expand Down Expand Up @@ -627,7 +630,22 @@ void LilTrackerApp::run() {
} else {
if (state.a.justPressed) {
// Enter edit mode
isEditing = true;

if (controlCursorY == 1) {
if (controlCursorX == 0) {
// Load
} else if (controlCursorX == 1) {
// Save
} else if (controlCursorX == 2) {
// Reset
if (confirm("Увага", "Очистити всі дані композиції?")) {
pageIndex = 0;
track.reset();
}
}
} else {
isEditing = true;
}
}
if (state.up.justPressed) {
// We add 1 to CONTROL_ROWS to account for the score header row which is not part of the control, but is managed by the same cursor
Expand Down Expand Up @@ -835,3 +853,14 @@ void LilTrackerApp::startPreview(
}
}
}

bool LilTrackerApp::confirm(String title, String message) {
lilka::Alert alert(title, message + "\n\n[START] - Так\n[A] - Ні");
alert.addActivationButton(lilka::Button::START);
alert.draw(canvas);
queueDraw();
while (!alert.isFinished()) {
alert.update();
}
return alert.getButton() == lilka::Button::START;
}
1 change: 1 addition & 0 deletions firmware/keira/src/apps/liltracker/liltracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ class LilTrackerApp : public App {
bool focused, bool dimmed
);
void startPreview(Track* track, page_t* page, int32_t requestedChannelIndex, int32_t requestedEventIndex);
bool confirm(String title, String message);
};
8 changes: 7 additions & 1 deletion firmware/keira/src/apps/liltracker/pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@
offset += sizeof(value);

Pattern::Pattern() : xMutex(xSemaphoreCreateMutex()) {
const waveform_t defaultWaveforms[CHANNEL_COUNT] = {
WAVEFORM_SQUARE,
WAVEFORM_SAWTOOTH,
WAVEFORM_NOISE,
};
for (int32_t channelIndex = 0; channelIndex < CHANNEL_COUNT; channelIndex++) {
channels[channelIndex].waveform = WAVEFORM_SILENCE;
// Set some default waveforms for nicer expeience when starting from scratch
channels[channelIndex].waveform = defaultWaveforms[channelIndex];
channels[channelIndex].volume = 1.0f;
channels[channelIndex].pitch = 1.0f;
for (int32_t eventIndex = 0; eventIndex < CHANNEL_SIZE; eventIndex++) {
Expand Down

0 comments on commit ba7d7c0

Please sign in to comment.