Merge pull request #5 from MrDham/MrDham-patch-1

Added cc control from rod and loop antenna
pull/6/head
MrDham 7 years ago committed by GitHub
commit 4fc7ff1948
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 122
      Open_Theremin_V3/application.cpp

@ -27,15 +27,20 @@ static int32_t volCalibrationBase = 0;
static uint16_t new_midi_note =0; static uint16_t new_midi_note =0;
static uint16_t old_midi_note =0; static uint16_t old_midi_note =0;
static uint16_t new_midi_volume =0; static uint16_t new_midi_loop_cc_val =0;
static uint16_t old_midi_volume =0; static uint16_t old_midi_loop_cc_val =0;
static uint16_t new_midi_rod_cc_val =0;
static uint16_t old_midi_rod_cc_val =0;
static uint16_t new_midi_bend =0; static uint16_t new_midi_bend =0;
static uint16_t old_midi_bend = 0; static uint16_t old_midi_bend = 0;
static uint8_t midi_bend_low; static uint8_t midi_bend_low;
static uint8_t midi_bend_high; static uint8_t midi_bend_high;
static double double_log_freq = 0;
static double midi_key_follow = 0.5; static double midi_key_follow = 0.5;
static uint8_t midi_channel = 0; static uint8_t midi_channel = 0;
static uint8_t old_midi_channel = 0; static uint8_t old_midi_channel = 0;
static uint8_t midi_bend_range = 0; static uint8_t midi_bend_range = 0;
@ -525,27 +530,50 @@ void Application::midi_msg_send(uint8_t channel, uint8_t midi_cmd1, uint8_t midi
// If pitch bend range = 1 no picth bend is generated (portamento will do a better job) // If pitch bend range = 1 no picth bend is generated (portamento will do a better job)
void Application::midi_application () void Application::midi_application ()
{ {
double double_log_freq; // Calculate loop antena cc value for midi
double double_log_bend; new_midi_loop_cc_val = vScaledVolume >> 1;
new_midi_loop_cc_val = min (new_midi_loop_cc_val, 127);
// Calculate volume for midi // Calculate log freq
new_midi_volume = vScaledVolume >> 1; if (vPointerIncrement < 18)
new_midi_volume = min (new_midi_volume, 127); {
// Highest note
double_log_freq = 0;
}
else if (vPointerIncrement > 26315)
{
// Lowest note
double_log_freq = 127;
}
else
{
// Find note in the playing range
double_log_freq = (log (vPointerIncrement/17.152) / 0.057762265); // Precise note played in the logaritmic scale
}
// Calculate rod antena cc value for midi
new_midi_rod_cc_val = round (double_log_freq);
// State machine for MIDI // State machine for MIDI
switch (_midistate) switch (_midistate)
{ {
case MIDI_SILENT: case MIDI_SILENT:
// Synth sound could be in Release phase of ADSR or may have some delay or reverb effect so... // Always refresh midi loop antena cc.
if (new_midi_loop_cc_val != old_midi_loop_cc_val)
// ... don't refresh pitch bend: {
// Instruction "midi_key_follow = 0.5;" and unrefreshed notes would make pitch bend verry messy. midi_msg_send(midi_channel, 0xB0, loop_midi_cc, new_midi_loop_cc_val);
old_midi_loop_cc_val = new_midi_loop_cc_val;
// ... but always refresh midi volume value. }
if (new_midi_volume != old_midi_volume) else
{ {
midi_msg_send(midi_channel, 0xB0, 0x07, new_midi_volume); // do nothing
old_midi_volume = new_midi_volume; }
// Always refresh midi rod antena cc if applicable.
if ((rod_midi_cc != 255) && (new_midi_rod_cc_val != old_midi_rod_cc_val))
{
midi_msg_send(midi_channel, 0xB0, rod_midi_cc, new_midi_rod_cc_val);
old_midi_rod_cc_val = new_midi_rod_cc_val;
} }
else else
{ {
@ -553,7 +581,7 @@ void Application::midi_application ()
} }
// If player's hand moves away from volume antenna // If player's hand moves away from volume antenna
if (new_midi_volume > midi_volume_trigger) if (new_midi_loop_cc_val > midi_volume_trigger)
{ {
// Set key follow to the minimum in order to use closest note played as the center note // Set key follow to the minimum in order to use closest note played as the center note
midi_key_follow = 0.5; midi_key_follow = 0.5;
@ -578,11 +606,22 @@ void Application::midi_application ()
break; break;
case MIDI_PLAYING: case MIDI_PLAYING:
// Always refresh midi volume value // Always refresh midi loop antena cc.
if (new_midi_volume != old_midi_volume) if (new_midi_loop_cc_val != old_midi_loop_cc_val)
{ {
midi_msg_send(midi_channel, 0xB0, 0x07, new_midi_volume); midi_msg_send(midi_channel, 0xB0, loop_midi_cc, new_midi_loop_cc_val);
old_midi_volume = new_midi_volume; old_midi_loop_cc_val = new_midi_loop_cc_val;
}
else
{
// do nothing
}
// Always refresh midi rod antena cc if applicable.
if ((rod_midi_cc != 255) && (new_midi_rod_cc_val != old_midi_rod_cc_val))
{
midi_msg_send(midi_channel, 0xB0, rod_midi_cc, new_midi_rod_cc_val);
old_midi_rod_cc_val = new_midi_rod_cc_val;
} }
else else
{ {
@ -590,7 +629,7 @@ void Application::midi_application ()
} }
// If player's hand is far from volume antenna // If player's hand is far from volume antenna
if (new_midi_volume > midi_volume_trigger) if (new_midi_loop_cc_val > midi_volume_trigger)
{ {
if ( flag_legato_on == 1) if ( flag_legato_on == 1)
{ {
@ -644,10 +683,6 @@ void Application::midi_application ()
// Send all note off // Send all note off
midi_msg_send(midi_channel, 0xB0, 0x7B, 0x00); midi_msg_send(midi_channel, 0xB0, 0x7B, 0x00);
// Mute long release notes
midi_msg_send(midi_channel, 0xB0, 0x07, 0);
old_midi_volume = 0;
_midistate = MIDI_MUTE; _midistate = MIDI_MUTE;
break; break;
@ -660,27 +695,8 @@ void Application::midi_application ()
void Application::calculate_note_bend () void Application::calculate_note_bend ()
{ {
double double_log_freq;
double double_log_bend; double double_log_bend;
double double_norm_log_bend; double double_norm_log_bend;
// Calculate log freq
if (vPointerIncrement < 18)
{
// Highest note
double_log_freq = 0;
}
else if (vPointerIncrement > 26315)
{
// Lowest note
double_log_freq = 127;
}
else
{
// Find note in the playing range
double_log_freq = (log (vPointerIncrement/17.152) / 0.057762265); // Precise note played in the logaritmic scale
}
double_log_bend = double_log_freq - old_midi_note; // How far from last played midi chromatic note we are double_log_bend = double_log_freq - old_midi_note; // How far from last played midi chromatic note we are
@ -867,7 +883,7 @@ void Application::set_parameters ()
rod_midi_cc = 16; // Ribbon Controler rod_midi_cc = 16; // Ribbon Controler
break; break;
default: default:
rod_midi_cc = 74; // Cutoff rod_midi_cc = 74; // Cutoff (exists of both loop and rod)
break; break;
} }
break; break;
@ -881,25 +897,25 @@ void Application::set_parameters ()
loop_midi_cc = 1; // Modulation loop_midi_cc = 1; // Modulation
break; break;
case 1: case 1:
loop_midi_cc = 2; // Breath controler loop_midi_cc = 7; // Volume
break; break;
case 2: case 2:
loop_midi_cc = 4; // Foot controler loop_midi_cc = 11; // Expression
break; break;
case 3: case 3:
loop_midi_cc = 7; // Volume loop_midi_cc = 71; // Resonnance
break; break;
case 4: case 4:
loop_midi_cc = 11; // Expression loop_midi_cc = 74; // Cutoff (exists of both loop and rod)
break; break;
case 5: case 5:
loop_midi_cc = 71; // Resonnance loop_midi_cc = 91; // Reverb
break; break;
case 6: case 6:
loop_midi_cc = 91; // Reverb loop_midi_cc = 93; // Chorus
break; break;
default: default:
loop_midi_cc = 93; // Chorus loop_midi_cc = 95; // Phaser
break; break;
} }
break; break;

Loading…
Cancel
Save