diff --git a/Audio_Track.H b/Audio_Track.H index cc542e9..ec013c6 100644 --- a/Audio_Track.H +++ b/Audio_Track.H @@ -46,6 +46,7 @@ public: case FL_DND_DRAG: case FL_DND_ENTER: case FL_ENTER: + dump(); return 1; case FL_DND_LEAVE: case FL_DND_RELEASE: @@ -85,4 +86,22 @@ public: return Track::handle( m ); } } + + + + void + dump ( void ) + { + + printf( "1 \"%s\" {\n", /* name() */ "Track" ); + + sort(); + for ( list ::const_iterator r = _widgets.begin(); r != _widgets.end(); r++ ) + { + printf( "\t" ); + ((Region*)(*r))->dump(); + } + + printf( "}\n" ); + } }; diff --git a/Region.C b/Region.C index 5cb82db..1611c93 100644 --- a/Region.C +++ b/Region.C @@ -356,3 +356,10 @@ Region::normalize ( void ) _scale = _clip->peaks()->normalization_factor( _start, _end ); } + + +void +Region::dump ( void ) +{ + printf( "%lu { \"%s\" %lu %lu }\n", _offset, _clip->name(), _start, _end ); +} diff --git a/Region.H b/Region.H index 0fb8f08..b05dc78 100644 --- a/Region.H +++ b/Region.H @@ -64,4 +64,7 @@ public: void resize ( void ); void normalize ( void ); + + void dump ( void ); + }; diff --git a/Tempo_Track.H b/Tempo_Track.H index e4e24e9..6873c49 100644 --- a/Tempo_Track.H +++ b/Tempo_Track.H @@ -32,8 +32,7 @@ public: Tempo_Track ( int X, int Y, int W, int H ) : Track ( X, Y, W, H ) { - - + box( FL_UP_BOX ); } float diff --git a/Time_Point.H b/Time_Point.H new file mode 100644 index 0000000..b358b78 --- /dev/null +++ b/Time_Point.H @@ -0,0 +1,79 @@ + +/*******************************************************************************/ +/* Copyright (C) 2008 Jonathan Moore Liles */ +/* */ +/* This program is free software; you can redistribute it and/or modify it */ +/* under the terms of the GNU General Public License as published by the */ +/* Free Software Foundation; either version 2 of the License, or (at your */ +/* option) any later version. */ +/* */ +/* This program is distributed in the hope that it will be useful, but WITHOUT */ +/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ +/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */ +/* more details. */ +/* */ +/* You should have received a copy of the GNU General Public License along */ +/* with This program; see the file COPYING. If not,write to the Free Software */ +/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/*******************************************************************************/ + +#pragma once + +#include "Track_Point.H" + +struct time_sig +{ + int beats_per_bar; + int note_type; + + time_sig ( int bpb, int note ) + { + beats_per_bar = bpb; + note_type = note; + } +}; + +class Time_Point : public Track_Point +{ + time_sig _time; + + void + _make_label ( void ) + { + if ( ! _label ) + _label = new char[40]; + + snprintf( _label, 40, "%d/%d", _time.beats_per_bar, _time.note_type ); + } + +public: + + Time_Point ( nframes_t when, int bpb, int note ) : _time( bpb, note ) + { + _offset = when; + _make_label(); + } + + ~Time_Point ( ) + { if ( _label ) delete[] _label; } + +/* beats_per_bar ( void ) const { return _time.beats_per_bar; } */ +/* note_type ( void ) const { return _note_type; } */ + + void time ( int bpb, int note ) { _time.beats_per_bar = bpb; _time.note_type = note; } + time_sig time ( void ) const { return _time; } + + int + handle ( int m ) + { + int r = Track_Widget::handle( m ); + + if ( m == FL_RELEASE ) + { + _track->sort(); + timeline.tracks->redraw(); + } + return r; + } + +}; diff --git a/Time_Track.H b/Time_Track.H new file mode 100644 index 0000000..06ef956 --- /dev/null +++ b/Time_Track.H @@ -0,0 +1,57 @@ + +/*******************************************************************************/ +/* Copyright (C) 2008 Jonathan Moore Liles */ +/* */ +/* This program is free software; you can redistribute it and/or modify it */ +/* under the terms of the GNU General Public License as published by the */ +/* Free Software Foundation; either version 2 of the License, or (at your */ +/* option) any later version. */ +/* */ +/* This program is distributed in the hope that it will be useful, but WITHOUT */ +/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ +/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */ +/* more details. */ +/* */ +/* You should have received a copy of the GNU General Public License along */ +/* with This program; see the file COPYING. If not,write to the Free Software */ +/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/*******************************************************************************/ + +#pragma once + +#include "Track.H" +#include "Time_Point.H" + +#include +using std::list; + +class Time_Track : public Track +{ + +public: + + Time_Track ( int X, int Y, int W, int H ) : Track ( X, Y, W, H ) + { + box( FL_UP_BOX ); + } + + time_sig + time ( nframes_t when ) + { + for ( list ::const_reverse_iterator i = _widgets.rbegin(); + i != _widgets.rend(); i++ ) + { + if ( (*i)->offset() < when ) + return ((Time_Point*)(*i))->time(); + } + + return time_sig( 4, 4 ); + } + + void + time ( nframes_t when, int bpb, int note ) + { + add( new Time_Point( when, bpb, note ) ); + } + +}; diff --git a/Timeline.C b/Timeline.C index 8ab0672..7abc3d1 100644 --- a/Timeline.C +++ b/Timeline.C @@ -49,6 +49,11 @@ Timeline::draw_measure_lines ( int X, int Y, int W, int H, Fl_Color color ) for ( int x = X; x < X + W; ++x ) { measure = ts_to_x( (double)(sample_rate * 60) / beats_per_minute( x_to_ts( x ) + xoffset )); + + /* don't bother with lines this close together */ + if ( measure < 4 ) + break; + if ( 0 == (ts_to_x( xoffset ) + x) % measure ) fl_line( x, Y, x, Y + H ); diff --git a/Timeline.H b/Timeline.H index c18e2a1..47c9a38 100644 --- a/Timeline.H +++ b/Timeline.H @@ -37,6 +37,7 @@ extern Timeline timeline; // #include "Tempo_Track.H" class Tempo_Track; +class Time_Track; // #include "Tempo_Point.H" // #include "Region.H" @@ -44,43 +45,21 @@ class Tempo_Track; #include using std::list; -class timestamped -{ -public: - - nframes_t timestamp; - - bool - operator< ( const timestamped &rhs ) const { return timestamp < rhs.timestamp; } -}; - struct Timeline { - struct tempo_event : timestamped - { - float beats_per_minute; - }; - - struct signature_event : timestamped - { - int beats_per_bar; - int beat_type; - }; - enum snap_flags_e { SNAP_TO_REGION, SNAP_TO_BAR, SNAP_TO_BEAT } snap_to; - list tempo_points; - list signature_points; - Fl_Scroll *scroll; Fl_Pack *tracks; + Fl_Pack *rulers; Fl_Scrollbar *scrollbar; Tempo_Track *tempo_track; + Time_Track *time_track; float fpp; /* frames per pixel */ // nframes_t fpp; @@ -111,4 +90,14 @@ struct Timeline { void beats_per_minute ( nframes_t when, float bpm ); void draw_measure_lines ( int X, int Y, int W, int H, Fl_Color color ); + /** set scroll position */ + void + position ( int X ) + { + xoffset = x_to_ts( X ); + + rulers->damage( FL_DAMAGE_SCROLL ); + tracks->damage( FL_DAMAGE_SCROLL ); + } + }; diff --git a/main.C b/main.C index cf9c445..6dd2949 100644 --- a/main.C +++ b/main.C @@ -43,6 +43,8 @@ #include "Audio_Track.H" #include "Timeline.H" #include "Tempo_Track.H" +#include "Time_Track.H" + #include "const.h" @@ -64,9 +66,11 @@ cb_scroll ( Fl_Widget *w, void *v ) // sb->slider_size( sb->w() / maxx ); // ((Fl_Scrollbar*)sb)->value( sb->value(), 60, 10, maxx ); - timeline.xoffset = timeline.x_to_ts( sb->value() ); - // timeline.tracks->redraw(); - timeline.scroll->redraw(); + timeline.position( sb->value() ); + +/* timeline.xoffset = timeline.x_to_ts( sb->value() ); */ +/* // timeline.tracks->redraw(); */ +/* timeline.scroll->redraw(); */ printf( "%lu\n", timeline.xoffset ); @@ -76,6 +80,14 @@ cb_scroll ( Fl_Widget *w, void *v ) track->damage( FL_DAMAGE_SCROLL ); } + for ( int i = timeline.rulers->children(); i-- ; ) + { + Fl_Group *track = (Fl_Group*)timeline.rulers->child( i ); + track->damage( FL_DAMAGE_SCROLL ); + } + + + /* /\* for ( int j = track->children(); j-- ; ) *\/ */ /* /\* ((Region*)(track->child( j )))->resize(); *\/ */ /* /\* } *\/ */ @@ -93,7 +105,45 @@ main ( int argc, char **argv ) Fl_Double_Window *main_window = new Fl_Double_Window( 0, 0, 800, 600 ); - timeline.scroll = new Fl_Scroll( 0, 0, 800, 600 - 24 ); + Fl::get_system_colors(); + Fl::scheme( "plastic" ); + + { + Fl_Pack *o = new Fl_Pack( 0, 0, 800, 24 * 2, "rulers" ); + o->type( Fl_Pack::VERTICAL ); + + { + Tempo_Track *o = new Tempo_Track( 0, 0, 800, 24 ); + + o->color( FL_RED ); + +// tempo_track->label( "tempo map" ); + o->add( new Tempo_Point( 0, 120 ) ); + o->add( new Tempo_Point( 56000, 250 ) ); + + o->end(); + + timeline.tempo_track = o; + } + + { + Time_Track *o = new Time_Track( 0, 24, 800, 24 ); + + o->color( fl_color_average( FL_RED, FL_WHITE, 0.50f ) ); + + o->add( new Time_Point( 0, 4, 4 ) ); + o->add( new Time_Point( 345344, 6, 8 ) ); + + o->end(); + + timeline.time_track = o; + } + + timeline.rulers = o; + o->end(); + } + + timeline.scroll = new Fl_Scroll( 0, 24 * 2, 800, 600 - (24 * 3) ); timeline.scroll->type( Fl_Scroll::VERTICAL ); timeline.fpp = 256; timeline._beats_per_minute = 120; @@ -102,27 +152,14 @@ main ( int argc, char **argv ) timeline.sample_rate = 44100; + timeline.tracks = new Fl_Pack( 0, 0, 800, 5000 ); timeline.tracks->type( Fl_Pack::VERTICAL ); timeline.tracks->spacing( 20 ); - Fl::get_system_colors(); - Fl::scheme( "plastic" ); // Fl_Group *pack = new Fl_Group( 0, 0, 5000, 600 ); - { - Tempo_Track *tempo_track = new Tempo_Track( 0, 0, 800, 24 ); - -// tempo_track->label( "tempo map" ); - tempo_track->add( new Tempo_Point( 0, 120 ) ); - - tempo_track->add( new Tempo_Point( 56000, 250 ) ); - - tempo_track->end(); - - timeline.tempo_track = tempo_track; - } Track *track1 = new Audio_Track( 40, 0, 800, 100 );