From 6aa13251931184ac436e948c3631c9d6477a702e Mon Sep 17 00:00:00 2001 From: EvanR Date: Tue, 6 Jan 2009 15:57:02 -0600 Subject: [PATCH] Enabled undo and redo. Buggy. Fixed key modifiers. Undo and redo are activated with control z and control r, and cannot be remapped yet. It certainly will fail and eventually crash if you fool with layers. I also got it to crash when doing heavy editting in the piano roll. Undoing recorded commands is currently klunky and unusable. --- src/arranger.cpp | 12 ------ src/keyboard.cpp | 10 ++++- src/saveload.cpp | 6 +-- src/seq.cpp | 111 +++++++++++++++++++++++++++++++++++++++++-------------- src/seq.h | 1 + src/uihelper.cpp | 1 + 6 files changed, 98 insertions(+), 43 deletions(-) diff --git a/src/arranger.cpp b/src/arranger.cpp index 3fa3d01..53651ca 100644 --- a/src/arranger.cpp +++ b/src/arranger.cpp @@ -115,18 +115,6 @@ int Arranger::handle(int event){ } return 1; case fltk::SHORTCUT: - if(event_state() && event_key()=='c'){ - - return 1; - } - if(event_state() && event_key()=='v'){ - - return 1; - } - if(event_state() && event_key()=='z'){ - - return 1; - } if(event_key()==fltk::DeleteKey){ apply_delete(); delete_flag = 0; diff --git a/src/keyboard.cpp b/src/keyboard.cpp index be6b429..dc2e796 100644 --- a/src/keyboard.cpp +++ b/src/keyboard.cpp @@ -78,6 +78,14 @@ int keyboard_handler(int e, fltk::Window* w){ if(E==combo(fltk::SpaceKey,0)){ ui->keyboard->set_sustain(1); } + else if(E==combo('z',fltk::CTRL)){ + do_undo(); + ui->main_window->redraw(); + } + else if(E==combo('r',fltk::CTRL)){ + do_redo(); + ui->main_window->redraw(); + } else if(ui->kg_od->cmp(E)){ ui->keyboard->octave_down(); } @@ -521,7 +529,7 @@ void KeyGrabber::draw(){ int KeyGrabber::set_key(int zkey, int zmod){ key = zkey; - mod = zmod; + mod = zmod&(fltk::SHIFT|fltk::CTRL|fltk::ALT|fltk::META|fltk::OPTION); strncpy(str,get_keystring(key,mod),32); redraw(); } diff --git a/src/saveload.cpp b/src/saveload.cpp index f7f6677..f96dda3 100644 --- a/src/saveload.cpp +++ b/src/saveload.cpp @@ -141,9 +141,6 @@ int clear(){ delete t; } - - - ui->title_text->text(""); ui->author_text->text(""); @@ -152,6 +149,9 @@ int clear(){ ui->track_info->clear_tracks(); + + undo_reset(); + ui->main_window->redraw(); } diff --git a/src/seq.cpp b/src/seq.cpp index cf98eaa..02b2a97 100644 --- a/src/seq.cpp +++ b/src/seq.cpp @@ -35,8 +35,10 @@ std::vector tracks; std::list undo_stack; -std::list undo_number; std::list::iterator undo_ptr; +std::list undo_number; +std::list::iterator undo_nptr; + int solo_flag = 0; @@ -174,32 +176,7 @@ int set_default_hsv_value(float v){ default_hsv_value = v; } -void set_undo(Command* c){ - if(undo_ptr != undo_stack.end()){ - //then we need to clean house - //delete everything at and after undo_ptr (for real); - } - - undo_stack.push_back(c); - undo_ptr = undo_stack.end(); - c->redo(); -} - -void undo_push(int n){ - undo_number.push_back(n); -} - -void do_undo(){ - - undo_ptr--; - (*undo_ptr)->undo(); -} - -void do_redo(){ - (*undo_ptr)->redo(); - undo_ptr++; -} @@ -359,7 +336,9 @@ void LayerSeqpat::redo(){ void LayerSeqpat::undo(){ s->p = s->layers->pop(); +printf("ok...%d\n",s->layers->total); if(s->layers->total == 1){ +printf("deleting layers\n"); delete s->layers; s->layers = NULL; } @@ -874,7 +853,7 @@ void layerstack::reallocate(){ } pattern* layerstack::pop(){ - if(index == 1){ + if(index == 0){ return NULL; } if(index == total-1){ @@ -946,3 +925,81 @@ void reset_record_flags(){ } } } + + + + +void set_undo(Command* c){ + if(undo_ptr != undo_stack.end()){ + //printf("changing the past, need to erase the future\n"); + std::list::iterator ptr = undo_ptr; + ptr++; + int N=0; + while(undo_ptr != undo_stack.end()){ + N++; + undo_ptr++; + } + for(int i=0; iredo(); +} + +void undo_push(int n){ + if(n==0){return;} +//printf("pushing number of commands %d\n",n); + undo_number.push_back(n); + undo_nptr++; +} + +void do_undo(){ + if(undo_ptr==undo_stack.begin()){ + printf("no more to undo!\n"); + return; + } +//printf("undoing\n"); + int N = *undo_nptr; + undo_nptr--; + for(int i=0; iundo(); + } +} + +void do_redo(){ + if(undo_ptr==undo_stack.end()){ + printf("no more to redo!\n"); + return; + } +//printf("redoing\n"); + undo_nptr++; + int N = *undo_nptr; + for(int i=0; iredo(); + undo_ptr++; + } +} + +void undo_reset(){ + //printf("undo reset\n"); + int N = undo_stack.size(); + for(int i=0; i::iterator c = undo_stack.end(); + c--; + //delete (*c); + undo_stack.pop_back(); + } + + N = undo_number.size(); + for(int i=0; iarranger->layout(); ui->song_vscroll->slider_size(60); ui->song_vscroll->value(0); -- 2.11.4.GIT