Fixes for volume and panorama handling.

Some small additions to MIDI hanlders.
pull/4/head
Holger Wirtz 5 years ago
parent 0292baede8
commit 13b5a55fff
  1. 121
      MicroDexed.ino
  2. 4
      UI.cpp
  3. 7
      UI.h
  4. 17
      config.h
  5. 2
      dexed.cpp
  6. 2
      dexed.h
  7. 2
      dexed_sysex.cpp
  8. 2
      dexed_sysex.h

@ -5,7 +5,7 @@
(https://github.com/asb2m10/dexed) for the Teensy-3.5/3.6 with audio shield.
Dexed ist heavily based on https://github.com/google/music-synthesizer-for-android
(c)2018 H. Wirtz <wirtz@parasitstudio.de>
(c)2018,2019 H. Wirtz <wirtz@parasitstudio.de>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -101,8 +101,7 @@ uint8_t bank = 0;
uint8_t max_loaded_banks = 0;
uint8_t voice = 0;
float vol = VOLUME;
float vol_right = 1.0;
float vol_left = 1.0;
float pan = 0.5f;
char bank_name[BANK_NAME_LEN];
char voice_name[VOICE_NAME_LEN];
char bank_names[MAX_BANKS][BANK_NAME_LEN];
@ -156,9 +155,11 @@ void setup()
delay(220);
Serial.println(F("MicroDexed based on https://github.com/asb2m10/dexed"));
Serial.println(F("(c)2018 H. Wirtz <wirtz@parasitstudio.de>"));
Serial.println(F("(c)2018,2019 H. Wirtz <wirtz@parasitstudio.de>"));
Serial.println(F("https://github.com/dcoredump/MicroDexed"));
Serial.println(F("<setup start>"));
//init_eeprom();
initial_values_from_eeprom();
setup_midi_devices();
@ -185,7 +186,7 @@ void setup()
Serial.println(F("PT8211 enabled."));
#endif
set_volume(vol, vol_left, vol_right);
set_volume(vol, pan);
// start SD card
SPI.setMOSI(SDCARD_MOSI_PIN);
@ -366,6 +367,13 @@ void handleControlChange(byte inChannel, byte inCtrl, byte inValue)
{
if (checkMidiChannel(inChannel))
{
#ifdef DEBUG
Serial.print(F("CC#"));
Serial.print(inCtrl, DEC);
Serial.print(F(":"));
Serial.println(inValue, DEC);
#endif
switch (inCtrl) {
case 0:
if (inValue < MAX_BANKS)
@ -388,27 +396,11 @@ void handleControlChange(byte inChannel, byte inCtrl, byte inValue)
break;
case 7: // Volume
vol = float(inValue) / 0x7f;
set_volume(vol, vol_left, vol_right);
set_volume(vol, pan);
break;
case 10: // Pan
if (inValue < 64)
{
vol_left = 1.0;
vol_right = float(inValue) / 0x40;
set_volume(vol, vol_left, vol_right);
}
else if (inValue > 64)
{
vol_left = float(0x7f - inValue) / 0x40;
vol_right = 1.0;
set_volume(vol, vol_left, vol_right);
}
else
{
vol_left = 1.0;
vol_right = 1.0;
set_volume(vol, vol_left, vol_right);
}
pan = float(inValue) / 128;
set_volume(vol, pan);
break;
case 32: // BankSelect LSB
bank = inValue;
@ -507,6 +499,18 @@ void handleProgramChange(byte inChannel, byte inProgram)
void handleSystemExclusive(byte *sysex, uint len)
{
#ifdef DEBUG
Serial.print(F("SYSEX-Data["));
Serial.print(len, DEC);
Serial.print(F("]"));
for (uint8_t i = 0; i < len; i++)
{
Serial.print(F(" "));
Serial.print(sysex[i], DEC);
}
Serial.println();
#endif
if (sysex[1] != 0x43) // check for Yamaha sysex
{
#ifdef DEBUG
@ -660,11 +664,10 @@ bool checkMidiChannel(byte inChannel)
return (true);
}
void set_volume(float v, float vr, float vl)
void set_volume(float v, float p)
{
vol = v;
vol_right = vr;
vol_left = vl;
pan = p;
#ifdef DEBUG
uint8_t tmp;
@ -675,33 +678,30 @@ void set_volume(float v, float vr, float vl)
Serial.print(tmp, DEC);
Serial.print(F("/"));
Serial.print(float(tmp) / UCHAR_MAX, DEC);
Serial.print(F("] VOL_L="));
Serial.print(vl, DEC);
Serial.print(F("] PAN="));
Serial.print(F("["));
tmp = EEPROM.read(EEPROM_OFFSET + EEPROM_VOLUME_LEFT_ADDR);
tmp = EEPROM.read(EEPROM_OFFSET + EEPROM_PAN_ADDR);
Serial.print(tmp, DEC);
Serial.print(F("/"));
Serial.print(float(tmp) / UCHAR_MAX, DEC);
Serial.print(F("] VOL_R="));
Serial.print(vr, DEC);
Serial.print(F("["));
tmp = EEPROM.read(EEPROM_OFFSET + EEPROM_VOLUME_RIGHT_ADDR);
Serial.print(tmp, DEC);
Serial.print(F("/"));
Serial.print(float(tmp) / UCHAR_MAX, DEC);
Serial.print(float(tmp) / SCHAR_MAX, DEC);
Serial.println(F("]"));
#endif
#ifdef TEENSY_AUDIO_BOARD
//sgtl5000_1.dacVolume(vol * vol_left, vol * vol_right);
sgtl5000_1.dacVolume(pow(vol * vol_left, 0.2), pow(vol * vol_right, 0.2));
sgtl5000_1.dacVolume(v * sinf(p * PI / 2), v * cosf(p * PI / 2));
#else
volume_master.gain(pow(vol, 0.2));
volume_r.gain(pow(vr, 0.2));
volume_l.gain(pow(vl, 0.2));
volume_master.gain(v);
volume_r.gain(sinf(p * PI / 2));
volume_l.gain(cosf(p * PI / 2));
#endif
}
// https://www.dr-lex.be/info-stuff/volumecontrols.html#table1
inline float logvol(float x)
{
return (0.001 * expf(6.908 * x));
}
void initial_values_from_eeprom(void)
{
uint32_t crc_eeprom = read_eeprom_checksum();
@ -718,16 +718,17 @@ void initial_values_from_eeprom(void)
#ifdef DEBUG
Serial.print(F(" - mismatch -> initializing EEPROM!"));
#endif
eeprom_write(EEPROM_UPDATE_BANK & EEPROM_UPDATE_VOICE & EEPROM_UPDATE_VOL & EEPROM_UPDATE_VOL_R & EEPROM_UPDATE_VOL_L & EEPROM_UPDATE_MIDICHANNEL);
eeprom_write(EEPROM_UPDATE_BANK + EEPROM_UPDATE_VOICE + EEPROM_UPDATE_VOL + EEPROM_UPDATE_PAN + EEPROM_UPDATE_MIDICHANNEL);
}
else
{
bank = EEPROM.read(EEPROM_OFFSET + EEPROM_BANK_ADDR);
voice = EEPROM.read(EEPROM_OFFSET + EEPROM_VOICE_ADDR);
vol = float(EEPROM.read(EEPROM_OFFSET + EEPROM_MASTER_VOLUME_ADDR)) / UCHAR_MAX;
vol_right = float(EEPROM.read(EEPROM_OFFSET + EEPROM_VOLUME_RIGHT_ADDR)) / UCHAR_MAX;
vol_left = float(EEPROM.read(EEPROM_OFFSET + EEPROM_VOLUME_LEFT_ADDR)) / UCHAR_MAX;
pan = float(EEPROM.read(EEPROM_OFFSET + EEPROM_PAN_ADDR)) / SCHAR_MAX;
midi_channel = EEPROM.read(EEPROM_OFFSET + EEPROM_MIDICHANNEL_ADDR);
if (midi_channel > 16)
midi_channel = MIDI_CHANNEL_OMNI;
}
#ifdef DEBUG
Serial.println();
@ -782,8 +783,8 @@ void eeprom_write(uint8_t status)
if (eeprom_update_status != 0)
autostore = 0;
#ifdef DEBUG
Serial.print(F("Updating EEPROM to state to: "));
Serial.println(eeprom_update_status);
Serial.print(F("Updating EEPROM state to: "));
Serial.println(eeprom_update_status, DEC);
#endif
}
@ -815,21 +816,13 @@ void eeprom_update(void)
#endif
eeprom_update_status &= ~EEPROM_UPDATE_VOL;
}
else if (eeprom_update_status & EEPROM_UPDATE_VOL_R)
else if (eeprom_update_status & EEPROM_UPDATE_PAN)
{
EEPROM.update(EEPROM_OFFSET + EEPROM_VOLUME_RIGHT_ADDR, uint8_t(vol_right * UCHAR_MAX));
EEPROM.update(EEPROM_OFFSET + EEPROM_PAN_ADDR, uint8_t(pan * SCHAR_MAX));
#ifdef DEBUG
Serial.println(F("Volume right written to EEPROM"));
Serial.println(F("Panorama written to EEPROM"));
#endif
eeprom_update_status &= ~EEPROM_UPDATE_VOL_R;
}
else if (eeprom_update_status & EEPROM_UPDATE_VOL_L)
{
EEPROM.update(EEPROM_OFFSET + EEPROM_VOLUME_LEFT_ADDR, uint8_t(vol_left * UCHAR_MAX));
#ifdef DEBUG
Serial.println(F("Volume left written to EEPROM"));
#endif
eeprom_update_status &= ~EEPROM_UPDATE_VOL_L;
eeprom_update_status &= ~EEPROM_UPDATE_PAN;
}
else if (eeprom_update_status & EEPROM_UPDATE_MIDICHANNEL )
{
@ -855,6 +848,14 @@ void eeprom_update(void)
eeprom_update_status |= EEPROM_UPDATE_CHECKSUM;
}
void init_eeprom(void)
{
for (uint8_t i = 0; i < EEPROM_DATA_LENGTH; i++)
{
EEPROM.update(EEPROM_OFFSET + i, 0);
}
}
#if defined (DEBUG) && defined (SHOW_CPU_LOAD_MSEC)
void show_cpu_and_mem_usage(void)
{

@ -5,7 +5,7 @@
(https://github.com/asb2m10/dexed) for the Teensy-3.5/3.6 with audio shield.
Dexed ist heavily based on https://github.com/google/music-synthesizer-for-android
(c)2018 H. Wirtz <wirtz@parasitstudio.de>
(c)2018,2019 H. Wirtz <wirtz@parasitstudio.de>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -217,7 +217,7 @@ void handle_ui(void)
enc[i].write(0);
else if (enc[i].read() >= ENC_VOL_STEPS)
enc[i].write(ENC_VOL_STEPS);
set_volume(float(map(enc[i].read(), 0, ENC_VOL_STEPS, 0, 100)) / 100, vol_left, vol_right);
set_volume(float(map(enc[i].read(), 0, ENC_VOL_STEPS, 0, 100)) / 100, pan);
eeprom_write(EEPROM_UPDATE_VOL);
ui_show_volume();
break;

@ -5,7 +5,7 @@
(https://github.com/asb2m10/dexed) for the Teensy-3.5/3.6 with audio shield.
Dexed ist heavily based on https://github.com/google/music-synthesizer-for-android
(c)2018 H. Wirtz <wirtz@parasitstudio.de>
(c)2018,2019 H. Wirtz <wirtz@parasitstudio.de>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -37,8 +37,7 @@ extern Encoder4 enc[2];
extern int32_t enc_val[2];
extern Bounce but[2];
extern float vol;
extern float vol_left;
extern float vol_right;
extern float pan;
extern LiquidCrystalPlus_I2C lcd;
extern uint8_t bank;
extern uint8_t max_loaded_banks;
@ -49,7 +48,7 @@ extern uint8_t ui_state;
extern uint8_t ui_main_state;
extern uint8_t midi_channel;
extern void eeprom_write(uint8_t status);
extern void set_volume(float v, float vr, float vl);
extern void set_volume(float v, float pan);
extern elapsedMillis autostore;
extern elapsedMillis long_button_pressed;
extern uint8_t effect_filter_frq;

@ -5,7 +5,7 @@
(https://github.com/asb2m10/dexed) for the Teensy-3.5/3.6 with audio shield.
Dexed ist heavily based on https://github.com/google/music-synthesizer-for-android
(c)2018 H. Wirtz <wirtz@parasitstudio.de>
(c)2018,2019 H. Wirtz <wirtz@parasitstudio.de>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -142,22 +142,20 @@
// EEPROM address
#define EEPROM_OFFSET 0
#define EEPROM_DATA_LENGTH 6
#define EEPROM_DATA_LENGTH 5
#define EEPROM_CRC32_ADDR EEPROM.length()-sizeof(uint32_t)
#define EEPROM_CRC32_ADDR EEPROM.length()-sizeof(uint32_t)-33
#define EEPROM_BANK_ADDR 0
#define EEPROM_VOICE_ADDR 1
#define EEPROM_MASTER_VOLUME_ADDR 2
#define EEPROM_VOLUME_RIGHT_ADDR 3
#define EEPROM_VOLUME_LEFT_ADDR 4
#define EEPROM_MIDICHANNEL_ADDR 5
#define EEPROM_PAN_ADDR 3
#define EEPROM_MIDICHANNEL_ADDR 4
#define EEPROM_UPDATE_BANK (1<<0)
#define EEPROM_UPDATE_VOICE (1<<1)
#define EEPROM_UPDATE_VOL (1<<2)
#define EEPROM_UPDATE_VOL_R (1<<3)
#define EEPROM_UPDATE_VOL_L (1<<4)
#define EEPROM_UPDATE_MIDICHANNEL (1<<5)
#define EEPROM_UPDATE_PAN (1<<3)
#define EEPROM_UPDATE_MIDICHANNEL (1<<4)
#define EEPROM_UPDATE_CHECKSUM (1<<7)
#define MAX_BANKS 100
@ -165,7 +163,6 @@
#define BANK_NAME_LEN 13 // FAT12 filenames (plus '\0')
#define VOICE_NAME_LEN 11 // 10 (plus '\0')
//*************************************************************************************************
//* DO NO CHANGE ANYTHING BEYOND IF YOU DON'T KNOW WHAT YOU ARE DOING !!!
//*************************************************************************************************

@ -5,7 +5,7 @@
(https://github.com/asb2m10/dexed) for the Teensy-3.5/3.6 with audio shield.
Dexed ist heavily based on https://github.com/google/music-synthesizer-for-android
(c)2018 H. Wirtz <wirtz@parasitstudio.de>
(c)2018,2019 H. Wirtz <wirtz@parasitstudio.de>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

@ -5,7 +5,7 @@
(https://github.com/asb2m10/dexed) for the Teensy-3.5/3.6 with audio shield.
Dexed ist heavily based on https://github.com/google/music-synthesizer-for-android
(c)2018 H. Wirtz <wirtz@parasitstudio.de>
(c)2018,2019 H. Wirtz <wirtz@parasitstudio.de>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

@ -5,7 +5,7 @@
(https://github.com/asb2m10/dexed) for the Teensy-3.5/3.6 with audio shield.
Dexed ist heavily based on https://github.com/google/music-synthesizer-for-android
(c)2018 H. Wirtz <wirtz@parasitstudio.de>
(c)2018,2019 H. Wirtz <wirtz@parasitstudio.de>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

@ -5,7 +5,7 @@
(https://github.com/asb2m10/dexed) for the Teensy-3.5/3.6 with audio shield.
Dexed ist heavily based on https://github.com/google/music-synthesizer-for-android
(c)2018 H. Wirtz <wirtz@parasitstudio.de>
(c)2018,2019 H. Wirtz <wirtz@parasitstudio.de>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

Loading…
Cancel
Save