zynaddsubfx

ZynAddSubFX open source synthesizer
Log | Files | Refs | Submodules | LICENSE

commit eb22672a8290f05d135d796f70983d3656a31bc7
parent dedd40a47a20e1caed3d5cee86a3eb2c79e953ff
Author: fundamental <[email protected]>
Date:   Sun, 22 Feb 2015 14:04:08 -0500

Partial Undo Support Integration

Diffstat:
Msrc/Misc/Master.cpp | 4++++
Msrc/Misc/MiddleWare.cpp | 21+++++++++++++++++++++
Msrc/UI/Connection.cpp | 18++++++++++++++++++
3 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/src/Misc/Master.cpp b/src/Misc/Master.cpp @@ -204,6 +204,10 @@ static Ports localports = { m.memory->addMemory(mem, i); m.pendingMemory = false; }}, + {"undo_pause",0,0,[](const char *, rtosc::RtData &d) + {d.reply("/undo_pause", "");}}, + {"undo_resume",0,0,[](const char *, rtosc::RtData &d) + {d.reply("/undo_resume", "");}}, }; diff --git a/src/Misc/MiddleWare.cpp b/src/Misc/MiddleWare.cpp @@ -5,6 +5,7 @@ #include <cstdlib> #include <fstream> +#include <rtosc/undo-history.h> #include <rtosc/thread-link.h> #include <rtosc/ports.h> #include <lo/lo.h> @@ -39,6 +40,7 @@ using std::string; rtosc::ThreadLink *bToU = new rtosc::ThreadLink(4096*2,1024); rtosc::ThreadLink *uToB = new rtosc::ThreadLink(4096*2,1024); +rtosc::UndoHistory undo; /****************************************************************************** * LIBLO And Reflection Code * @@ -681,6 +683,8 @@ public: //If currently broadcasting messages bool broadcast = false; + //If accepting undo events as user driven + bool recording_undo = true; void bToUhandle(const char *rtmsg); void tick(void) @@ -778,6 +782,17 @@ MiddleWareImpl::MiddleWareImpl(void) pending_load[i] = 0; actual_load[i] = 0; } + + //Setup Undo + undo.setCallback([this](const char *msg) { + printf("undo callback <%s>\n", msg); + char buf[1024]; + rtosc_message(buf, 1024, "/undo_pause",""); + handleMsg(buf); + handleMsg(msg); + rtosc_message(buf, 1024, "/undo_resume",""); + handleMsg(buf); + }); } MiddleWareImpl::~MiddleWareImpl(void) { @@ -879,6 +894,12 @@ void MiddleWareImpl::bToUhandle(const char *rtmsg) } else if(!strcmp(rtmsg, "/setprogram") && !strcmp(rtosc_argument_string(rtmsg),"cc")) { loadPart(rtosc_argument(rtmsg,0).i, master->bank.ins[rtosc_argument(rtmsg,1).i].filename.c_str(), master, osc); + } else if(!strcmp("/undo_pause", rtmsg)) { + recording_undo = false; + } else if(!strcmp("/undo_resume", rtmsg)) { + recording_undo = true; + } else if(!strcmp("undo_change", rtmsg) && recording_undo) { + undo.recordEvent(rtmsg); } else if(!strcmp(rtmsg, "/broadcast")) { broadcast = true; } else if(broadcast) { diff --git a/src/UI/Connection.cpp b/src/UI/Connection.cpp @@ -4,6 +4,7 @@ #include <rtosc/rtosc.h> #include <rtosc/ports.h> +#include <rtosc/undo-history.h> #include <FL/Fl.H> #include "Fl_Osc_Tree.H" @@ -18,6 +19,7 @@ using namespace GUI; class MasterUI *ui; +extern rtosc::UndoHistory undo; Fl_Osc_Interface *osc;//TODO: the scope of this should be narrowed @@ -25,6 +27,20 @@ Fl_Osc_Interface *osc;//TODO: the scope of this should be narrowed static Fl_Tiled_Image *module_backdrop; #endif +int undo_redo_handler(int) +{ + const bool undo_ = Fl::event_ctrl() && Fl::event_key() == 'z'; + const bool redo = Fl::event_ctrl() && Fl::event_key() == 'r'; + if(undo_) { + printf("Trying to undo an action\n"); + undo.seekHistory(-1); + } else if(redo) { + printf("Trying to redo an action\n"); + undo.seekHistory(+1); + } + return undo_ || redo; +} + void set_module_parameters ( Fl_Widget *o ) { @@ -80,6 +96,7 @@ ui_handle_t GUI::createUi(Fl_Osc_Interface *osc, void *exit) tree->osc = osc; midi_win->show(); + Fl::add_handler(undo_redo_handler); return (void*) (ui = new MasterUI((int*)exit, osc)); } void GUI::destroyUi(ui_handle_t ui) @@ -137,6 +154,7 @@ static rtosc::Ports ports = { } END }; + void GUI::raiseUi(ui_handle_t gui, const char *message) { MasterUI *mui = (MasterUI*)gui;