Skip to content

Commit

Permalink
Drag n Drop SCL onto Status Panel (surge-synthesizer#1053)
Browse files Browse the repository at this point in the history
If you drop an .scl file onto the status panel it retunes.
  • Loading branch information
baconpaul authored Aug 19, 2019
1 parent 9a97e61 commit 9f4a358
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 14 deletions.
27 changes: 27 additions & 0 deletions src/common/gui/CStatusPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,30 @@ VSTGUI::CMouseEventResult CStatusPanel::onMouseDown(VSTGUI::CPoint& where, const
return CControl::onMouseDown(where, button);
}

bool CStatusPanel::onDrop(VSTGUI::DragEventData data )
{
doingDrag = false;

auto drag = data.drag;
auto where = data.pos;
uint32_t ct = drag->getCount();
if (ct == 1)
{
IDataPackage::Type t = drag->getDataType(0);
if (t == IDataPackage::kFilePath)
{
const void* fn;
drag->getData(0, fn, t);
const char* fName = static_cast<const char*>(fn);
fs::path fPath(fName);
if ((_stricmp(fPath.extension().generic_string().c_str(), ".scl") == 0))
{
if( editor )
editor->tuningFileDropped(fName);
}
}
}

return true;
}

43 changes: 29 additions & 14 deletions src/common/gui/CStatusPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class SurgeGUIEditor;

class CStatusPanel : public VSTGUI::CControl
class CStatusPanel : public VSTGUI::CControl, public VSTGUI::IDropTarget
{
public:

Expand All @@ -18,21 +18,19 @@ class CStatusPanel : public VSTGUI::CControl
} DisplayFeatures;

CStatusPanel(const VSTGUI::CRect& size, VSTGUI::IControlListener* listener, long tag, SurgeStorage* storage)
: VSTGUI::CControl(size, listener, tag, 0)
{
for( auto i=0; i<numDisplayFeatures; ++i )
dispfeatures[i] = false;

}
: VSTGUI::CControl(size, listener, tag, 0) {
for( auto i=0; i<numDisplayFeatures; ++i )
dispfeatures[i] = false;
doingDrag = false;
}

void setDisplayFeature( DisplayFeatures df, bool v )
void setDisplayFeature( DisplayFeatures df, bool v ) {
if( dispfeatures[df] != v )
{
if( dispfeatures[df] != v )
{
dispfeatures[df] = v;
invalid();
}
dispfeatures[df] = v;
invalid();
}
}

void setEditor(SurgeGUIEditor *e)
{
Expand All @@ -41,8 +39,25 @@ class CStatusPanel : public VSTGUI::CControl

virtual void draw(VSTGUI::CDrawContext* dc);
VSTGUI::CMouseEventResult onMouseDown(VSTGUI::CPoint& where, const VSTGUI::CButtonState& button);


virtual VSTGUI::DragOperation onDragEnter(VSTGUI::DragEventData data) override
{
doingDrag = true;
return VSTGUI::DragOperation::Copy;
}
virtual VSTGUI::DragOperation onDragMove(VSTGUI::DragEventData data) override
{
return VSTGUI::DragOperation::Copy;
}
virtual void onDragLeave(VSTGUI::DragEventData data) override
{
doingDrag = false;
}
virtual bool onDrop(VSTGUI::DragEventData data) override;
virtual VSTGUI::SharedPointer<VSTGUI::IDropTarget> getDropTarget () override { return this; }

protected:
bool doingDrag = false;
bool dispfeatures[numDisplayFeatures];
SurgeStorage* storage = nullptr;
SurgeGUIEditor *editor = nullptr;
Expand Down
4 changes: 4 additions & 0 deletions src/common/gui/SurgeGUIEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2676,6 +2676,10 @@ void SurgeGUIEditor::showTuningMenu(VSTGUI::CPoint &where)
frame->removeView(m, true);
}

void SurgeGUIEditor::tuningFileDropped(std::string fn)
{
this->synth->storage.retuneToScale(Surge::Storage::readSCLFile(fn));
}

void SurgeGUIEditor::setZoomFactor(int zf)
{
Expand Down
1 change: 1 addition & 0 deletions src/common/gui/SurgeGUIEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ class SurgeGUIEditor : public EditorType, public VSTGUI::IControlListener, publi
void showMPEMenu(VSTGUI::CPoint &where);
void toggleTuning();
void showTuningMenu(VSTGUI::CPoint &where);
void tuningFileDropped(std::string fn);
std::string tuningCacheForToggle = "";

private:
Expand Down

0 comments on commit 9f4a358

Please sign in to comment.