From 2adb0e184712d03ba93ddfa45d140a33b8b418e7 Mon Sep 17 00:00:00 2001 From: asb2m10 Date: Tue, 16 Jul 2024 18:51:50 -0400 Subject: [PATCH 1/5] WIP CartManager refractor --- Source/CartManager.cpp | 103 +++++++++++++++++++++++----------------- Source/CartManager.h | 24 ++++++---- Source/PluginEditor.cpp | 2 +- 3 files changed, 74 insertions(+), 55 deletions(-) diff --git a/Source/CartManager.cpp b/Source/CartManager.cpp index fede0229..15ce6041 100644 --- a/Source/CartManager.cpp +++ b/Source/CartManager.cpp @@ -1,6 +1,6 @@ /** * - * Copyright (c) 2015-2017 Pascal Gauthier. + * Copyright (c) 2015-2024 Pascal Gauthier. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -41,26 +41,26 @@ class SyxFileFilter : public FileFilter { class FileTreeDrop : public FileTreeComponent { public : FileTreeDrop(DirectoryContentsList &listToShow) : FileTreeComponent(listToShow) {} - + bool isInterestedInFileDrag (const StringArray &files) override { bool found = false; - + for(int i=0; isetBounds(28, 441, 800, 96); activeCart->addListener(this); - + browserCart.reset(new ProgramListBox("browserpgm", 2)); addAndMakeVisible(browserCart.get()); - browserCart->setBounds(635, 18, 200, 384); browserCart->addListener(this); - + // ------------------------- syxFileFilter.reset(new SyxFileFilter()); timeSliceThread.reset(new TimeSliceThread("Cartridge Directory Scanner")); timeSliceThread->startThread(); - + cartBrowserList.reset(new DirectoryContentsList(syxFileFilter.get(), *timeSliceThread.get())); cartBrowserList->setDirectory(cartDir, true, true); cartBrowser.reset(new FileTreeDrop(*cartBrowserList)); cartBrowser->addKeyListener(this); addAndMakeVisible(cartBrowser.get()); - - cartBrowser->setBounds(23, 18, 590, 384); + cartBrowser->setDragAndDropDescription("Sysex Browser"); cartBrowser->addListener(this); - + closeButton.reset(new TextButton("CLOSE")); addAndMakeVisible(closeButton.get()); - closeButton->setBounds(4, 545, 50, 30); closeButton->addListener(this); loadButton.reset(new TextButton("LOAD")); addAndMakeVisible(loadButton.get()); - loadButton->setBounds(52, 545, 50, 30); loadButton->addListener(this); - + saveButton.reset(new TextButton("SAVE")); addAndMakeVisible(saveButton.get()); - saveButton->setBounds(100, 545, 50, 30); saveButton->addListener(this); fileMgrButton.reset(new TextButton("SHOW DIR")); addAndMakeVisible(fileMgrButton.get()); - fileMgrButton->setBounds(148, 545, 70, 30); fileMgrButton->addListener(this); + + activeCartName.reset(new Label("activeCart")); + addAndMakeVisible(activeCartName.get()); + updateCartFilename(); /* * * I've removed this since it only works on the DX7 II. TBC. * - addAndMakeVisible(getDXPgmButton = new TextButton("GET DX7 PGM")); getDXPgmButton->setBounds(656, 545, 100, 30); getDXPgmButton->addListener(this); - + addAndMakeVisible(getDXCartButton = new TextButton("GET DX7 CART")); getDXCartButton->setBounds(755, 545, 100, 30); getDXCartButton->addListener(this); -*/ + */ } CartManager::~CartManager() { @@ -141,12 +137,31 @@ CartManager::~CartManager() { cartBrowserList.reset(NULL); } +void CartManager::resized() { + float activeSize = ((float) getWidth() - 30) / 8; + + activeCart->setBounds(15, 402, activeSize * 8, 96); + browserCart->setBounds(activeSize * 6 + 15, 10, activeSize * 2, 384); + cartBrowser->setBounds(15, 10, activeSize * 6 - 1, 383); + closeButton->setBounds(4, getHeight() - 40, 50, 30); + saveButton->setBounds(100, getHeight() - 40, 50, 30); + loadButton->setBounds(52, getHeight() - 40, 50, 30); + fileMgrButton->setBounds(148, getHeight() - 40, 70, 30); + activeCartName->setBounds(getWidth() - 30 - 100, getHeight() - 40, 100, 30); +} + void CartManager::paint(Graphics &g) { g.fillAll(DXLookNFeel::lightBackground); - g.setColour(DXLookNFeel::roundBackground); +/* 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); + g.drawText("currently loaded cartridge", 38, 410, 150, 40, Justification::left);*/ +} + +void CartManager::updateCartFilename() { + if ( mainWindow->processor->activeFileCartridge.exists() ) + DBG("OK"); + /*activeCartName->setText(mainWindow->processor->activeFileCartridge.getFileName(), NotificationType::dontSendNotification);*/ } void CartManager::programSelected(ProgramListBox *source, int pos) { @@ -171,19 +186,19 @@ void CartManager::buttonClicked(juce::Button *buttonThatWasClicked) { setVisible(false); return; } - + if ( buttonThatWasClicked == loadButton.get() ) { FileChooser fc ("Import original DX sysex...", File::getSpecialLocation(File::SpecialLocationType::userDocumentsDirectory), "*.syx;*.SYX;*.*", 1); - + if ( fc.browseForFileToOpen()) mainWindow->loadCart(fc.getResult()); return; } - + if ( buttonThatWasClicked == saveButton.get() ) { mainWindow->saveCart(); } - + if ( buttonThatWasClicked == fileMgrButton.get() ) { cartDir.revealToUser(); return; @@ -199,7 +214,7 @@ void CartManager::buttonClicked(juce::Button *buttonThatWasClicked) { } return; } - + if ( buttonThatWasClicked == getDXCartButton.get() ) { if ( mainWindow->processor->sysexComm.isInputActive() && mainWindow->processor->sysexComm.isOutputActive() ) { unsigned char msg[] = { 0xF0, 0x43, 0x20, 0x00, 0xF7 }; @@ -221,14 +236,14 @@ void CartManager::fileDoubleClicked(const File& file) { void CartManager::fileClicked(const File& file, const MouseEvent& e) { if ( e.mods.isPopupMenu()) { PopupMenu menu; - + menu.addItem(1000, "Open location"); if ( ! file.isDirectory() ) { menu.addItem(1010, "Send sysex cartridge to DX7"); } menu.addSeparator(); menu.addItem(1020, "Refresh"); - + switch(menu.show()) { case 1000: file.revealToUser(); @@ -261,17 +276,17 @@ void CartManager::selectionChanged() { if ( ! file.exists() ) return; - + if ( file.isDirectory() ) return; - + Cartridge browserSysex; int rc = browserSysex.load(file); if ( rc < 0 ) { AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon, "Error", "Unable to open file"); return; } - + if ( rc != 0 ) { browserCart->readOnly = true; } else { @@ -283,22 +298,22 @@ void CartManager::selectionChanged() { void CartManager::programRightClicked(ProgramListBox *source, int pos) { PopupMenu menu; - + menu.addItem(1000, "Send program '" + source->programNames[pos] + "' to DX7"); - + if ( source == activeCart.get() ) menu.addItem(1010, "Send current sysex cartridge to DX7"); switch(menu.show()) { case 1000: uint8_t unpackPgm[161]; - + if ( source == activeCart.get() ) { mainWindow->processor->currentCart.unpackProgram(unpackPgm, pos); } else { source->getCurrentCart().unpackProgram(unpackPgm, pos); } - + if ( mainWindow->processor->sysexComm.isOutputActive() ) { uint8_t msg[163]; exportSysexPgm(msg, unpackPgm); @@ -306,7 +321,7 @@ void CartManager::programRightClicked(ProgramListBox *source, int pos) { mainWindow->processor->sysexComm.send(MidiMessage(msg, 163)); } break; - + case 1010: mainWindow->processor->sendCurrentSysexCartridge(); break; @@ -321,10 +336,10 @@ void CartManager::programDragged(ProgramListBox *destListBox, int dest, char *pa mainWindow->updateUI(); } else { File file = cartBrowser->getSelectedFile(); - + if ( ! file.exists() ) return; - + if ( file.isDirectory() ) return; if ( file.getSize() != 4104 && file.getSize() != 4096 ) diff --git a/Source/CartManager.h b/Source/CartManager.h index 27fa30e3..1ad3fe4c 100644 --- a/Source/CartManager.h +++ b/Source/CartManager.h @@ -35,18 +35,19 @@ class CartManager : public Component, public Button::Listener, public DragAndDr std::unique_ptr fileMgrButton; std::unique_ptr getDXPgmButton; std::unique_ptr getDXCartButton; - + std::unique_ptr activeCart; std::unique_ptr browserCart; - + std::unique_ptr syxFileFilter; - + std::unique_ptr cartBrowser; std::unique_ptr timeSliceThread; std::unique_ptr cartBrowserList; - + std::unique_ptr