diff --git a/Builds/MacOSX/Dexed.xcodeproj/project.xcworkspace/xcuserdata/asb2m10.xcuserdatad/UserInterfaceState.xcuserstate b/Builds/MacOSX/Dexed.xcodeproj/project.xcworkspace/xcuserdata/asb2m10.xcuserdatad/UserInterfaceState.xcuserstate index 164dea0..6f26b18 100644 Binary files a/Builds/MacOSX/Dexed.xcodeproj/project.xcworkspace/xcuserdata/asb2m10.xcuserdatad/UserInterfaceState.xcuserstate and b/Builds/MacOSX/Dexed.xcodeproj/project.xcworkspace/xcuserdata/asb2m10.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/README.md b/README.md index 429a8b6..64af96c 100644 --- a/README.md +++ b/README.md @@ -18,11 +18,12 @@ in the source folder) stays on the Apache 2.0 license to able to collaborate bet Changelog --------- -#### Version 0.8.1 +#### Version 0.8.2 * Cartridge Manager * Apple AU support * Basic theming * Fixed the UI corruption when more than one Dexed instance was loaded +* Fixed wrong display value issues #### Version 0.8.0 * New UI by [AZur Studio](http://bji.yukihotaru.com/) diff --git a/Source/CartManager.cpp b/Source/CartManager.cpp index c43238c..fe58aa9 100644 --- a/Source/CartManager.cpp +++ b/Source/CartManager.cpp @@ -211,6 +211,9 @@ void CartManager::resetActiveSysex() { void CartManager::selectionChanged() { File file = cartBrowser->getSelectedFile(); + + if ( ! file.exists() ) + return; if ( file.isDirectory() ) return; @@ -233,6 +236,9 @@ void CartManager::selectionChanged() { message << ((int)checksum) << " != " << ((int)syx_data[4102]); AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon, "Warning", message); + browserCart->readOnly = true; + } else { + browserCart->readOnly = false; } browserCart->setSelected(-1); browserCart->setCartridge(browserSysex); @@ -270,6 +276,38 @@ void CartManager::programRightClicked(ProgramListBox *source, int pos) { } +void CartManager::programDragged(ProgramListBox *destListBox, int dest, char *packedPgm) { + if ( destListBox == activeCart ) { + char *sysex = mainWindow->processor->sysex; + memcpy(sysex+(dest*128), packedPgm, 128); + mainWindow->updateUI(); + } else { + File file = cartBrowser->getSelectedFile(); + + if ( ! file.exists() ) + return; + + if ( file.isDirectory() ) + return; + if ( file.getSize() > 5000 ) + return; + + MemoryBlock block; + file.loadFileAsData(block); + + if ( block.getSize() < 4104 ) + return; + + char *sysex = ((char *) block.getData()) + 6; + memcpy(sysex+(dest*128), packedPgm, 128); + + char exported[4104]; + exportSysexCart(exported, sysex, 0); + file.replaceWithData(exported, 4104); + browserCart->setCartridge(sysex); + } +} + void CartManager::initialFocus() { cartBrowser->grabKeyboardFocus(); } diff --git a/Source/CartManager.h b/Source/CartManager.h index 0bd7a3c..681a452 100644 --- a/Source/CartManager.h +++ b/Source/CartManager.h @@ -65,6 +65,7 @@ public: virtual void programSelected(ProgramListBox *source, int pos) override; virtual void programRightClicked(ProgramListBox *source, int pos) override; + virtual void programDragged(ProgramListBox *destListBox, int dest, char *packedPgm) override; void initialFocus(); }; diff --git a/Source/Dexed.h b/Source/Dexed.h index a76a1ea..695c75a 100644 --- a/Source/Dexed.h +++ b/Source/Dexed.h @@ -24,14 +24,14 @@ void dexed_trace(const char *source, const char *fmt, ...); #ifdef DEBUG - #define DEXED_VERSION "0.8.1 DEBUG" + #define DEXED_VERSION "0.8.2 DEBUG" #ifdef _MSC_VER #define TRACE(fmt, ...) dexed_trace(__FUNCTION__,fmt,##__VA_ARGS__) #else #define TRACE(fmt, ...) dexed_trace(__PRETTY_FUNCTION__,fmt,##__VA_ARGS__) #endif #else - #define DEXED_VERSION "0.8.1" + #define DEXED_VERSION "0.8.2" #define TRACE(fmt, ...) #endif diff --git a/Source/OperatorEditor.cpp b/Source/OperatorEditor.cpp index 94c4dcb..f9a03ec 100644 --- a/Source/OperatorEditor.cpp +++ b/Source/OperatorEditor.cpp @@ -458,7 +458,7 @@ void OperatorEditor::updateDisplay() { if (opMode->getToggleState() == 0) { if ( freq == 0 ) freq = 0.5; - txtFreq << "f = " << (freq + ((freq*2) * (fine/100))); + txtFreq << "f = " << (freq + (freq * (fine/100))); } else { freq = pow(10,((int)freq)&3); freq = freq + ((freq*10) * (fine/100)); diff --git a/Source/ProgramListBox.cpp b/Source/ProgramListBox.cpp index e0b7e5c..6309421 100644 --- a/Source/ProgramListBox.cpp +++ b/Source/ProgramListBox.cpp @@ -28,6 +28,8 @@ ProgramListBox::ProgramListBox(const String name, int numCols) : Component(name) rows = 32 / numCols; selectedPgm = -1; hasContent = false; + dragCandidate = -1; + readOnly = false; } void ProgramListBox::paint(Graphics &g) { @@ -44,7 +46,6 @@ void ProgramListBox::paint(Graphics &g) { g.setColour(Colour(75,73,73)); g.drawLine(0,getHeight(),getWidth(),getHeight(), 2); - const float dashLength[] = { 4, 4 }; g.setColour(Colour(83,76,69)); @@ -59,14 +60,20 @@ void ProgramListBox::paint(Graphics &g) { for(int i=0;ilistener = listener; } -int ProgramListBox::programPosition(const MouseEvent &event) { - return (event.getMouseDownY() / cellHeight) + ((event.getMouseDownX() / cellWidth) * rows); +int ProgramListBox::programPosition(int x, int y) { + return (y / cellHeight) + ((x / cellWidth) * rows); } void ProgramListBox::mouseDoubleClick(const MouseEvent &event) { @@ -99,7 +106,7 @@ void ProgramListBox::mouseDoubleClick(const MouseEvent &event) { if ( ! event.mods.isLeftButtonDown() ) return; - int pos = programPosition(event); + int pos = programPosition(event.getMouseDownX(), event.getMouseDownY()); if ( listener != nullptr ) listener->programSelected(this, pos); } @@ -110,11 +117,33 @@ void ProgramListBox::mouseDown(const MouseEvent &event) { if ( ! event.mods.isRightButtonDown() ) return; - int pos = programPosition(event); + int pos = programPosition(event.getMouseDownX(), event.getMouseDownY()); if ( listener != nullptr ) listener->programRightClicked(this, pos); } +void ProgramListBox::mouseDrag(const MouseEvent &event) { + if ( ! hasContent ) + return; + if ( dragCandidate != -1 ) + return; + if ( event.getDistanceFromDragStart() < 7 ) + return; + + if (DragAndDropContainer* const dragContainer = DragAndDropContainer::findParentDragContainerFor(this)) { + Image snapshot (Image::ARGB, cellWidth, cellHeight, true); + int position = programPosition(event.getMouseDownX(), event.getMouseDownY()); + Graphics g(snapshot); + g.setColour(DXLookNFeel::lightBackground); + g.fillRect(0,0,cellWidth, cellHeight); + g.setColour(Colours::white); + g.drawFittedText(programNames[position], 0, 0, cellWidth, cellHeight, Justification::centred, true); + void *src = cartContent + (position*128); + var description = var(src, 128); + dragContainer->startDragging(description, this, snapshot, false); + } +} + void ProgramListBox::setSelected(int idx) { selectedPgm = idx; } @@ -124,3 +153,44 @@ char* ProgramListBox::getCurrentCart() { return nullptr; return cartContent; } + +bool ProgramListBox::isInterestedInDragSource (const SourceDetails& dragSourceDetail) { + if ( readOnly ) + return false; + if ( ! hasContent ) + return false; + + Component *comp = dragSourceDetail.sourceComponent.get(); + if ( comp == nullptr ) + return false; + if ( dynamic_cast(comp) == nullptr ) + return false; + + return true; +} + +void ProgramListBox::itemDropped(const SourceDetails& dragSourceDetails) { + dragCandidate = programPosition(dragSourceDetails.localPosition.x, dragSourceDetails.localPosition.y); + + MemoryBlock* block = dragSourceDetails.description.getBinaryData(); + if ( listener != nullptr ) + listener->programDragged(this, dragCandidate, (char *)block->getData()); + dragCandidate = -1; + repaint(); +} + +void ProgramListBox::itemDragEnter(const SourceDetails &dragSourceDetails) { + dragCandidate = programPosition(dragSourceDetails.localPosition.x, dragSourceDetails.localPosition.y); + repaint(); +} + +void ProgramListBox::itemDragMove(const SourceDetails &dragSourceDetails) { + dragCandidate = programPosition(dragSourceDetails.localPosition.x, dragSourceDetails.localPosition.y); + repaint(); +} + +void ProgramListBox::itemDragExit(const SourceDetails &dragSourceDetails) { + dragCandidate = -1; + repaint(); +} + diff --git a/Source/ProgramListBox.h b/Source/ProgramListBox.h index a8c862a..531971a 100644 --- a/Source/ProgramListBox.h +++ b/Source/ProgramListBox.h @@ -29,23 +29,27 @@ public: virtual ~ProgramListBoxListener() {} virtual void programSelected(ProgramListBox *source, int pos) = 0; virtual void programRightClicked(ProgramListBox *source, int pos) = 0; + virtual void programDragged(ProgramListBox *destListBox, int dest, char *packedPgm) = 0; }; -class ProgramListBox : public Component { +class ProgramListBox : public Component, public DragAndDropTarget { ProgramListBoxListener *listener; bool hasContent; bool showPgmNumber; int cols, rows; int cellWidth, cellHeight; - int programPosition(const MouseEvent &event); + int programPosition(int x, int y); int selectedPgm; // TODO: this should be a pointer char cartContent[4104]; - + + int dragCandidate; public: StringArray programNames; + bool readOnly; + ProgramListBox(const String name, int numCols); void addListener(ProgramListBoxListener *listener); void paint(Graphics &g); @@ -53,8 +57,15 @@ public: void resized(); void mouseDoubleClick(const MouseEvent &event); void mouseDown(const MouseEvent &event); + void mouseDrag(const MouseEvent &event); void setSelected(int idx); char* getCurrentCart(); + + bool isInterestedInDragSource(const SourceDetails& dragSourceDetails) override; + void itemDragEnter(const SourceDetails &dragSourceDetails) override; + void itemDragMove(const SourceDetails &dragSourceDetails) override; + void itemDragExit(const SourceDetails &dragSourceDetails) override; + void itemDropped(const SourceDetails& dragSourceDetails) override; };