diff --git a/Source/CartManager.cpp b/Source/CartManager.cpp index a0bcdd84..b108516f 100644 --- a/Source/CartManager.cpp +++ b/Source/CartManager.cpp @@ -25,6 +25,7 @@ #include "PluginData.h" #include +#include using namespace ::std; class SyxFileFilter : public FileFilter { @@ -120,6 +121,11 @@ CartManager::CartManager(DexedAudioProcessorEditor *editor) : Component("CartMan addAndMakeVisible(fileMgrButton.get()); fileMgrButton->setBounds(148, 545, 70, 30); fileMgrButton->addListener(this); + + randomButton.reset(new TextButton("LOAD RANDOM CART & PROGRAM")); + addAndMakeVisible(randomButton.get()); + randomButton->setBounds(216, 545, 205, 30); + randomButton->addListener(this); /* * * I've removed this since it only works on the DX7 II. TBC. @@ -146,7 +152,14 @@ void CartManager::paint(Graphics &g) { g.setColour(DXLookNFeel::roundBackground); g.fillRoundedRectangle(8, 418, 843, 126, 15); g.setColour(Colours::whitesmoke); - g.drawText("currently loaded cartridge", 38, 410, 150, 40, Justification::left); + + String path = mainWindow->processor->activeFileCartridge.getFullPathName(); + int maxLength = 110; + if(path.length() > maxLength){ + path = "..." + path.substring(path.length()-maxLength); + } + + g.drawText("currently loaded cartridge: " + path, 38, 410, 775, 40, Justification::left); } void CartManager::programSelected(ProgramListBox *source, int pos) { @@ -189,6 +202,40 @@ void CartManager::buttonClicked(juce::Button *buttonThatWasClicked) { return; } + if ( buttonThatWasClicked == randomButton.get() ) { + Array files; + + for(const auto& iter : RangedDirectoryIterator(DexedAudioProcessor::dexedCartDir, true, "*.syx;*.SYX", File::findFiles)) { + files.add(iter.getFile()); + } + + auto cartIndex = Random::getSystemRandom().nextInt(files.size()); + mainWindow->loadCart(files[cartIndex]); + + int numPrograms = mainWindow->processor->getNumPrograms(); + vector programIndices; + for(int i=0; iprocessor->getProgramName(programIndex).trim(); + if(programName.length() > 0){ + // A program exists at this index. + programSelected(activeCart.get(), programIndex); + break; + } + } + + return; + } + // THIS IS NOT USED if ( buttonThatWasClicked == getDXPgmButton.get() ) { if ( mainWindow->processor->sysexComm.isInputActive() && mainWindow->processor->sysexComm.isOutputActive() ) { diff --git a/Source/CartManager.h b/Source/CartManager.h index 27fa30e3..aecbf5ee 100644 --- a/Source/CartManager.h +++ b/Source/CartManager.h @@ -33,6 +33,7 @@ class CartManager : public Component, public Button::Listener, public DragAndDr std::unique_ptr saveButton; std::unique_ptr closeButton; std::unique_ptr fileMgrButton; + std::unique_ptr randomButton; std::unique_ptr getDXPgmButton; std::unique_ptr getDXCartButton; diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index c1c73b5d..0d58df51 100644 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -125,7 +125,7 @@ void DexedAudioProcessorEditor::loadCart(File file) { } if ( rc != 0 ) { - rc = AlertWindow::showOkCancelBox(AlertWindow::QuestionIcon, "Unable to find DX7 sysex cartridge in file", + rc = AlertWindow::showOkCancelBox(AlertWindow::QuestionIcon, "Unable to find DX7 sysex cartridge in file: " + file.getFullPathName(), "This sysex file is not for the DX7 or it is corrupted. " "Do you still want to load this file as random data ?"); if ( rc == 0 )