Crudely begin to support drawing of timecodes on ruler.

This commit is contained in:
Jonathan Moore Liles 2008-04-18 15:18:07 -05:00
parent 24fe463579
commit 714fc8766c
7 changed files with 314 additions and 20 deletions

View File

@ -20,11 +20,11 @@
#include "Audio_File.H"
#include "Audio_File_SF.H"
map <string, Audio_File*> Audio_File::_open_files;
std::map <std::string, Audio_File*> Audio_File::_open_files;
Audio_File::~Audio_File ( )
{
_open_files[ string( _filename ) ] = NULL;
_open_files[ std::string( _filename ) ] = NULL;
}
/** attmpet to open any supported filetype */
@ -34,7 +34,7 @@ Audio_File::from_file ( const char * filename )
Audio_File *a;
if ( ( a = _open_files[ string( filename ) ] ) )
if ( ( a = _open_files[ std::string( filename ) ] ) )
return a;
if ( ( a = Audio_File_SF::from_file( filename ) ) )
@ -51,7 +51,7 @@ done:
/* a->_peaks->clip( a ); */
/* a->_peaks->open(); */
_open_files[ string( filename ) ] = a;
_open_files[ std::string( filename ) ] = a;
return a;
}

View File

@ -23,19 +23,17 @@
#include <stdlib.h>
#include "types.h"
typedef float sample_t;
#include "Peaks.H"
#include <string>
#include <map>
using namespace std;
class Peak_Writer;
class Audio_File
{
static map <string, Audio_File*> _open_files;
static std::map <std::string, Audio_File*> _open_files;
protected:

152
Timeline/Ruler_Point.H Normal file
View File

@ -0,0 +1,152 @@
/*******************************************************************************/
/* 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 "Loggable.H"
#include "Track_Point.H"
class Ruler_Point : public Track_Point
{
public:
const char *name ( void ) const { return _label; }
void name ( const char *s )
{
if ( _label )
free( _label );
_label = strdup( s );
}
protected:
const char *class_name ( void ) { return "Ruler_Point"; }
char ** get ( void )
{
char **sa = (char**)malloc( sizeof( char* ) * 4 );
int i = 0;
asprintf( &sa[i++], ":track 0x%X", _track ? _track->id() : 0 );
asprintf( &sa[i++], ":x %lu", _r->offset );
asprintf( &sa[i++], ":label \"%s\"", _label );
sa[i] = NULL;
return sa;
}
void
set ( char **sa )
{
for ( int i = 0; sa[i]; ++i )
{
char *s = sa[i];
strtok( s, " " );
char *v = s + strlen( s ) + 1;
if ( ! strcmp( s, ":x" ) )
_r->offset = atol( v );
else if ( ! strcmp( s, ":label" ) )
name( v );
else if ( ! strcmp( s, ":track" ) )
{
int i;
sscanf( v, "%X", &i );
Track *t = (Track*)Loggable::find( i );
assert( t );
t->add( this );
}
free( s );
}
free( sa );
timeline->redraw();
}
Ruler_Point ( )
{
}
public:
/* for loggable */
static Loggable *
create ( char **sa )
{
Ruler_Point *r = new Ruler_Point;
r->set( sa );
return (Loggable *)r;
}
Ruler_Point ( nframes_t when, const char *name )
{
_r->offset = when;
_label = strdup( name );
log_create();
}
Ruler_Point ( const Ruler_Point &rhs )
{
_r->offset = rhs._r->offset;
_label = strdup( rhs._label );
}
Track_Widget *clone ( const Track_Widget *r )
{
return new Ruler_Point( *(Ruler_Point*)r );
}
~Ruler_Point ( )
{
if ( _label ) free( _label );
log_destroy();
}
int
handle ( int m )
{
int r = Track_Widget::handle( m );
if ( m == FL_RELEASE )
{
_track->sort();
timeline->redraw();
}
return r;
}
};

43
Timeline/Ruler_Track.H Normal file
View File

