First complete version of simple UI.

pull/4/head
Holger Wirtz 6 years ago
parent b333216b0f
commit bfac53701b
  1. 9
      MicroDexed.ino
  2. 81
      UI.cpp
  3. 6
      UI.h
  4. 1
      config.h
  5. 13
      dexed.cpp
  6. 21
      dexed_sysex.cpp
  7. 4
      dexed_sysex.h

@ -48,6 +48,7 @@ int32_t enc_val[2] = {INITIAL_ENC_L_VALUE, INITIAL_ENC_R_VALUE};
Bounce but[2] = {Bounce(BUT_L_PIN, BUT_DEBOUNCE_MS), Bounce(BUT_R_PIN, BUT_DEBOUNCE_MS)};
elapsedMillis master_timer;
uint8_t ui_state = UI_MAIN;
uint8_t ui_main_state = UI_MAIN_VOICE_SELECTED;
#endif
// GUItool: begin automatically generated code
@ -183,7 +184,9 @@ void setup()
load_sysex(bank, voice);
#ifdef I2C_DISPLAY
enc[0].write(map(vol * 100, 0, 100, 0, ENC_VOL_STEPS));
enc_val[0] = enc[0].read();
enc[1].write(voice);
enc_val[1] = enc[1].read();
but[0].update();
but[1].update();
#endif
@ -216,8 +219,6 @@ void setup()
sched_note_off.begin(note_off, 6333333);
#endif
Serial.println(F("<setup end>"));
#if defined (DEBUG) && defined (SHOW_CPU_LOAD_MSEC)
show_cpu_and_mem_usage();
#endif
@ -226,6 +227,8 @@ void setup()
ui_show_main();
#endif
Serial.println(F("<setup end>"));
#ifdef TEST_NOTE
//dexed->data[DEXED_VOICE_OFFSET+DEXED_LFO_PITCH_MOD_DEP] = 99; // full pitch mod depth
//dexed->data[DEXED_VOICE_OFFSET+DEXED_LFO_PITCH_MOD_SENS] = 99; // full pitch mod sense
@ -411,7 +414,7 @@ bool handle_master_key(uint8_t data)
Serial.println(bank, DEC);
#endif
#ifdef I2C_DISPLAY
if (get_bank_name(bank))
if (get_bank_voice_name(bank, voice))
{
lcd.show(0, 0, 2, bank + 1);
lcd.show(0, 2, 1, " ");

@ -25,6 +25,8 @@
#include <Arduino.h>
#include "config.h"
#include "dexed.h"
#include "dexed_sysex.h"
#include "UI.h"
#ifdef I2C_DISPLAY // selecting sounds by encoder, button and display
@ -43,6 +45,37 @@ void handle_ui(void)
if (but[i].risingEdge())
{
// Button pressed
switch (i)
{
case 0: // left button pressed
switch (ui_main_state)
{
case UI_MAIN_BANK:
ui_main_state = UI_MAIN_VOICE;
enc[1].write(voice);
enc_val[1] = enc[1].read();
break;
case UI_MAIN_VOICE:
ui_main_state = UI_MAIN_VOICE_SELECTED;
enc[1].write(voice);
enc_val[1] = enc[1].read();
break;
case UI_MAIN_VOICE_SELECTED:
ui_main_state = UI_MAIN_BANK;
enc[1].write(bank);
enc_val[1] = enc[1].read();
break;
}
break;
case 1: // right button pressed
ui_main_state = UI_MAIN_VOICE_SELECTED;
load_sysex(bank, voice);
EEPROM.update(EEPROM_OFFSET + EEPROM_BANK_ADDR, bank);
EEPROM.update(EEPROM_OFFSET + EEPROM_VOICE_ADDR, voice);
update_eeprom_checksum();
break;
}
ui_show_main();
#ifdef DEBUG
Serial.print(F("Button "));
Serial.println(i, DEC);
@ -64,6 +97,33 @@ void handle_ui(void)
ui_show_volume();
break;
case 1: // right encoder moved
switch (ui_main_state)
{
case UI_MAIN_BANK:
if (enc[i].read() <= 0)
enc[i].write(0);
else if (enc[i].read() >= MAX_BANKS)
enc[i].write(MAX_BANKS);
bank = enc[i].read();
if (!get_bank_voice_name(bank, voice))
{
bank--;
enc[i].write(bank);
get_bank_voice_name(bank, voice);
}
break;
case UI_MAIN_VOICE:
if (enc[i].read() <= 0)
enc[i].write(0);
else if (enc[i].read() >= MAX_VOICES)
enc[i].write(MAX_VOICES);
voice = enc[i].read();
break;
case UI_MAIN_VOICE_SELECTED:
ui_main_state = UI_MAIN_VOICE;
break;
}
get_bank_voice_name(bank, voice);
ui_show_main();
break;
}
@ -85,9 +145,30 @@ void ui_show_main(void)
lcd.clear();
lcd.show(0, 0, 2, bank + 1);
lcd.show(0, 2, 1, " ");
if (ui_main_state == UI_MAIN_BANK)
{
lcd.show(0, 2, 1, "[");
lcd.show(0, 3, 10, bank_name);
lcd.show(0, 14, 1, "]");
}
else
lcd.show(0, 3, 10, bank_name);
lcd.show(1, 0, 2, voice + 1);
lcd.show(1, 2, 1, " ");
if (ui_main_state == UI_MAIN_VOICE)
{
lcd.show(1, 2, 1, "<");
lcd.show(1, 3, 10, voice_name);
lcd.show(1, 14, 1, ">");
}
else if (ui_main_state == UI_MAIN_VOICE_SELECTED)
{
lcd.show(1, 2, 1, "[");
lcd.show(1, 3, 10, voice_name);
lcd.show(1, 14, 1, "]");
}
else
lcd.show(1, 3, 10, voice_name);
}

