From 855ab39c32ba1a26187c216a61e6c65d2c42943f Mon Sep 17 00:00:00 2001 From: EvanR Date: Sun, 21 Dec 2008 23:12:27 -0600 Subject: [PATCH] Event edit gui works more. The graphical feedback for box select, line, delete, and insert work. Buttons C (clear) and X (clear all) were added. shift left drag: draw a box around events. ctrl left drag: choose were to insert event and what value right click drag: choose range of events to delete left drag: draw a line to edit event values middle click drag: choose where to past current selection C button: clear all events of the current type shown in the event editor. X button: clear all events of all type (except note on/off) The actual actions associated with the graphics do not yet work. --- src/eventedit.cpp | 221 ++++++++++++++++++++++++++++++++++++++++++++---------- src/eventedit.h | 52 +++++++++++-- src/pianoroll.cpp | 4 +- src/ui.cpp | 24 +++++- src/ui.fl | 10 ++- src/ui.h | 4 + 6 files changed, 261 insertions(+), 54 deletions(-) diff --git a/src/eventedit.cpp b/src/eventedit.cpp index 331c928..9f3cdc6 100644 --- a/src/eventedit.cpp +++ b/src/eventedit.cpp @@ -58,6 +58,7 @@ EventEdit::EventEdit(int x, int y, int w, int h, const char* label = 0) : fltk:: } int EventEdit::handle(int event){ + int X,Y; switch(event){ case MOUSEWHEEL: if(event_dy() < 0){ @@ -70,49 +71,104 @@ int EventEdit::handle(int event){ return 1; break; case PUSH: + X=event_x(); + Y=event_y(); if(event_button()==1){ - //actually, check for - //shift box select - //control insert event - line_flag=1; - line_orig_x=event_x(); - line_orig_y=event_y(); - line_x = event_x(); - line_y = event_y(); - //more state - redraw(); - return 1; + if(event_state()&fltk::CTRL){//insert + insert_flag = 1; + insert_x = X; + insert_y = Y; + insert_t = xpix2tick(X); + insert_M = ypix2mag(Y); + } + else if(event_state()&fltk::SHIFT){//box select + box_flag=1; + box_x1=X; + box_x2=X; + box_y1=Y; + box_y2=Y; + box_t1=xpix2tick(X); + box_t2=xpix2tick(X); + } + else{//line + line_flag=1; + line_x1=X; + line_x2=X; + line_y1=Y; + line_y2=Y; + line_t1=xpix2tick(X); + line_M1=ypix2mag(Y); + line_t2=line_t1; + line_M2=line_M1; + } } else if(event_button()==2){//paste + paste_flag = 1; + paste_x = X; + paste_t = xpix2tick(X); } else if(event_button()==3){//delete + delete_flag = 1; + delete_x1 = X; + delete_x2 = X; + delete_t1 = xpix2tick(X); + delete_t2 = delete_t1; } + redraw(); + return 1; break; case DRAG: + X=event_x(); + Y=event_y(); if(line_flag){ - line_x = event_x(); - line_y = event_y(); - - - + line_x2 = X; + line_y2 = Y; + line_t2 = xpix2tick(X); + line_M2 = ypix2mag(Y); + } + if(box_flag){ + box_x2 = X; + box_y2 = Y; + } + if(insert_flag){ + insert_x = X; + insert_y = Y; + insert_t = xpix2tick(X); + insert_M = ypix2mag(Y); + } + if(delete_flag){ + delete_x2 = X; + delete_t2 = xpix2tick(X); + } + if(paste_flag){ + paste_x = X; + paste_t = xpix2tick(X); } redraw(); break; case RELEASE: - line_flag=0; - int t1 = ui->piano_roll->xpix2tick(line_orig_x+scroll); - int t2 = ui->piano_roll->xpix2tick(line_x+scroll); - int v1 = ypix2mag(line_orig_y); - int v2 = ypix2mag(line_y); - if(t1>t2){ - int tmp = t2; - t2 = t1; - t1 = tmp; - tmp = v2; - v2 = v1; - v1 = tmp; + if(event_button()==1){//insert, box, line + if(line_flag){ + apply_line(); + line_flag=0; + } + if(box_flag){ + apply_box(); + box_flag=0; + } + if(insert_flag){ + apply_insert(); + insert_flag=0; + } + } + else if(event_button()==2){//complete paste + apply_paste(); + paste_flag=0; + } + else if(event_button()==3){//delete + apply_delete(); + delete_flag = 0; } - apply_line(t1,t2,v1,v2); redraw(); break; } @@ -125,6 +181,20 @@ void EventEdit::draw(){ fltk::push_clip(0,0,w(),h()); + if(delete_flag){ + fltk::setcolor(fltk::color(64,0,0)); + int X1,X2; + if(delete_x1>delete_x2){ + X1=delete_x2; + X2=delete_x1; + } + else{ + X1=delete_x1; + X2=delete_x2; + } + fltk::fillrect(X1,0,X2-X1,h()); + } + fltk::setcolor(fltk::GRAY20); fltk::drawtext(event_type_name(), 2, h()-5); @@ -147,7 +217,7 @@ void EventEdit::draw(){ fltk::fillrect(I,0,1,h()); } - fltk::setcolor(fltk::RED); + fltk::setcolor(fltk::color(128,0,0)); int rightend = tick2xpix(cur_seqpat->dur)-scroll; fltk::fillrect(rightend,0,1,h()); @@ -178,10 +248,10 @@ void EventEdit::draw(){ break; } } - int T1 = ui->piano_roll->xpix2tick(line_orig_x+scroll); - int T2 = ui->piano_roll->xpix2tick(line_x+scroll); - int M1 = ypix2mag(line_orig_y); - int M2 = ypix2mag(line_y); + int T1 = line_t1; + int T2 = line_t2; + int M1 = line_M1; + int M2 = line_M2; if(T1>T2){ int tmp = T2; T2 = T1; @@ -224,9 +294,40 @@ void EventEdit::draw(){ if(line_flag){ fltk::setcolor(fltk::BLUE); - fltk::drawline(line_orig_x,line_orig_y,line_x,line_y); + fltk::drawline(line_x1,line_y1,line_x2,line_y2); + } + + if(box_flag){ + fltk::setcolor(fltk::GREEN); + int X1,X2,Y1,Y2; + if(box_x1>box_x2){ + X1=box_x2; + X2=box_x1; + } + else{ + X1=box_x1; + X2=box_x2; + } + if(box_y1>box_y2){ + Y1=box_y2; + Y2=box_y1; + } + else{ + Y1=box_y1; + Y2=box_y2; + } + fltk::fillrect(X1,Y1,X2-X1,1); + fltk::fillrect(X1,Y1,1,Y2-Y1); + fltk::fillrect(X2,Y1,1,Y2-Y1); + fltk::fillrect(X1,Y2,X2-X1,1); + } + + if(insert_flag){ + fltk::setcolor(fltk::BLUE); + fltk::fillrect(insert_x,insert_y,2,h()-insert_y); } + fltk::pop_clip(); } @@ -345,23 +446,34 @@ int EventEdit::val2mag(int val){ return val*MAG_MAX/127; } -void EventEdit::apply_line(int t1, int t2, int M1, int M2){ +void EventEdit::apply_line(){ mevent* e = cur_seqpat->p->events; Command* c; int N = 0; - while(e->tick < t1){ + int T1, T2; + int M1 = line_M1; + int M2 = line_M2; + if(line_t1>line_t2){ + T1=line_t2; + T2=line_t1; + } + else{ + T1=line_t1; + T2=line_t2; + } + while(e->tick < T1){ e = e->next; if(!e){ return; } } while(e){ - if(e->tick > t2){ + if(e->tick > T2){ break; } if(match_event_type(e)){ - float m = (float)(M2-M1)/(t2-t1); - float b = M1 - m*t1; + float m = (float)(M2-M1)/(T2-T1); + float b = M1 - m*T1; int M = (int)(m*e->tick + b); int V1, V2; if(M<0){M=0;} @@ -392,6 +504,22 @@ void EventEdit::apply_line(int t1, int t2, int M1, int M2){ undo_push(N); } +void EventEdit::apply_box(){ +printf("apply box\n"); +} + +void EventEdit::apply_insert(){ +printf("apply insert\n"); +} + +void EventEdit::apply_delete(){ +printf("apply delete\n"); +} + +void EventEdit::apply_paste(){ +printf("apply paste\n"); +} + int EventEdit::match_event_type(mevent* e){ if(e->type == event_type){ if(e->type == MIDI_CONTROLLER_CHANGE){ @@ -404,5 +532,16 @@ int EventEdit::match_event_type(mevent* e){ } } return 0; - } +} + +int EventEdit::xpix2tick(int xpix){ + ui->piano_roll->xpix2tick(xpix+scroll); +} +void EventEdit::clear_events(){ +printf("clear\n"); +} + +void EventEdit::clear_all_events(){ +printf("clear all\n"); +} diff --git a/src/eventedit.h b/src/eventedit.h index ad236c2..f99e795 100644 --- a/src/eventedit.h +++ b/src/eventedit.h @@ -23,6 +23,8 @@ #ifndef eventedit_h #define eventedit_h +#include + class EventEdit : public fltk::Widget { int event_type; @@ -37,18 +39,53 @@ class EventEdit : public fltk::Widget { int q_tick; - int line_flag; - int line_x; - int line_y; - int line_orig_x; - int line_orig_y; + std::vector selection; + int line_flag; + int line_t1; + int line_M1; + int line_t2; + int line_M2; + int line_x1; + int line_x2; + int line_y1; + int line_y2; + + int box_flag; + int box_x1; + int box_y1; + int box_x2; + int box_y2; + int box_t1; + int box_t2; + + int insert_flag; + int insert_x; + int insert_y; + int insert_t; + int insert_M; + + int paste_flag; + int paste_x; + int paste_t; + + int delete_flag; + int delete_t1; + int delete_t2; + int delete_x1; + int delete_x2; + + int xpix2tick(int xpix); int ypix2mag(int ypix); int mag2ypix(int mag); int mag2val(int mag); int val2mag(int val); - void apply_line(int t1, int t2, int v1, int v2); + void apply_line(); + void apply_box(); + void apply_insert(); + void apply_delete(); + void apply_paste(); int match_event_type(mevent* e); public: @@ -69,6 +106,9 @@ class EventEdit : public fltk::Widget { void load(seqpat* s); void set_qtick(int q){q_tick=q;} + void clear_events(); + void clear_all_events(); + }; #endif diff --git a/src/pianoroll.cpp b/src/pianoroll.cpp index 28af58a..c5a5c53 100644 --- a/src/pianoroll.cpp +++ b/src/pianoroll.cpp @@ -256,7 +256,7 @@ void PianoRoll::draw(){ fltk::fillrect(i,0,1,h()); } - fltk::setcolor(fltk::RED); + fltk::setcolor(fltk::color(128,0,0)); int rightend = tick2xpix(cur_seqpat->dur); fltk::fillrect(rightend,0,1,h()); @@ -272,7 +272,7 @@ void PianoRoll::draw(){ } if(move_flag){ - fltk::setcolor(fltk::RED); + fltk::setcolor(fltk::color(255,0,0)); int X = tick2xpix(move_t)+1; int Y = note2ypix(move_note); int W = tick2xpix(main_sel->dur); diff --git a/src/ui.cpp b/src/ui.cpp index 563963c..bb7e0e5 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -56,6 +56,20 @@ void UI::cb_L(fltk::Button* o, void* v) { ((UI*)(o->parent()->parent()->parent()->parent()->parent()->user_data()))->cb_L_i(o,v); } +inline void UI::cb_C_i(fltk::Button*, void*) { + ui->event_edit->clear_events(); +} +void UI::cb_C(fltk::Button* o, void* v) { + ((UI*)(o->parent()->parent()->parent()->parent()->parent()->user_data()))->cb_C_i(o,v); +} + +inline void UI::cb_X_i(fltk::Button*, void*) { + ui->event_edit->clear_all_events(); +} +void UI::cb_X(fltk::Button* o, void* v) { + ((UI*)(o->parent()->parent()->parent()->parent()->parent()->user_data()))->cb_X_i(o,v); +} + inline void UI::cb_1_i(fltk::Button*, void*) { ui->pattern_edit->hide(); ui->pattern_buttons->hide(); @@ -438,8 +452,14 @@ UI::UI() { o->tooltip("toggle event value labels"); o->type(fltk::Button::TOGGLE); } - new fltk::Button(580, 45, 15, 15, "?"); - new fltk::Button(580, 60, 15, 15, "?"); + {fltk::Button* o = new fltk::Button(580, 45, 15, 15, "C"); + o->callback((fltk::Callback*)cb_C); + o->tooltip("clear these events"); + } + {fltk::Button* o = new fltk::Button(580, 60, 15, 15, "X"); + o->callback((fltk::Callback*)cb_X); + o->tooltip("clear all events in pattern"); + } o->end(); } o->end(); diff --git a/src/ui.fl b/src/ui.fl index bf9328e..8ad15b9 100644 --- a/src/ui.fl +++ b/src/ui.fl @@ -158,17 +158,21 @@ o->resize(960,900);} {fltk::Button} {} { label L callback {ui->event_edit->label_flag = o->state(); -ui->event_edit->redraw();} selected +ui->event_edit->redraw();} tooltip {toggle event value labels} xywh {580 30 15 15} extra_code {o->type(fltk::Button::TOGGLE);} } {fltk::Button} {} { - label {?} + label C + callback {ui->event_edit->clear_events();} + tooltip {clear these events} xywh {580 45 15 15} } {fltk::Button} {} { - label {?} + label X + callback {ui->event_edit->clear_all_events();} selected + tooltip {clear all events in pattern} xywh {580 60 15 15} } } diff --git a/src/ui.h b/src/ui.h index ba2aa0f..2c93e7a 100644 --- a/src/ui.h +++ b/src/ui.h @@ -56,6 +56,10 @@ public: private: inline void cb_L_i(fltk::Button*, void*); static void cb_L(fltk::Button*, void*); + inline void cb_C_i(fltk::Button*, void*); + static void cb_C(fltk::Button*, void*); + inline void cb_X_i(fltk::Button*, void*); + static void cb_X(fltk::Button*, void*); public: TrackSelect *track_select; SampleView *sample_view; -- 2.11.4.GIT