@ -0,0 +1,43 @@
/*******************************************************************************/
/* 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 "Ruler_Point.H"
#include "Timeline.H"
class Ruler_Track : public Track
{
public:
Ruler_Track ( int X, int Y, int W, int H ) : Track ( X, Y, W, H )
{
box( FL_UP_BOX );
}
void
draw ( void )
{
Track::draw();
timeline->draw_measure_BBT( x(), y(), w(), h(), FL_WHITE );
}
};

View File

@ -24,6 +24,8 @@
#include "Control_Track.H"
#include <FL/Fl_Scrollbar.H>
#include "Ruler_Track.H"
// #include <FL/Fl_Image.H>
// #include <FL/Fl_RGB_Image.H> // needed for alpha blending
@ -140,6 +142,22 @@ Timeline::Timeline ( int X, int Y, int W, int H, const char* L ) : Fl_Overlay_Wi
}
{
Ruler_Track *o = new Ruler_Track( 0, 24, 800, 24 );
o->color( FL_GREEN );
/* o->add( new Time_Point( 0, 4, 4 ) ); */
/* o->add( new Time_Point( 345344, 6, 8 ) ); */
o->label( "Ruler" );
o->align( FL_ALIGN_LEFT );
ruler_track = o;
// o->end();
}
o->size( o->w(), o->child( 0 )->h() * o->children() );
rulers = o;
o->end();
@ -218,6 +236,36 @@ Timeline::beats_per_minute ( nframes_t when, float bpm )
tempo_track->add( new Tempo_Point( when, bpm ) );
}
#if 0
struct BBT
{
int bar, beat, tick;
BBT ( int bar, int beat, int tick ) : bar( bar ), beat( beat ), tick( tick )
{
}
};
/** returns the BBT value for timestamp /when/ by examining the tempo/time maps */
BBT
Timeline::bbt ( nframes_t when )
{
Tempo_Track *tempo = (Tempo_Track*)rulers->child( 0 );
BBT bbt;
for ( list <Track_Widget *>::const_iterator i = tempo.widgets.begin();
i != tempo.widgets.end(); ++i )
{
Tempo_Point *p = *i;
}
};
#endif
/** return the absolute pixel of the nearest measure line to /x/ */
int
Timeline::nearest_line ( int ix )
@ -240,7 +288,7 @@ Timeline::nearest_line ( int ix )
searched both the time and tempo lists once for every horiontal
pixel and performs a number of calculations--this is slow. */
void
Timeline::draw_measure_lines ( int X, int Y, int W, int H, Fl_Color color )
Timeline::draw_measure ( int X, int Y, int W, int H, Fl_Color color, bool BBT )
{
if ( ! _enable_measure_lines )
return;
@ -248,14 +296,15 @@ Timeline::draw_measure_lines ( int X, int Y, int W, int H, Fl_Color color )
// fl_line_style( FL_DASH, 2 );
fl_line_style( FL_DASH, 0 );
Fl_Color beat = fl_color_average( FL_BLACK, color, 0.65f );
Fl_Color bar = fl_color_average( FL_RED, color, 0.65f );
Fl_Color beat = fl_color_average( FL_BLACK, color, 0.65f );
Fl_Color bar = fl_color_average( FL_RED, color, 0.65f );
int measure;
for ( int x = X; x < X + W; ++x )
{
measure = ts_to_x( (double)(_sample_rate * 60) / beats_per_minute( x_to_ts( x - Track_Header::width() ) + xoffset ));
measure = ts_to_x( (double)(_sample_rate * 60) / beats_per_minute( x_to_ts( x - Track_Header::width() ) + xoffset ) );
const int abs_x = ts_to_x( xoffset ) + x - Track_Header::width();
@ -268,6 +317,41 @@ Timeline::draw_measure_lines ( int X, int Y, int W, int H, Fl_Color color )
if ( measure * bpb < 8 )
break;
if ( BBT )
{
fl_font( FL_HELVETICA, 14 );
fl_color( fl_lighter( color ) );
char pat[40];
const nframes_t ts = x_to_ts( abs_x );
// if ( draw_hms )
{
const double seconds = (double)ts / _sample_rate;
int S = (int)seconds;
int M = S / 60; S -= M * 60;
int H = M / 60; M -= H * 60;
snprintf( pat, sizeof( pat ), "%d:%d:%d", H, M, S );
}
// else if ( draw_bbt )
{
/* const int bar = */
/* const int beat; */
/* const int tick = 0; */
/* snprintf( pat, sizeof( pat ), "%d:%d:%d", bar, beat, tick ); */
}
fl_draw( pat, x, Y + 14 );
}
fl_color( bar );
}
else
@ -287,6 +371,18 @@ Timeline::draw_measure_lines ( int X, int Y, int W, int H, Fl_Color color )
}
void
Timeline::draw_measure_lines ( int X, int Y, int W, int H, Fl_Color color )
{
draw_measure( X, Y, W, H, color, false );
}
/** just like draw mesure lines except that it also draws the BBT values. */
void
Timeline::draw_measure_BBT ( int X, int Y, int W, int H, Fl_Color color )
{
draw_measure( X, Y, W, H, color, true );
}
void
Timeline::xposition ( int X )

View File

@ -44,6 +44,7 @@ extern Timeline *timeline;
class Tempo_Track;
class Time_Track;
class Ruler_Track;
#include <list>
using std::list;
@ -98,14 +99,15 @@ class Timeline : public Fl_Overlay_Window, public RWLock
SNAP_TO_BEAT
} snap_to;
Fl_Scroll *scroll;
Fl_Pack *tracks;
Fl_Pack *rulers;
Scalebar *hscroll;
Fl_Scroll *scroll;
Fl_Pack *tracks;
Fl_Pack *rulers;
Scalebar *hscroll;
Fl_Scrollbar *vscroll;
Tempo_Track *tempo_track;
Time_Track *time_track;
Time_Track *time_track;
Ruler_Track *ruler_track;
static void cb_scroll ( Fl_Widget *w, void *v );
@ -136,6 +138,9 @@ public:
int nearest_line ( int ix );
void draw_measure_lines ( int X, int Y, int W, int H, Fl_Color color );
void draw_measure_BBT ( int X, int Y, int W, int H, Fl_Color color );
void draw_measure ( int X, int Y, int W, int H, Fl_Color color, bool BBT );
void xposition ( int X );
void yposition ( int Y );
void draw_playhead ( void );

View File

@ -31,8 +31,8 @@
#include <assert.h>
#include <list>
#include <queue>
using namespace std;
// using namespace std;
class Region;
class Track_Widget;
@ -51,7 +51,7 @@ class Track : public Fl_Widget, public Loggable
protected:
list <Track_Widget *> _widgets;
std::list <Track_Widget *> _widgets;
Track_Widget *event_widget ( void );
virtual const char *class_name ( void ) { return "Track"; }
@ -103,7 +103,7 @@ public:
void remove_selected ( void );
const list <Track_Widget *> widgets ( void ) const { return _widgets; }
const std::list <Track_Widget *> widgets ( void ) const { return _widgets; }
void queue_delete ( Track_Widget *r )
{