From 47b8847e5fdf2304be7ac683c260a2b6066472e0 Mon Sep 17 00:00:00 2001 From: EvanR Date: Mon, 5 Jan 2009 16:14:46 -0600 Subject: [PATCH] Restored pattern editor functionality. --- src/arranger.cpp | 8 ++-- src/arranger.h | 1 - src/eventedit.cpp | 16 +++++-- src/keyboard.cpp | 11 +++-- src/pianoroll.cpp | 125 ++++++++++++++++++++++++++++++++---------------------- src/pianoroll.h | 7 +-- src/timeline.cpp | 2 +- src/ui.cpp | 22 +++++++++- src/ui.fl | 8 +++- src/ui.h | 8 ++++ src/uihelper.cpp | 10 +++++ 11 files changed, 149 insertions(+), 69 deletions(-) diff --git a/src/arranger.cpp b/src/arranger.cpp index ad414a1..af13875 100644 --- a/src/arranger.cpp +++ b/src/arranger.cpp @@ -68,7 +68,6 @@ Arranger::Arranger(int x, int y, int w, int h, const char* label = 0) : fltk::Wi maxt = 0; - fakew = 1000; fakeh = 16*30; if(fakeh < h){fakeh = h;} @@ -706,7 +705,6 @@ void Arranger::update(int pos){ if(!is_backend_playing()){ return; } - //int wp = ui->song_scroll->w(); int X1 = tick2xpix(pos); int X2 = X1 - scrollx; if(X2 < 0){ @@ -734,7 +732,11 @@ void Arranger::layout(){ ui->song_vscroll->maximum(0); ui->song_vscroll->minimum(fakeh-h()); int M = ui->song_vscroll->h() - 30; - ui->song_vscroll->slider_size(M - (fakeh-h())); + int newsize = M-(fakeh-h()); + if(newsize<20){ + newsize=20; + } + ui->song_vscroll->slider_size(newsize); } diff --git a/src/arranger.h b/src/arranger.h index 5b59527..94225bb 100644 --- a/src/arranger.h +++ b/src/arranger.h @@ -113,7 +113,6 @@ class Arranger : public fltk::Widget { public: int fakeh; - int fakew; int scrollx; int scrolly; diff --git a/src/eventedit.cpp b/src/eventedit.cpp index 1ec3c39..3402dfe 100644 --- a/src/eventedit.cpp +++ b/src/eventedit.cpp @@ -222,12 +222,16 @@ void EventEdit::draw(){ fltk::setcolor(fltk::GRAY20); fltk::fillrect(0,h()-3,w(),1); for(int i=zoom - scroll; i=0){ + fltk::drawline(i,0,i,h()-1); + } } fltk::setcolor(fltk::GRAY50); for(int i=zoom*4-scroll; i=0){ + fltk::drawline(i,0,i,h()-1); + } } fltk::setcolor(fltk::WHITE); @@ -235,12 +239,16 @@ void EventEdit::draw(){ int I = 0; for(int i=1; I=0){ + fltk::fillrect(I,0,1,h()); + } } fltk::setcolor(fltk::color(128,0,0)); int rightend = tick2xpix(cur_seqpat->dur)-scroll; - fltk::fillrect(rightend,0,1,h()); + if(rightend >=0 && rightend < w()){ + fltk::fillrect(rightend,0,1,h()); + } mevent* e = cur_seqpat->p->events->next; diff --git a/src/keyboard.cpp b/src/keyboard.cpp index c055a15..4ff356b 100644 --- a/src/keyboard.cpp +++ b/src/keyboard.cpp @@ -273,6 +273,9 @@ int Keyboard::handle(int event){ case fltk::PUSH: take_focus(); note = ypix2note(event_y()+scroll, event_x() < w()/2 ? 1 : 0); + if(note < 0 || note > 127){ + return 1; + } cur_note = note; helds[note] = 1; play_note(note,1); @@ -288,10 +291,10 @@ int Keyboard::handle(int event){ } return 1; case fltk::DRAG: - if(event_y() > h() || event_y() < 12){ + note = ypix2note(event_y()+scroll, event_x() < w()/2 ? 1 : 0); + if(note < 0 || note > 127){ return 1; } - note = ypix2note(event_y()+scroll, event_x() < w()/2 ? 1 : 0); if(cur_note != note){ helds[cur_note]=0; cur_note = note; @@ -408,8 +411,8 @@ void Keyboard::draw(){ } fltk::setcolor(fltk::BLACK); - for(int i=-scroll; iselected = 1; resize_arrow_color = fltk::color(128,128,0); - if(over_rhandle(e,X,Y)){//resize + if(over_rhandle(e)){//resize rresize_flag = 1; rresize_torig = e->tick+e->dur; rresize_toffset = 0; } - else if(over_lhandle(e,X,Y)){//resize move + else if(over_lhandle(e)){//resize move lresize_flag = 1; lresize_torig = e->tick; lresize_toffset = 0; @@ -179,7 +183,7 @@ int PianoRoll::handle(int event){ //move_offset = quantize(xpix2tick(X)) - move_torig - move_qoffset; //move_toffset = 0; move_offset = X - tick2xpix(e->tick); - move_norig = ypix2note(event_y(),1); + move_norig = ypix2note(Y+scrolly,1); move_noffset = 0; last_note = move_norig; @@ -215,15 +219,15 @@ int PianoRoll::handle(int event){ if(box_flag){ box_x2 = X; box_y2 = Y; - box_t2 = xpix2tick(X); - box_n2 = ypix2note(Y,1); + box_t2 = xpix2tick(X+scrollx); + box_n2 = ypix2note(Y+scrolly,1); } else if(insert_flag){ - insert_toffset = quantize(xpix2tick(X)+q_tick) - insert_torig; + insert_toffset = quantize(xpix2tick(X+scrollx)+q_tick) - insert_torig; if(insert_toffset<=0){ insert_toffset -= q_tick; } - insert_note = ypix2note(Y,1); + insert_note = ypix2note(Y+scrolly,1); if(insert_note != last_note){ if(config.playinsert){//play on insert ui->keyboard->release_note(last_note,0); @@ -234,7 +238,7 @@ int PianoRoll::handle(int event){ } else if(move_flag){ move_toffset = quantize(xpix2tick(X - move_offset)) - move_torig; - move_noffset = ypix2note(Y,1) - move_norig; + move_noffset = ypix2note(Y+scrolly,1) - move_norig; int N = move_norig+move_noffset; if(N != last_note){ if(config.playmove){//play on move @@ -245,10 +249,10 @@ int PianoRoll::handle(int event){ } } else if(rresize_flag){ - rresize_toffset = quantize(xpix2tick(X)) + q_tick - rresize_torig; + rresize_toffset = quantize(xpix2tick(X+scrollx))+q_tick-rresize_torig; } else if(lresize_flag){ - lresize_toffset = quantize(xpix2tick(X)) - lresize_torig; + lresize_toffset = quantize(xpix2tick(X+scrollx)) - lresize_torig; } redraw(); return 1; @@ -316,25 +320,25 @@ int PianoRoll::handle(int event){ case fltk::MOVE: e = over_note(); if(e){ - if(over_rhandle(e,X,Y)){ + if(over_rhandle(e)){ if(resize_e != e || resize_arrow != 1){ if(e->selected){resize_arrow_color = fltk::color(128,128,0);} else{resize_arrow_color = fltk::color(95,58,119);} resize_e = e; resize_arrow = 1; - resize_x = tick2xpix(e->tick + e->dur) - resize_handle_width; - resize_y = note2ypix(e->value1); + resize_x = tick2xpix(e->tick + e->dur)-scrollx-resize_handle_width; + resize_y = note2ypix(e->value1)-scrolly; redraw(); } } - else if(over_lhandle(e,X,Y)){ + else if(over_lhandle(e)){ if(resize_e != e || resize_arrow != 1){ if(e->selected){resize_arrow_color = fltk::color(128,128,0);} else{resize_arrow_color = fltk::color(95,58,119);} resize_e = e; resize_arrow = -1; - resize_x = tick2xpix(e->tick)+1; - resize_y = note2ypix(e->value1); + resize_x = tick2xpix(e->tick)+1 - scrollx; + resize_y = note2ypix(e->value1) - scrolly; redraw(); } } @@ -360,39 +364,53 @@ int PianoRoll::handle(int event){ void PianoRoll::draw(){ + fltk::push_clip(0,0,w(),h()); + fltk::setcolor(fltk::GRAY05); fltk::fillrect(0,0,w(),h()); fltk::setcolor(fltk::GRAY20); - for(int i=12; i=0){ + fltk::fillrect(0,i,w(),1); + } } - for(int i=zoom; i=0){ + fltk::fillrect(i,0,1,h()); + } } fltk::setcolor(fltk::GRAY30); - for(int i=12*5; i=0){ + fltk::fillrect(0,i,w(),1); + } } fltk::setcolor(fltk::GRAY50); - for(int i=zoom*4; i=0){ + fltk::fillrect(i,0,1,h()); + } } fltk::setcolor(fltk::WHITE); int M = config.beats_per_measure; - for(int i=zoom*4*M; i=0){ + fltk::fillrect(i,0,1,h()); + } } fltk::setcolor(fltk::color(128,0,0)); - int rightend = tick2xpix(cur_seqpat->dur); - fltk::fillrect(rightend,0,1,h()); + int rightend = tick2xpix(cur_seqpat->dur)-scrollx; + if(rightend >=0 && rightend < w()){ + fltk::fillrect(rightend,0,1,h()); + } fltk::setcolor(fltk::color(128,128,0)); - fltk::drawline(0,12*40,w(),12*40); + fltk::fillrect(0,12*40-scrolly,w(),1); int tmp; if(insert_flag){ @@ -400,9 +418,9 @@ void PianoRoll::draw(){ int T1 = insert_torig; int T2 = T1 + insert_toffset; if(T1>T2){SWAP(T1,T2);} - int X = tick2xpix(T1)+1; - int Y = note2ypix(insert_note); - int W = tick2xpix(T2) - X; + int X = tick2xpix(T1)+1 - scrollx; + int Y = note2ypix(insert_note) - scrolly; + int W = tick2xpix(T2)-scrollx - X; fltk::fillrect(X,Y,W,11); } @@ -411,8 +429,8 @@ void PianoRoll::draw(){ mevent* ptr = cur_seqpat->p->events->next; while(ptr){ if(ptr->type == MIDI_NOTE_ON && ptr->selected){ - int X = tick2xpix(ptr->tick+move_toffset)+1; - int Y = note2ypix(ptr->value1+move_noffset); + int X = tick2xpix(ptr->tick+move_toffset)+1-scrollx; + int Y = note2ypix(ptr->value1+move_noffset)-scrolly; int W = tick2xpix(ptr->dur); fltk::fillrect(X,Y,W-1,1); fltk::fillrect(X,Y+11,W-1,1); @@ -451,9 +469,10 @@ void PianoRoll::draw(){ } } - int X = tick2xpix(T1) + 1; - int Y = note2ypix(e->value1); - int W = tick2xpix(T2) - X; + int X = tick2xpix(T1) + 1 - scrollx; + int Y = note2ypix(e->value1) - scrolly; + + int W = tick2xpix(T2)-scrollx - X; get_event_color(e,&c1,&c2,&c3); fltk::setcolor(c1); @@ -526,6 +545,8 @@ void PianoRoll::draw(){ fltk::fillrect(X1,Y2,X2-X1,1); } + fltk::pop_clip(); + } @@ -560,7 +581,7 @@ void PianoRoll::load(seqpat* s){ int PianoRoll::note2ypix(int note){ int udy = 6*(note + (note+7)/12 + note/12) + 12; - return h() - udy + 1; + return 900 - udy + 1; } int PianoRoll::tick2xpix(int tick){ @@ -587,14 +608,17 @@ void PianoRoll::set_zoom(int z){ mevent* PianoRoll::over_note(){ mevent* e = cur_seqpat->p->events->next; + int X = event_x()+scrollx; + int Y = event_y()+scrolly; + int cy, lx, rx; while(e){ if(e->type == MIDI_NOTE_ON){ cy = note2ypix(e->value1); lx = tick2xpix(e->tick); rx = tick2xpix(e->tick+e->dur); - if(event_x() > lx && event_x() < rx && - event_y() < cy+12 && event_y() > cy){ + if(X > lx && X < rx && + Y < cy+12 && Y > cy){ return e; } } @@ -610,15 +634,12 @@ void PianoRoll::update(int pos){ if(!is_backend_playing() || !cur_seqpat){ return; } - //int wp = ui->pattern_scroll->w(); - //int xp = ui->pattern_scroll->xposition(); - //int yp = ui->pattern_scroll->yposition(); int X1 = tick2xpix(pos-cur_seqpat->tick); int X2 = X1 - scrollx; if(X2 < 0){ scrollTo(X1-50<0?0:X1-50,scrolly); } - if(X2 > fakew-30){ + if(X2 > w()-30){ scrollTo(X1-50,scrolly); } } @@ -902,7 +923,9 @@ void PianoRoll::apply_lresize(){ -int PianoRoll::over_rhandle(mevent* e, int X, int Y){ +int PianoRoll::over_rhandle(mevent* e){ + int X = event_x()+scrollx; + int Y = event_y()+scrolly; int X1 = tick2xpix(e->tick); int X2 = X1 + tick2xpix(e->dur); int Y1 = note2ypix(e->value1); @@ -915,7 +938,9 @@ int PianoRoll::over_rhandle(mevent* e, int X, int Y){ return (Y > Y1 && Y < Y2 && X < X2 && X > X2 - resize_handle_width); } -int PianoRoll::over_lhandle(mevent* e, int X, int Y){ +int PianoRoll::over_lhandle(mevent* e){ + int X = event_x()+scrollx; + int Y = event_y()+scrolly; int X1 = tick2xpix(e->tick); int X2 = X1 + tick2xpix(e->dur); int Y1 = note2ypix(e->value1); diff --git a/src/pianoroll.h b/src/pianoroll.h index 6b643b4..282019e 100644 --- a/src/pianoroll.h +++ b/src/pianoroll.h @@ -96,8 +96,8 @@ class PianoRoll : public fltk::Widget { void apply_lresize(); void apply_insert(); - int over_lhandle(mevent* e, int X, int Y); - int over_rhandle(mevent* e, int X, int Y); + int over_lhandle(mevent* e); + int over_rhandle(mevent* e); public: @@ -124,11 +124,12 @@ class PianoRoll : public fltk::Widget { void update(int pos); - int fakew; int fakeh; int scrollx; int scrolly; + int fakehmin; + void scrollTo(int X, int Y); }; diff --git a/src/timeline.cpp b/src/timeline.cpp index 58164d5..2c384a5 100644 --- a/src/timeline.cpp +++ b/src/timeline.cpp @@ -45,7 +45,7 @@ using namespace fltk; Timeline::Timeline(int x, int y, int w, int h, const char* label = 0) : fltk::Widget(x, y, w, h, label) { hand = fltk::SharedImage::get(ROOT_DATA_DIR"gfx/hand.gif"); if(!hand){ - printf("gfx files not found, installed correctly?\n"); + printf("Timeline: gfx files not found, installed correctly?\n"); } scale = 1; label_scale = 1; diff --git a/src/ui.cpp b/src/ui.cpp index 94529b8..96d3905 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -67,6 +67,22 @@ void UI::cb_song_hscroll(fltk::ThumbWheel* o, void* v) { ((UI*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_song_hscroll_i(o,v); } +inline void UI::cb_pattern_vscroll_i(fltk::Scrollbar* o, void*) { + int target = (int)o->value(); + int dummy = ui->piano_roll->scrollx; + ui->piano_roll->scrollTo(dummy,target); +} +void UI::cb_pattern_vscroll(fltk::Scrollbar* o, void* v) { + ((UI*)(o->parent()->parent()->parent()->parent()->parent()->user_data()))->cb_pattern_vscroll_i(o,v); +} + +inline void UI::cb_pattern_hscroll_i(fltk::ThumbWheel* o, void*) { + ui->piano_roll->scrollTo((int)o->value(),ui->piano_roll->scrolly); +} +void UI::cb_pattern_hscroll(fltk::ThumbWheel* o, void* v) { + ((UI*)(o->parent()->parent()->parent()->parent()->parent()->user_data()))->cb_pattern_hscroll_i(o,v); +} + inline void UI::cb_event_menu_button_i(fltk::Button* o, void*) { if(o->state()==0){ ui->event_menu->hide(); @@ -547,8 +563,12 @@ UI::UI() { } {fltk::Scrollbar* o = pattern_vscroll = new fltk::Scrollbar(580, 0, 15, 340); o->set_vertical(); + o->callback((fltk::Callback*)cb_pattern_vscroll); + } + {fltk::ThumbWheel* o = pattern_hscroll = new fltk::ThumbWheel(0, 340, 580, 15); + o->step(10); + o->callback((fltk::Callback*)cb_pattern_hscroll); } - pattern_hscroll = new fltk::ThumbWheel(0, 340, 580, 15); o->end(); fltk::Group::current()->resizable(o); } diff --git a/src/ui.fl b/src/ui.fl index d7d9f94..b3aaa77 100644 --- a/src/ui.fl +++ b/src/ui.fl @@ -111,7 +111,7 @@ o->label_scale=4;} {fltk::Scrollbar} song_vscroll { callback {int target = (int)o->value(); int dummy = ui->arranger->scrollx; -ui->arranger->scrollTo(dummy,target);} selected +ui->arranger->scrollTo(dummy,target);} xywh {370 0 15 415} slider_size 60 } {fltk::ThumbWheel} song_hscroll { @@ -147,10 +147,14 @@ o->edit_flag = 1;} class PianoRoll } {fltk::Scrollbar} pattern_vscroll { + callback {int target = (int)o->value(); +int dummy = ui->piano_roll->scrollx; +ui->piano_roll->scrollTo(dummy,target);} xywh {580 0 15 340} } {fltk::ThumbWheel} pattern_hscroll { - xywh {0 340 580 15} + callback {ui->piano_roll->scrollTo((int)o->value(),ui->piano_roll->scrolly);} selected + xywh {0 340 580 15} step 10 } } {fltk::Group} {} { diff --git a/src/ui.h b/src/ui.h index 67cfe85..17e7262 100644 --- a/src/ui.h +++ b/src/ui.h @@ -65,7 +65,15 @@ public: fltk::Group *pattern_scrollgroup; PianoRoll *piano_roll; fltk::Scrollbar *pattern_vscroll; +private: + inline void cb_pattern_vscroll_i(fltk::Scrollbar*, void*); + static void cb_pattern_vscroll(fltk::Scrollbar*, void*); +public: fltk::ThumbWheel *pattern_hscroll; +private: + inline void cb_pattern_hscroll_i(fltk::ThumbWheel*, void*); + static void cb_pattern_hscroll(fltk::ThumbWheel*, void*); +public: EventEdit *event_edit; EventMenu *event_menu; fltk::Button *event_menu_button; diff --git a/src/uihelper.cpp b/src/uihelper.cpp index b1b9a5a..a630fc4 100644 --- a/src/uihelper.cpp +++ b/src/uihelper.cpp @@ -735,5 +735,15 @@ void init_gui(){ ui->song_hscroll->minimum(0); ui->song_hscroll->maximum(1<<20); + + ui->pattern_timeline->edit_flag = 1; + ui->pattern_timeline->zoom = 15; + ui->pattern_vscroll->minimum(12*75); + ui->pattern_vscroll->maximum(0); + ui->pattern_vscroll->value(300); + ui->pattern_vscroll->slider_size(50); + ui->pattern_hscroll->minimum(0); + ui->pattern_hscroll->maximum(1<<20); + ui->pattern_hscroll->value(0); } -- 2.11.4.GIT