Update application.cpp

MrDham-issue30
MrDham 3 years ago committed by GitHub
parent 99d6b8a0ac
commit 634306f3a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 93
      Open_Theremin_V3/application.cpp

@ -67,6 +67,10 @@ static double rod_cc_scale = 1;
static uint16_t data_pot_value = 0; static uint16_t data_pot_value = 0;
static uint16_t old_data_pot_value = 0; static uint16_t old_data_pot_value = 0;
static uint16_t param_pot_value = 0;
static uint16_t old_param_pot_value = 0;
Application::Application() Application::Application()
: _state(PLAYING), : _state(PLAYING),
_mode(NORMAL) { _mode(NORMAL) {
@ -816,13 +820,33 @@ void Application::init_parameters ()
void Application::set_parameters () void Application::set_parameters ()
{ {
uint16_t param_pot_value = 0; uint16_t data_steps;
param_pot_value = analogRead(REGISTER_SELECT_POT); param_pot_value = analogRead(REGISTER_SELECT_POT);
data_pot_value = analogRead(WAVE_SELECT_POT); data_pot_value = analogRead(WAVE_SELECT_POT);
// If data pot moved // If parameter pot moved
if (abs((int32_t)data_pot_value - (int32_t)old_data_pot_value) >= 8) if (abs((int32_t)param_pot_value - (int32_t)old_param_pot_value) >= 8)
{
// Blink the LED relatively to pot position
resetTimer();
if (((param_pot_value >> 7) % 2) == 0)
{
HW_LED1_OFF;
HW_LED2_OFF;
}
else
{
HW_LED1_ON;
HW_LED2_ON;
}
// Memorize data pot value to monitor changes
old_param_pot_value = param_pot_value;
}
// Else If data pot moved
else if (abs((int32_t)data_pot_value - (int32_t)old_data_pot_value) >= 8)
{ {
// Modify selected parameter // Modify selected parameter
switch (param_pot_value >> 7) switch (param_pot_value >> 7)
@ -833,25 +857,30 @@ void Application::set_parameters ()
{ {
case 0: case 0:
registerValue=3; // -1 Octave registerValue=3; // -1 Octave
data_steps = 1;
break; break;
case 1: case 1:
case 2: case 2:
registerValue=2; // Center registerValue=2; // Center
data_steps = 2;
break; break;
default: default:
registerValue=1; // +1 Octave registerValue=1; // +1 Octave
data_steps = 3;
break; break;
} }
break; break;
case 1: case 1:
// Waveform // Waveform
vWavetableSelector=data_pot_value>>7; data_steps = data_pot_value >> 7;
vWavetableSelector = data_steps;
break; break;
case 2: case 2:
// Channel // Channel
midi_channel = (uint8_t)((data_pot_value >> 6) & 0x000F); data_steps = data_pot_value >> 6;
midi_channel = (uint8_t)(data_steps & 0x000F);
if (old_midi_channel != midi_channel) if (old_midi_channel != midi_channel)
{ {
// Send all note off to avoid stuck notes // Send all note off to avoid stuck notes
@ -862,20 +891,18 @@ void Application::set_parameters ()
case 3: case 3:
// Rod antenna mode // Rod antenna mode
switch (data_pot_value >> 7) data_steps = data_pot_value >> 8;
switch (data_steps)
{ {
case 0: case 0:
case 1:
flag_legato_on = 0; flag_legato_on = 0;
flag_pitch_bend_on = 0; flag_pitch_bend_on = 0;
break; break;
case 2: case 1:
case 3:
flag_legato_on = 0; flag_legato_on = 0;
flag_pitch_bend_on = 1; flag_pitch_bend_on = 1;
break; break;
case 4: case 2:
case 5:
flag_legato_on = 1; flag_legato_on = 1;
flag_pitch_bend_on = 0; flag_pitch_bend_on = 0;
break; break;
@ -887,8 +914,9 @@ void Application::set_parameters ()
break; break;
case 4: case 4:
// Pitch bend range // Pitch-Bend range
switch (data_pot_value >> 7) data_steps = data_pot_value >> 7;
switch (data_steps)
{ {
case 0: case 0:
midi_bend_range = 1; midi_bend_range = 1;
@ -919,12 +947,14 @@ void Application::set_parameters ()
case 5: case 5:
// Volume trigger // Volume trigger
data_steps = data_pot_value >> 8;
midi_volume_trigger = (uint8_t)((data_pot_value >> 3) & 0x007F); midi_volume_trigger = (uint8_t)((data_pot_value >> 3) & 0x007F);
break; break;
case 6: case 6:
//Rod antenna cc //Rod antenna cc
switch (data_pot_value >> 7) data_steps = data_pot_value >> 7;
switch (data_steps)
{ {
case 0: case 0:
rod_midi_cc = 255; // Nothing rod_midi_cc = 255; // Nothing
@ -972,7 +1002,8 @@ void Application::set_parameters ()
default: default:
// Loop antenna cc // Loop antenna cc
switch (data_pot_value >> 7) data_steps = data_pot_value >> 7;
switch (data_steps)
{ {
case 0: case 0:
loop_midi_cc = 1; // Modulation loop_midi_cc = 1; // Modulation
@ -1002,7 +1033,39 @@ void Application::set_parameters ()
break; break;
} }
// Blink the LED relatively to pot position
resetTimer();
if ((data_steps % 2) == 0)
{
HW_LED1_OFF;
HW_LED2_OFF;
}
else
{
HW_LED1_ON;
HW_LED2_ON;
}
// Memorize data pot value to monitor changes // Memorize data pot value to monitor changes
old_data_pot_value = data_pot_value; old_data_pot_value = data_pot_value;
} }
else
{
if (timerExpired(65000))
//restore LED status
{
if (_mode == NORMAL)
{
HW_LED1_ON;
HW_LED2_OFF;
}
else
{
HW_LED1_OFF;
HW_LED2_ON;
}
}
}
} }

Loading…
Cancel
Save