Skip to content

Commit

Permalink
Add based cartridge name in cartmanager
Browse files Browse the repository at this point in the history
  • Loading branch information
asb2m10 committed Jul 21, 2024
1 parent 2c27328 commit c63a85c
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 23 deletions.
30 changes: 13 additions & 17 deletions Source/CartManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "PluginData.h"

#include <fstream>
using namespace ::std;

class SyxFileFilter : public FileFilter {
public:
Expand Down Expand Up @@ -114,9 +113,9 @@ CartManager::CartManager(DexedAudioProcessorEditor *editor) : Component("CartMan
addAndMakeVisible(fileMgrButton.get());
fileMgrButton->addListener(this);

activeCartName.reset(new Label("activeCart"));
activeCartName.reset(new CartridgeFileDisplay());
addAndMakeVisible(activeCartName.get());
updateCartFilename();

/*
*
* I've removed this since it only works on the DX7 II. TBC.
Expand All @@ -143,25 +142,19 @@ void CartManager::resized() {
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);
closeButton->setBounds(4, getHeight() - 40, 70, 30);
saveButton->setBounds(144, getHeight() - 40, 70, 30);
loadButton->setBounds(74, getHeight() - 40, 70, 30);
fileMgrButton->setBounds(214, getHeight() - 40, 90, 30);
activeCartName->setBounds(getWidth() - 8 - 300, getHeight() - 40, 300, 30);
}

void CartManager::paint(Graphics &g) {
g.fillAll(DXLookNFeel::lightBackground);
/* 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);*/
}

void CartManager::updateCartFilename() {
if ( mainWindow->processor->activeFileCartridge.exists() )
DBG("OK");
/*activeCartName->setText(mainWindow->processor->activeFileCartridge.getFileName(), NotificationType::dontSendNotification);*/
activeCartName->setCartrdigeFile(mainWindow->processor->activeFileCartridge);
}

void CartManager::programSelected(ProgramListBox *source, int pos) {
Expand All @@ -183,15 +176,17 @@ void CartManager::programSelected(ProgramListBox *source, int pos) {
void CartManager::buttonClicked(juce::Button *buttonThatWasClicked) {
if ( buttonThatWasClicked == closeButton.get() ) {
mainWindow->startTimer(100);
setVisible(false);
getParentComponent()->setVisible(false);
return;
}

if ( buttonThatWasClicked == loadButton.get() ) {
FileChooser fc ("Import original DX sysex...", File::getSpecialLocation(File::SpecialLocationType::userDocumentsDirectory), "*.syx;*.SYX;*.*", 1);

if ( fc.browseForFileToOpen())
if ( fc.browseForFileToOpen()) {
mainWindow->loadCart(fc.getResult());
updateCartFilename();
}
return;
}

Expand Down Expand Up @@ -231,6 +226,7 @@ void CartManager::fileDoubleClicked(const File& file) {
return;
mainWindow->loadCart(file);
activeCart->setCartridge(mainWindow->processor->currentCart);
updateCartFilename();
}

void CartManager::fileClicked(const File& file, const MouseEvent& e) {
Expand Down
33 changes: 32 additions & 1 deletion Source/CartManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,37 @@
#include "ProgramListBox.h"
#include "PluginData.h"

class CartridgeFileDisplay : public Component {
File file;
float clickableArea = 0;
public:
void setCartrdigeFile(File &file) {
this->file = file;
repaint();
}

void paint(Graphics& g) override {
g.setColour(Colours::whitesmoke);
if ( file.exists() ) {
g.setFont(g.getCurrentFont().withStyle(Font::underlined));
clickableArea = g.getCurrentFont().getStringWidthFloat(file.getFileName());
g.drawText(file.getFileName(), 0, 0, getWidth(), getHeight(), Justification::right);
g.setFont(g.getCurrentFont().withStyle(Font::plain));
g.drawText("Based on cartridge: ", 0, 0, getWidth() - (clickableArea + 2), getHeight(), Justification::right);
} else {
g.drawText("[No reference to original cartridge]", 0, 0, getWidth(), getHeight(), Justification::right);
clickableArea = 0;
}
}

void mouseDown(const MouseEvent &event) override {
if ( event.getMouseDownX() > getWidth() - clickableArea ) {
if ( file.exists() )
file.revealToUser();
}
}
};

class CartManager : public Component, public Button::Listener, public DragAndDropContainer, public FileBrowserListener
, public ProgramListBoxListener, public KeyListener {
std::unique_ptr<TextButton> newButton;
Expand All @@ -44,7 +75,7 @@ class CartManager : public Component, public Button::Listener, public DragAndDr
std::unique_ptr<FileTreeComponent> cartBrowser;
std::unique_ptr<TimeSliceThread> timeSliceThread;
std::unique_ptr<DirectoryContentsList> cartBrowserList;
std::unique_ptr<Label> activeCartName;
std::unique_ptr<CartridgeFileDisplay> activeCartName;

File cartDir;

Expand Down
14 changes: 9 additions & 5 deletions Source/PluginEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ DexedAudioProcessorEditor::DexedAudioProcessorEditor (DexedAudioProcessor* owner
rebuildProgramCombobox();
global.programs->addListener(this);

addChildComponent(&cartManager);

addChildComponent(&cartManagerCover);
cartManagerCover.addChildComponent(&cartManager);
cartManager.setVisible(true);

updateUI();
startTimer(100);
}
Expand All @@ -106,12 +108,13 @@ void DexedAudioProcessorEditor::paint (Graphics& g) {
void DexedAudioProcessorEditor::cartShow() {
stopTimer();
cartManager.resetActiveSysex();
cartManager.setBounds(16, 16, WINDOW_SIZE_X - 32, WINDOW_SIZE_Y - 94 - 32);
cartManager.setVisible(true);
cartManagerCover.setBounds(0, 0, WINDOW_SIZE_X , WINDOW_SIZE_Y - 94);
cartManager.setBounds(16, 16, cartManagerCover.getWidth() - 32, cartManagerCover.getHeight() - 32);
cartManager.updateCartFilename();
cartManager.initialFocus();
cartManagerCover.setVisible(true);
}


void DexedAudioProcessorEditor::loadCart(File file) {
Cartridge cart;

Expand Down Expand Up @@ -273,6 +276,7 @@ void DexedAudioProcessorEditor::updateUI() {
}
rebuildProgramCombobox();
global.updateDisplay();
cartManager.updateCartFilename();
}

void DexedAudioProcessorEditor::rebuildProgramCombobox() {
Expand Down
2 changes: 2 additions & 0 deletions Source/PluginEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class DexedAudioProcessorEditor : public AudioProcessorEditor, public ComboBox:
OperatorEditor operators[6];
Colour background;
CartManager cartManager;
// This cover is used to disable main window when cart manager is shown
Component cartManagerCover;

SharedResourcePointer<DXLookNFeel> lookAndFeel;
public:
Expand Down

0 comments on commit c63a85c

Please sign in to comment.