@ -25,6 +25,7 @@
#include "config.h"
#include <Bounce.h>
#include <EEPROM.h>
#include "LiquidCrystalPlus_I2C.h"
#include "Encoder4.h"
@ -43,7 +44,8 @@ extern uint8_t voice;
extern char bank_name[11];
extern char voice_name[11];
extern uint8_t ui_state;
extern uint8_t ui_main_state;
extern void update_eeprom_checksum(void);
extern void set_volume(float v, float vr, float vl);
void handle_ui(void);
@ -51,10 +53,10 @@ void ui_show_main(void);
void ui_show_volume(void);
enum ui_states {UI_MAIN, UI_VOLUME};
enum ui_main_states {UI_MAIN_BANK, UI_MAIN_VOICE, UI_MAIN_VOICE_SELECTED};
class MyEncoder : public Encoder
{
int32_t read()
{
return (Encoder::read() / 4);

@ -48,6 +48,7 @@
#endif
#define SAMPLE_RATE 44100
#define MAX_BANKS 99
#define MAX_VOICES 32 // voices per bank
#if !defined(__MK66FX1M0__) // check for Teensy-3.6
#define MAX_NOTES 11 // No?

@ -679,13 +679,16 @@ bool Dexed::loadSysexVoice(uint8_t* new_data)
doRefreshVoice();
//activate();
strncpy(voice_name, (char *)&data[145], sizeof(voice_name) - 1);
#ifdef DEBUG
char voicename[11];
memset(voicename, 0, sizeof(voicename));
strncpy(voicename, (char *)&data[145], sizeof(voicename) - 1);
strncpy(voice_name, (char *)&data[145], sizeof(voicename) - 1);
//char voicename[11];
//memset(voicename, 0, sizeof(voicename));
//strncpy(voicename, (char *)&data[145], sizeof(voicename) - 1);
Serial.print(F("Voice ["));
Serial.print(voicename);
//Serial.print(voicename);
Serial.print(voice_name);
Serial.println(F("] loaded."));
#endif

@ -30,8 +30,9 @@
#include "dexed.h"
#include "dexed_sysex.h"
#include "config.h"
#include "UI.h"
bool get_bank_name(uint8_t b)
bool get_bank_voice_name(uint8_t b, uint8_t v)
{
File root;
b %= MAX_BANKS;
@ -65,12 +66,19 @@ bool get_bank_name(uint8_t b)
if (!entry.isDirectory())
{
char *token;
uint8_t data[128];
token = strtok(entry.name(), ".");
if (token != NULL)
strcpy(bank_name, token);
if (get_sysex_voice(bankdir, entry, v, data))
strncpy(voice_name, (char*)&data[118], 10);
else
strcpy(voice_name, "*ERROR*");
token = strtok(entry.name(), ".");
if (token == NULL)
strcpy(bank_name, "*ERROR*");
else
strcpy(bank_name, token);
return (true);
}
}
@ -84,7 +92,7 @@ bool load_sysex(uint8_t b, uint8_t v)
File root;
bool found = false;
v %= 32;
v %= MAX_VOICES;
b %= MAX_BANKS;
if (sd_card_available)
@ -121,6 +129,8 @@ bool load_sysex(uint8_t b, uint8_t v)
{
#ifdef DEBUG
char n[11];
bool r;
strncpy(n, (char*)&data[118], 10);
Serial.print("Loading sysex ");
Serial.print(bankdir);
@ -138,6 +148,7 @@ bool load_sysex(uint8_t b, uint8_t v)
strcpy(bank_name, token);
else
strcpy(bank_name, "*ERROR*");
return (dexed->loadSysexVoice(data));
}
else

@ -35,8 +35,10 @@ extern uint8_t bank;
extern uint8_t voice;
extern char bank_name[11];
extern char voice_name[11];
extern uint8_t ui_state;
extern uint8_t ui_main_state;
bool get_bank_name(uint8_t b);
bool get_bank_voice_name(uint8_t b, uint8_t v);
bool load_sysex(uint8_t b, uint8_t v);
bool get_sysex_voice(char* dir, File sysex, uint8_t voice_number, uint8_t* data);

Loading…
Cancel
Save