diff --git a/RadioMusic/AudioEngine.cpp b/RadioMusic/AudioEngine.cpp index c0e3000..c95853b 100644 --- a/RadioMusic/AudioEngine.cpp +++ b/RadioMusic/AudioEngine.cpp @@ -142,7 +142,7 @@ void AudioEngine::changeTo(AudioFileInfo* fileInfo, unsigned long start) { currentFileInfo = fileInfo; // Re-apply speed limits - if(settings->pitchMode) { + if((settings->pitchMode == Settings::PitchMode::Speed) || (settings->pitchMode == Settings::PitchMode::PotSpeedCvStart)) { setPlaybackSpeed(currentPlayer->playbackSpeed); } diff --git a/RadioMusic/FileScanner.cpp b/RadioMusic/FileScanner.cpp index a65109a..b9610ab 100644 --- a/RadioMusic/FileScanner.cpp +++ b/RadioMusic/FileScanner.cpp @@ -44,7 +44,7 @@ void FileScanner::scan(File* root, Settings& settings) { // TODO : remove this when looping is fixed for 24 bit settings.looping = false; settings.hardSwap = true; - settings.pitchMode = true; + settings.pitchMode = Settings::PitchMode::Speed; D( Serial.print("Finished Tip Top with "); Serial.print(lastBankIndex); Serial.println(" active banks");); } else { diff --git a/RadioMusic/Interface.cpp b/RadioMusic/Interface.cpp index b797bc0..5885bbc 100644 --- a/RadioMusic/Interface.cpp +++ b/RadioMusic/Interface.cpp @@ -37,24 +37,43 @@ void Interface::init(int fileSize, int channels, const Settings& settings, PlayS pitchMode = settings.pitchMode; - if(pitchMode) { - quantiseRootCV = settings.quantiseRootCV; - quantiseRootPot = settings.quantiseRootPot; - - float lowNote = settings.lowNote + 0.5; - startCVInput.setRange(lowNote, lowNote + settings.noteRange, quantiseRootCV); - startPotInput.setRange(0.0,48, quantiseRootPot); - startCVInput.borderThreshold = 64; - startPotInput.borderThreshold = 64; - } else { - D(Serial.print("Set Start Range ");Serial.println(ADC_MAX_VALUE / startCVDivider);); - startPotInput.setRange(0.0, ADC_MAX_VALUE / startCVDivider, false); - startCVInput.setRange(0.0, ADC_MAX_VALUE / startCVDivider, false); - startPotInput.setAverage(true); - startCVInput.setAverage(true); - startCVInput.borderThreshold = 32; - startPotInput.borderThreshold = 32; - } + switch(pitchMode) { + default: + case Settings::PitchMode::Start: { + D(Serial.print("Set Start Range ");Serial.println(ADC_MAX_VALUE / startCVDivider);); + startPotInput.setRange(0.0, ADC_MAX_VALUE / startCVDivider, false); + startPotInput.setAverage(true); + startPotInput.borderThreshold = 32; + + startCVInput.setRange(0.0, ADC_MAX_VALUE / startCVDivider, false); + startCVInput.setAverage(true); + startCVInput.borderThreshold = 32; + break; + } + case Settings::PitchMode::Speed: { + quantiseRootPot = settings.quantiseRootPot; + startPotInput.setRange(0.0,48, quantiseRootPot); + startPotInput.borderThreshold = 64; + + quantiseRootCV = settings.quantiseRootCV; + float lowNote = settings.lowNote + 0.5; + startCVInput.setRange(lowNote, lowNote + settings.noteRange, quantiseRootCV); + startCVInput.borderThreshold = 64; + break; + } + case Settings::PitchMode::PotSpeedCvStart: { + quantiseRootPot = settings.quantiseRootPot; + startPotInput.setRange(0.0,48, quantiseRootPot); + startPotInput.borderThreshold = 64; + + startCVInput.setRange(0.0, ADC_MAX_VALUE / startCVDivider, false); + startCVInput.setAverage(true); + startCVInput.borderThreshold = 32; + + break; + } + + } channelPotImmediate = settings.chanPotImmediate; channelCVImmediate = settings.chanCVImmediate; @@ -80,10 +99,12 @@ void Interface::setChannelCount(uint16_t count) { uint16_t Interface::update() { uint16_t channelChanged = updateChannelControls(); - uint16_t startChanged = pitchMode ? updateRootControls() : updateStartControls(); + uint16_t startChanged = updateStartControls(); + uint16_t rootChanged = updateRootControls(); changes = channelChanged; changes |= startChanged; + changes |= rootChanged; changes |= updateButton(); if(resetCVHigh || (changes & BUTTON_SHORT_PRESS)) { @@ -129,26 +150,44 @@ uint16_t Interface::updateChannelControls() { } uint16_t Interface::updateStartControls() { - uint16_t changes = 0; - boolean cvChanged = startCVInput.update(); - boolean potChanged = startPotInput.update(); + if(pitchMode == Settings::PitchMode::Speed) { + return 0; + } + + uint16_t changes = 0; - if(potChanged) { - changes |= TIME_POT_CHANGED; - if(startPotImmediate) { - changes |= CHANGE_START_NOW; + if(pitchMode == Settings::PitchMode::Start) { + boolean potChanged = startPotInput.update(); + if(potChanged) { + changes |= TIME_POT_CHANGED; + if(startPotImmediate) { + changes |= CHANGE_START_NOW; + } } } - if(cvChanged) { - changes |= TIME_CV_CHANGED; - if(startCVImmediate) { - changes |= CHANGE_START_NOW; + if((pitchMode == Settings::PitchMode::Start) || (pitchMode == Settings::PitchMode::PotSpeedCvStart)) { + boolean cvChanged = startCVInput.update(); + if(cvChanged) { + changes |= TIME_CV_CHANGED; + if(startCVImmediate) { + changes |= CHANGE_START_NOW; + } } } - start = constrain(((startCVInput.currentValue * startCVDivider) + (startPotInput.currentValue * startCVDivider)),0,ADC_MAX_VALUE); + switch(pitchMode) { + default: + case Settings::PitchMode::Start: { + start = constrain(((startCVInput.currentValue * startCVDivider) + (startPotInput.currentValue * startCVDivider)),0,ADC_MAX_VALUE); + break; + } + case Settings::PitchMode::PotSpeedCvStart: { + start = constrain(((startCVInput.currentValue * startCVDivider)),0,ADC_MAX_VALUE); + break; + } + } if(changes) { // D( @@ -168,56 +207,62 @@ uint16_t Interface::updateStartControls() { // return bitmap of state of changes for CV, Pot and combined Note. uint16_t Interface::updateRootControls() { - uint16_t change = 0; + if (pitchMode == Settings::PitchMode::Start) { + return 0; + } - boolean cvChanged = startCVInput.update(); - boolean potChanged = startPotInput.update(); + uint16_t change = 0; - // early out if no changes - if(!cvChanged && !potChanged) { - return change; - } + if(pitchMode == Settings::PitchMode::Speed) { + boolean cvChanged = startCVInput.update(); + if(cvChanged) { + D(Serial.println("CV Changed");); + float rootCV = startCVInput.currentValue; + if(quantiseRootCV) { + rootNoteCV = floor(rootCV); + if(rootNoteCV != rootNoteCVOld) { + D(Serial.print("CV ");Serial.println(startCVInput.inputValue);); + change |= ROOT_CV_CHANGED; + } + } else { + rootNoteCV = rootCV; + change |= ROOT_CV_CHANGED; + } + } + } - float rootPot = startPotInput.currentValue; - float rootCV = startCVInput.currentValue; - - if(cvChanged) { - D( - Serial.println("CV Changed"); - ); - if(quantiseRootCV) { - rootNoteCV = floor(rootCV); - if(rootNoteCV != rootNoteCVOld) { - D( - Serial.print("CV ");Serial.println(startCVInput.inputValue); - ); - change |= ROOT_CV_CHANGED; - } - } else { - rootNoteCV = rootCV; - change |= ROOT_CV_CHANGED; - } - } + if((pitchMode == Settings::PitchMode::Speed) || (pitchMode == Settings::PitchMode::PotSpeedCvStart)) { + boolean potChanged = startPotInput.update(); + if(potChanged) { + D(Serial.println("Pot Changed");); + float rootPot = startPotInput.currentValue; + if(quantiseRootPot) { + rootNotePot = floor(rootPot); + if(rootNotePot != rootNotePotOld) { + D(Serial.print("Pot ");Serial.println(startPotInput.inputValue);); + change |= ROOT_POT_CHANGED; + } + } else { + rootNotePot = rootPot; + change |= ROOT_POT_CHANGED; + } + } + } - if(potChanged) { - D( - Serial.println("Pot Changed"); - ); - if(quantiseRootPot) { - rootNotePot = floor(rootPot); - if(rootNotePot != rootNotePotOld) { - D( - Serial.print("Pot ");Serial.println(startPotInput.inputValue); - ); - change |= ROOT_POT_CHANGED; - } - } else { - rootNotePot = rootPot; - change |= ROOT_POT_CHANGED; - } - } + if(!change) + return 0; - rootNote = rootNoteCV + rootNotePot; + switch(pitchMode) { + default: + case Settings::PitchMode::Speed: { + rootNote = rootNoteCV + rootNotePot; + break; + } + case Settings::PitchMode::PotSpeedCvStart: { + rootNote = 24 + rootNotePot; + break; + } + } // Flag note changes when the note index itself changes if(floor(rootNote) != rootNoteOld) { diff --git a/RadioMusic/Interface.h b/RadioMusic/Interface.h index 61be540..0a3dacf 100644 --- a/RadioMusic/Interface.h +++ b/RadioMusic/Interface.h @@ -91,7 +91,7 @@ class Interface { uint16_t updateChannelControls(); uint16_t updateStartControls(); uint16_t updateRootControls(); - boolean pitchMode = false; + Settings::PitchMode pitchMode = Settings::PitchMode::Start; }; #endif diff --git a/RadioMusic/RadioMusic.ino b/RadioMusic/RadioMusic.ino index d571c60..aa5e2ac 100644 --- a/RadioMusic/RadioMusic.ino +++ b/RadioMusic/RadioMusic.ino @@ -317,20 +317,33 @@ uint16_t checkInterface() { bool skipToStartPoint = false; bool speedChange = false; - if(settings.pitchMode) { - - if(resetTriggered) { - skipToStartPoint = true; + switch(settings.pitchMode) { + default: + case Settings::PitchMode::Start: { + if((changes & CHANGE_START_NOW) || resetTriggered) { + skipToStartPoint = true; + } + break; } + case Settings::PitchMode::Speed: { + if(resetTriggered) { + skipToStartPoint = true; + } - if((changes & (ROOT_NOTE_CHANGED | ROOT_POT_CHANGED | ROOT_CV_CHANGED) ) || resetTriggered) { - speedChange = true; + if((changes & (ROOT_NOTE_CHANGED | ROOT_POT_CHANGED | ROOT_CV_CHANGED) ) || resetTriggered) { + speedChange = true; + } + break; } + case Settings::PitchMode::PotSpeedCvStart: { + if((changes & CHANGE_START_NOW) || resetTriggered) { + skipToStartPoint = true; + } - } else { - - if((changes & CHANGE_START_NOW) || resetTriggered) { - skipToStartPoint = true; + if((changes & (ROOT_NOTE_CHANGED | ROOT_POT_CHANGED) ) || resetTriggered) { + speedChange = true; + } + break; } } @@ -344,13 +357,12 @@ uint16_t checkInterface() { if(speedChange) doSpeedChange(); if(skipToStartPoint && !playState.channelChanged) { - if(settings.pitchMode) { + if(settings.pitchMode == Settings::PitchMode::Speed) { audioEngine.skipTo(0); } else { D(Serial.print("Skip to ");Serial.println(interface.start);); audioEngine.skipTo(interface.start); } - } return changes; diff --git a/RadioMusic/Settings.cpp b/RadioMusic/Settings.cpp index 181a1da..9ba28a3 100644 --- a/RadioMusic/Settings.cpp +++ b/RadioMusic/Settings.cpp @@ -88,7 +88,7 @@ void Settings::read() { // startPotImmediate = true; // quantiseRootPot = true; // quantiseRootCV = true; -// pitchMode = true; +// pitchMode = PitchMode::Start; // startCVDivider = 1; #ifdef TEST_RADIO_MODE @@ -100,7 +100,7 @@ void Settings::read() { #endif if(!loopMode) { - if(pitchMode) { + if(pitchMode == PitchMode::Speed) { loopMode = LOOP_MODE_START_POINT; } else { loopMode = LOOP_MODE_RADIO; @@ -109,7 +109,7 @@ void Settings::read() { D(Serial.print("Loop mode ");Serial.println(loopMode);); - if(anyAudioFiles || pitchMode) { + if(anyAudioFiles || (pitchMode == PitchMode::Speed)) { hardSwap = true; } } @@ -126,7 +126,7 @@ void Settings::drumMode() { startCVDivider=1; looping=1; sort=1; - pitchMode=1; + pitchMode = PitchMode::Speed; hardSwap = true; anyAudioFiles = true; loopMode = LOOP_MODE_START_POINT; @@ -144,7 +144,7 @@ void Settings::radioMode() { startCVDivider=2; looping=1; sort=1; - pitchMode=0; + pitchMode = PitchMode::Start; hardSwap = false; anyAudioFiles = false; loopMode = LOOP_MODE_RADIO; @@ -211,7 +211,7 @@ void Settings::applySetting(String settingName, String settingValue) { } if(settingName.equalsIgnoreCase("pitchMode")) { - pitchMode = toBoolean(settingValue); + pitchMode = settingValue.toInt(); } if(settingName.equalsIgnoreCase("hardSwap")) { diff --git a/RadioMusic/Settings.h b/RadioMusic/Settings.h index dcc1164..092436e 100644 --- a/RadioMusic/Settings.h +++ b/RadioMusic/Settings.h @@ -49,7 +49,12 @@ class Settings { boolean sort = true; // By default we sort the directory contents. // Use start pot and cv to control speed instead of start point - boolean pitchMode = false; + enum PitchMode : uint8_t { + Start, + Speed, + PotSpeedCvStart + }; + PitchMode pitchMode = PitchMode::Start; // If this is true we'll read any .wav files and try to play them // if not we'll only play 44khz, 16bit mono files