Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a "LOAD RANDOM CART & PROGRAM" button #294

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
49 changes: 48 additions & 1 deletion Source/CartManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "PluginData.h"

#include <fstream>
#include <random>
using namespace ::std;

class SyxFileFilter : public FileFilter {
Expand Down Expand Up @@ -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.
Expand All @@ -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) {
Expand Down Expand Up @@ -189,6 +202,40 @@ void CartManager::buttonClicked(juce::Button *buttonThatWasClicked) {
return;
}

if ( buttonThatWasClicked == randomButton.get() ) {
Array<File> 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<int> programIndices;
for(int i=0; i<numPrograms; i++) {
programIndices.push_back(i);
}

random_device rd;
mt19937 g(rd());
shuffle(programIndices.begin(), programIndices.end(), g);

// A while loop was originally considered here, but this solution prevents the possibility of an infinite loop.
for(int i=0; i<numPrograms; i++) {
int programIndex = programIndices[i];
String programName = mainWindow->processor->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() ) {
Expand Down
1 change: 1 addition & 0 deletions Source/CartManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class CartManager : public Component, public Button::Listener, public DragAndDr
std::unique_ptr<TextButton> saveButton;
std::unique_ptr<TextButton> closeButton;
std::unique_ptr<TextButton> fileMgrButton;
std::unique_ptr<TextButton> randomButton;
std::unique_ptr<TextButton> getDXPgmButton;
std::unique_ptr<TextButton> getDXCartButton;

Expand Down
2 changes: 1 addition & 1 deletion Source/PluginEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down