Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ RadioMusic/.RadioMusic.ino.swp
RadioMusic/RadioMusic.ino.TEENSY31.hex
>>>>>>> crossFade

*.swo
*.swo
39 changes: 32 additions & 7 deletions RadioMusic/RadioMusic.ino
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@

#define SD_CARD_CHECK_DELAY 20

#define MAX_BANKS 16

// //////////
// TIMERS
// //////////
Expand All @@ -86,6 +88,8 @@ boolean bankChangeMode = false;
File settingsFile;

Settings settings("SETTINGS.TXT");
Settings* localSettings[MAX_BANKS];
Settings* currentSettings = &settings;
LedControl ledControl;
FileScanner fileScanner;
AudioEngine audioEngine;
Expand Down Expand Up @@ -122,9 +126,29 @@ void setup() {
File root = SD.open("/");
fileScanner.scan(&root, settings);

if(settings.local) {
for (int i=0; i < (fileScanner.lastBankIndex+1); i++){
char path[35];
sprintf(path, "%i/LOCAL.TXT",i);
localSettings[i] = (Settings*)malloc(sizeof(Settings));
localSettings[i] = new Settings(path);
localSettings[i]->init(hasSD);
localSettings[i]->local = 1;
}
}

getSavedBankPosition();

audioEngine.init(settings);
if (settings.local) {
*currentSettings = *localSettings[playState.bank];
fileScanner.scan(&root, *currentSettings);
D(
Serial.print("Using local settings from bank ");
Serial.println(playState.bank);
)
}

audioEngine.init(*currentSettings);

int numFiles = 0;
for(int i=0;i<=fileScanner.lastBankIndex;i++) {
Expand All @@ -147,7 +171,7 @@ void setup() {
D(Serial.print("Set bank to ");Serial.println(playState.bank););
}

interface.init(fileScanner.fileInfos[playState.bank][0].size, fileScanner.numFilesInBank[playState.bank], settings, &playState);
interface.init(fileScanner.fileInfos[playState.bank][0].size, fileScanner.numFilesInBank[playState.bank], *currentSettings, &playState);

D(Serial.println("--READY--"););
}
Expand Down Expand Up @@ -272,7 +296,7 @@ void updateDisplay(uint16_t changes) {
} else {
ledFlashTimer = 0;
}
} else if (settings.showMeter && !bankChangeMode) {
} else if (currentSettings->showMeter && !bankChangeMode) {
peakMeter();
}
}
Expand All @@ -299,6 +323,7 @@ uint16_t checkInterface() {
D(Serial.println("Exit bank change mode"););
flashLeds = false;
bankChangeMode = false;
if (settings.local) reBoot(0);
}

if(changes & BUTTON_PULSE) {
Expand All @@ -317,7 +342,7 @@ uint16_t checkInterface() {
bool skipToStartPoint = false;
bool speedChange = false;

if(settings.pitchMode) {
if(currentSettings->pitchMode) {

if(resetTriggered) {
skipToStartPoint = true;
Expand All @@ -344,7 +369,7 @@ uint16_t checkInterface() {

if(speedChange) doSpeedChange();
if(skipToStartPoint && !playState.channelChanged) {
if(settings.pitchMode) {
if(currentSettings->pitchMode) {
audioEngine.skipTo(0);
} else {
D(Serial.print("Skip to ");Serial.println(interface.start););
Expand All @@ -358,7 +383,7 @@ uint16_t checkInterface() {

void doSpeedChange() {
float speed = 1.0;
speed = interface.rootNote - settings.rootNote;
speed = interface.rootNote - currentSettings->rootNote;
D(Serial.print("Root ");Serial.println(interface.rootNote););
speed = pow(2,speed / 12);

Expand Down Expand Up @@ -421,7 +446,7 @@ void engineTest() {
#endif

void peakMeter() {
if( (peakDisplayTimer < 50) || (meterDisplayDelayTimer < settings.meterHide) ) return;
if( (peakDisplayTimer < 50) || (meterDisplayDelayTimer < currentSettings->meterHide) ) return;

float peakReading = audioEngine.getPeak();
int monoPeak = round(peakReading * 4);
Expand Down
22 changes: 16 additions & 6 deletions RadioMusic/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@ void Settings::copyDefaults() {

void Settings::read() {

D(Serial.println("Reading settings.txt"););
D(
Serial.print("Reading ");
Serial.println(_filename);
);

char character;
String settingName;
String settingValue;
settingsFile = SD.open("settings.txt");
settingsFile = SD.open(_filename);

uint8_t NAME = 1;
uint8_t VALUE = 2;
Expand Down Expand Up @@ -72,7 +75,8 @@ void Settings::read() {
settingsFile.close();
} else {
// if the file didn't open, print an error:
Serial.println("error opening settings.txt");
Serial.print("error opening ");
Serial.println(_filename);
}
// Do test settings here

Expand Down Expand Up @@ -240,6 +244,9 @@ void Settings::applySetting(String settingName, String settingValue) {
if(settingName.equalsIgnoreCase("quantiseNotePot") || settingName.equalsIgnoreCase("quantizeRootPot")) {
quantiseRootPot = toBoolean(settingValue);
}
if(settingName.equalsIgnoreCase("local")) {
local = toBoolean(settingValue);
}

}

Expand All @@ -263,12 +270,13 @@ boolean Settings::toBoolean(String settingValue) {
}

void Settings::write() {
Serial.println("Settings file not found, writing new settings");
Serial.print(_filename);
Serial.println(" not found, writing new settings");

// Delete the old One
SD.remove("settings.txt");
SD.remove(_filename);
// Create new one
settingsFile = SD.open("settings.txt", FILE_WRITE);
settingsFile = SD.open(_filename, FILE_WRITE);
settingsFile.print("crossfade=");
settingsFile.println(crossfade);
settingsFile.print("crossfadeTime=");
Expand All @@ -293,6 +301,8 @@ void Settings::write() {
settingsFile.println(sort);
settingsFile.print("pitchMode=");
settingsFile.println(pitchMode);
settingsFile.print("local=");
settingsFile.println(local);
// close the file:
settingsFile.close();
}
3 changes: 3 additions & 0 deletions RadioMusic/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class Settings {
// Only overrides if true. Force no crossfades.
boolean hardSwap = false;

// Check bank directories for local settings.txt files
boolean local = false;

uint8_t loopMode = 0;

private:
Expand Down