Work on time/tempo tracks.
This commit is contained in:
parent
1246944a95
commit
391ec0757a
|
@ -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 <Track_Widget *>::const_iterator r = _widgets.begin(); r != _widgets.end(); r++ )
|
||||
{
|
||||
printf( "\t" );
|
||||
((Region*)(*r))->dump();
|
||||
}
|
||||
|
||||
printf( "}\n" );
|
||||
}
|
||||
};
|
||||
|
|
7
Region.C
7
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 );
|
||||
}
|
||||
|
|
3
Region.H
3
Region.H
|
@ -64,4 +64,7 @@ public:
|
|||
void resize ( void );
|
||||
|
||||
void normalize ( void );
|
||||
|
||||
void dump ( void );
|
||||
|
||||
};
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
};
|
|
@ -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 <list>
|
||||
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 <Track_Widget *>::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 ) );
|
||||
}
|
||||
|
||||
};
|
|
@ -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 );
|
||||
|
||||
|
|
37
Timeline.H
37
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 <list>
|
||||
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_event> tempo_points;
|
||||
list <signature_event> 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 );
|
||||
}
|
||||
|
||||
};
|
||||
|
|
73
main.C
73
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 );
|
||||
|
||||
|
|
Loading…
Reference in New Issue