From 504489175e2dce057ab2462e97f1d4a665d8ecf0 Mon Sep 17 00:00:00 2001 From: EvanR Date: Fri, 8 May 2009 15:38:28 -0500 Subject: [PATCH] Unhardcoded ticks per beat. Fixed triplet bugs. Replaced obvious 128s with TICKS_PER_BEAT. Will now begin testing to see if 128 can be changed to 288 or more for the purposes of allowing correct triplets. Inserting triplets works better now. Probably more triplet related bugs in the pattern editor. --- src/arranger.cpp | 24 +++++++++++++----------- src/eventedit.cpp | 5 +++-- src/metronome.cpp | 6 +++++- src/midi.h | 4 ++-- src/pianoroll.cpp | 26 ++++++++++++++++++++------ src/saveload.cpp | 6 +++--- src/timeline.cpp | 6 +++--- src/uihelper.cpp | 20 ++++++++++---------- 8 files changed, 59 insertions(+), 38 deletions(-) diff --git a/src/arranger.cpp b/src/arranger.cpp index 99e62ae..4a149ca 100644 --- a/src/arranger.cpp +++ b/src/arranger.cpp @@ -46,7 +46,7 @@ using namespace fltk; #define SWAP(X,Y) tmp=X; X=Y; Y=tmp; Arranger::Arranger(int x, int y, int w, int h, const char* label = 0) : fltk::Widget(x, y, w, h, label) { - new_default_w = 128*4; + new_default_w = TICKS_PER_BEAT*4; delete_flag = 0; move_flag = 0; paste_flag = 0; @@ -55,7 +55,7 @@ Arranger::Arranger(int x, int y, int w, int h, const char* label = 0) : fltk::Wi zoom = 30; zoom_n = 4; - q_tick = 128*4; + q_tick = TICKS_PER_BEAT*4; insert_flag = 0; box_flag = 0; @@ -322,10 +322,12 @@ int Arranger::handle(int event){ insert_track = (Y+scrolly) / 30; } else if(rresize_flag){ - rresize_toffset = xpix2tick(X+scrollx)/128*128 - rresize_torig; + rresize_toffset = xpix2tick(X+scrollx)/TICKS_PER_BEAT*TICKS_PER_BEAT - +rresize_torig; } else if(lresize_flag){ - lresize_toffset = xpix2tick(X+scrollx)/128*128 - lresize_torig; + lresize_toffset = xpix2tick(X+scrollx)/TICKS_PER_BEAT*TICKS_PER_BEAT - +lresize_torig; } else if(move_flag){ move_toffset = quantize(xpix2tick(X+scrollx)) - move_torig - move_offset; @@ -606,10 +608,10 @@ void Arranger::draw(){ int W = tick2xpix(T2)-tick2xpix(T1)-1; if(rresize_flag && s->selected && T1==T2){ - W = tick2xpix(128)-1; + W = tick2xpix(TICKS_PER_BEAT)-1; } if(lresize_flag && s->selected && T1==T2){ - W = tick2xpix(128)-1; + W = tick2xpix(TICKS_PER_BEAT)-1; } fillrect(X+1,Y+1,W-2,27); @@ -784,13 +786,13 @@ int Arranger::over_lhandle(seqpat* s){ return (Y > Y1 && Y < Y2 && X < X1 + 5 + 1 && X > X1+1); } -// 4=beats per measure, 128=ticks per beat, 30=width of measure in pixels +// 4=beats per measure, TICKS_PER_BEAT=ticks per beat, 30=width of measure in pixels int Arranger::tick2xpix(int tick){ - return tick *zoom /(128*4); + return tick *zoom /(TICKS_PER_BEAT*4); } int Arranger::xpix2tick(int xpix){ - return xpix * (128*4) /zoom; + return xpix * (TICKS_PER_BEAT*4) /zoom; } int Arranger::quantize(int tick){ @@ -1089,7 +1091,7 @@ void Arranger::apply_rresize(){ } else{ if(T1==T2){ - T2 = T1+128; //magic + T2 = T1+TICKS_PER_BEAT; } c=new ResizeSeqpat(s,T2-T1); set_undo(c); @@ -1149,7 +1151,7 @@ void Arranger::apply_lresize(){ } else{ if(T1==T2){ - T2 = T1+128; //magic + T2 = T1+TICKS_PER_BEAT; } seqpat* stmp = s->prev; c=new MoveSeqpat(s,s->track,T1); diff --git a/src/eventedit.cpp b/src/eventedit.cpp index 22d7f6d..b1f6ce0 100644 --- a/src/eventedit.cpp +++ b/src/eventedit.cpp @@ -34,10 +34,11 @@ #include "uihelper.h" +#include "backend.h" #define MAG_MAX 16383 -#define SWAP(X,Y) tmp=X; X=Y; Y=tmp; +#define SWAP(X,Y) {int tmp=X; X=Y; Y=tmp;} extern struct conf config; @@ -401,7 +402,7 @@ void EventEdit::load(seqpat* s){ } int EventEdit::tick2xpix(int tick){ - return tick*zoom*4 / 128; + return tick*zoom*4 / TICKS_PER_BEAT; } const char* EventEdit::event_type_name(){ diff --git a/src/metronome.cpp b/src/metronome.cpp index 185dfed..16c0a0d 100644 --- a/src/metronome.cpp +++ b/src/metronome.cpp @@ -5,8 +5,12 @@ #include #include +#include "seq.h" +#include "backend.h" #include "metronome.h" + + using namespace fltk; Metronome::Metronome(int x, int y, int w, int h, const char* label = 0) : fltk::Widget(x, y, w, h, label) { @@ -63,7 +67,7 @@ int div(int N){ } void Metronome::update(int tick){ - int now_beat = tick/128; + int now_beat = tick/TICKS_PER_BEAT; if(now_beat != last_beat){ int step = last_beat - now_beat; diff --git a/src/midi.h b/src/midi.h index ca4f3bc..ff28b92 100644 --- a/src/midi.h +++ b/src/midi.h @@ -28,8 +28,8 @@ corresponds to its minimum allowed note length. a beat is divided into four parts at the regular zoom. in 4/4 time this corresponds to 1/16 notes. -lets make the shortest note 1/128 note. -this means there are 128 'ticks' per beat. +lets make the shortest note 1/TICKS_PER_BEAT note. +this means there are TICKS_PER_BEAT 'ticks' per beat. to convert from time in us into ticks do diff --git a/src/pianoroll.cpp b/src/pianoroll.cpp index 79b4b38..4ce0be3 100644 --- a/src/pianoroll.cpp +++ b/src/pianoroll.cpp @@ -165,7 +165,12 @@ int PianoRoll::handle(int event){ else{//begin insert insert_flag = 1; insert_torig = quantize(xpix2tick(X+scrollx)); - insert_toffset = q_tick; + if(trip_flag){ + insert_toffset = (q_tick*4) / 3; + } + else{ + insert_toffset = q_tick; + } //new_orig_t = new_left_t; insert_note = ypix2note(Y+scrolly,1); @@ -247,9 +252,18 @@ int PianoRoll::handle(int event){ box_n2 = ypix2note(Y+scrolly,1); } else if(insert_flag){ - insert_toffset = quantize(xpix2tick(X+scrollx)+q_tick) - insert_torig; - if(insert_toffset<=0){ - insert_toffset -= q_tick; + if(trip_flag){ + int q_tri = (q_tick*4) / 3; + insert_toffset = quantize(xpix2tick(X+scrollx)+q_tri) - insert_torig; + if(insert_toffset<=0){ + insert_toffset -= q_tri; + } + } + else{ + insert_toffset = quantize(xpix2tick(X+scrollx)+q_tick) - insert_torig; + if(insert_toffset<=0){ + insert_toffset -= q_tick; + } } insert_note = ypix2note(Y+scrolly,1); if(insert_note != last_note){ @@ -660,11 +674,11 @@ int PianoRoll::note2ypix(int note){ } int PianoRoll::tick2xpix(int tick){ - return tick*zoom*4 / 128; + return tick*zoom*4 / TICKS_PER_BEAT; } int PianoRoll::xpix2tick(int xpix){ - return xpix*128 / (zoom*4); + return xpix*TICKS_PER_BEAT / (zoom*4); } int PianoRoll::quantize(int tick){ diff --git a/src/saveload.cpp b/src/saveload.cpp index 686672f..3435d11 100644 --- a/src/saveload.cpp +++ b/src/saveload.cpp @@ -638,9 +638,9 @@ int savesmf(const char* filename){ L = htons(L); memcpy(buf+10,&L,2); - //128 ticks per beat, 128 | 0x0000 - buf[12] = 0x00; - buf[13] = 0x80; + //ticks per beat + buf[12] = TICKS_PER_BEAT >> 8; + buf[13] = TICKS_PER_BEAT & 0x00ff; file.write((const char*)buf,14); diff --git a/src/timeline.cpp b/src/timeline.cpp index 5d04926..365eaf8 100644 --- a/src/timeline.cpp +++ b/src/timeline.cpp @@ -209,15 +209,15 @@ void Timeline::update(int ticks){ int Timeline::tick2xpix(int tick){ //return (tick - ticks_offset) * zoom / 128 - scroll; - return tick * zoom / 128 - scroll - ticks_offset*zoom/32; + return tick * zoom / TICKS_PER_BEAT - scroll - ticks_offset*zoom/(32); } int Timeline::xpix2tick(int xpix){ //return (xpix+scroll+ticks_offset*32/zoom)*128 / zoom; - return (xpix+scroll) * 128 / zoom + ticks_offset*120/30; + return (xpix+scroll) * TICKS_PER_BEAT / zoom + ticks_offset*120/30; } int Timeline::quantize(int tick){ - return tick/128 * 128; + return tick/TICKS_PER_BEAT * TICKS_PER_BEAT; } diff --git a/src/uihelper.cpp b/src/uihelper.cpp index 790ae2a..7c11a47 100644 --- a/src/uihelper.cpp +++ b/src/uihelper.cpp @@ -177,10 +177,10 @@ seqpat* rob_check(seqpat* s){ int pos = get_play_position(); int M = config.measures_per_phrase; if(M!=0){ - M = M*config.beats_per_measure*128; + M = M*config.beats_per_measure*TICKS_PER_BEAT; } else{ - M = 4*config.beats_per_measure*128; + M = 4*config.beats_per_measure*TICKS_PER_BEAT; } int P1 = pos/M*M; int P2 = P1 + M; @@ -205,10 +205,10 @@ seqpat* rob_check(seqpat* s){ int pos = get_play_position(); int M = config.measures_per_phrase; if(M!=0){ - M = M*config.beats_per_measure*128; + M = M*config.beats_per_measure*TICKS_PER_BEAT; } else{ - M = 4*config.beats_per_measure*128; + M = 4*config.beats_per_measure*TICKS_PER_BEAT; } int P = pos/M*M + M;//tick at next phrase boundary int W = P - s->tick; @@ -531,7 +531,7 @@ void set_quant(int q){ ui->qbutton64->state(0); ui->qbutton128->state(0); ui->qbutton0->state(0); - ui->piano_roll->set_qtick(128); + ui->piano_roll->set_qtick(TICKS_PER_BEAT); break; case 8: ui->qbutton4->state(0); @@ -541,7 +541,7 @@ void set_quant(int q){ ui->qbutton64->state(0); ui->qbutton128->state(0); ui->qbutton0->state(0); - ui->piano_roll->set_qtick(64); + ui->piano_roll->set_qtick(TICKS_PER_BEAT/2); break; case 16: ui->qbutton4->state(0); @@ -551,7 +551,7 @@ void set_quant(int q){ ui->qbutton64->state(0); ui->qbutton128->state(0); ui->qbutton0->state(0); - ui->piano_roll->set_qtick(32); + ui->piano_roll->set_qtick(TICKS_PER_BEAT/4); break; case 32: ui->qbutton4->state(0); @@ -561,7 +561,7 @@ void set_quant(int q){ ui->qbutton64->state(0); ui->qbutton128->state(0); ui->qbutton0->state(0); - ui->piano_roll->set_qtick(16); + ui->piano_roll->set_qtick(TICKS_PER_BEAT/8); break; case 64: ui->qbutton4->state(0); @@ -571,7 +571,7 @@ void set_quant(int q){ ui->qbutton64->state(1); ui->qbutton128->state(0); ui->qbutton0->state(0); - ui->piano_roll->set_qtick(8); + ui->piano_roll->set_qtick(TICKS_PER_BEAT/16); break; case 128: ui->qbutton4->state(0); @@ -581,7 +581,7 @@ void set_quant(int q){ ui->qbutton64->state(0); ui->qbutton128->state(1); ui->qbutton0->state(0); - ui->piano_roll->set_qtick(4); + ui->piano_roll->set_qtick(TICKS_PER_BEAT/32); break; } } -- 2.11.4.GIT