Actually use tempo track for tempo data.

This commit is contained in:
Jonathan Moore Liles 2008-02-21 04:39:13 -06:00
parent 44904bc640
commit 045bb504c3
7 changed files with 151 additions and 67 deletions

View File

@ -5,7 +5,7 @@ CXXFLAGS=-ggdb -Wall -O0
LIBS=-lsndfile `fltk-config --ldflags`
# CXXFLAGS=`fltk-config -cxxflags`
SRCS= Clip.C Waveform.C Region.C Peaks.C main.C Track.C
SRCS= Clip.C Waveform.C Region.C Peaks.C main.C Track.C Timeline.C
OBJS=$(SRCS:.C=.o)

View File

@ -33,6 +33,7 @@ class Tempo_Point : public Track_Point
snprintf( _label, 40, "%.1f", _tempo );
}
public:
Tempo_Point ( nframes_t when, float bpm )
@ -46,4 +47,21 @@ public:
~Tempo_Point ( )
{ if ( _label ) delete[] _label; }
float tempo ( void ) const { return _tempo; }
void tempo ( float v ) { _tempo = v; }
int
handle ( int m )
{
int r = Track_Widget::handle( m );
if ( m == FL_RELEASE )
{
_track->sort();
timeline.tracks->redraw();
}
return r;
}
};

60
Tempo_Track.H Normal file
View File

@ -0,0 +1,60 @@
/*******************************************************************************/
/* 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 "Tempo_Point.H"
#include <list>
using std::list;
class Tempo_Track : public Track
{
public:
Tempo_Track ( int X, int Y, int W, int H ) : Track ( X, Y, W, H )
{
}
float
beats_per_minute ( nframes_t when )
{
// sort();
for ( list <Track_Widget *>::const_reverse_iterator i = _widgets.rbegin();
i != _widgets.rend(); i++ )
{
if ( (*i)->offset() < when )
return ((Tempo_Point*)(*i))->tempo();
}
return 120.0;
}
void
beats_per_minute ( nframes_t when, float bpm )
{
add( new Tempo_Point( when, bpm ) );
}
};

57
Timeline.C Normal file
View File

@ -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. */
/*******************************************************************************/
#include "Timeline.H"
#include "Tempo_Track.H"
float
Timeline::beats_per_minute ( nframes_t when ) const
{
return tempo_track->beats_per_minute( when );
}
void
Timeline::beats_per_minute ( nframes_t when, float bpm )
{
tempo_track->add( new Tempo_Point( when, bpm ) );
}
/* draw appropriate measure lines inside the given bounding box */
void
Timeline::draw_measure_lines ( int X, int Y, int W, int H, Fl_Color color )
{
fl_line_style( FL_DASH, 2 );
fl_color( fl_color_average( FL_BLACK, color, 0.65f ) );
// int measure = ts_to_x( sample_rate * 60 / beats_per_minute() );
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 ) + xoffset ));
if ( 0 == (ts_to_x( xoffset ) + x) % measure )
fl_line( x, Y, x, Y + H );
}
fl_line_style( FL_SOLID, 0 );
}

View File

@ -34,6 +34,10 @@ class Timeline;
extern Timeline timeline;
#include "Track.H"
// #include "Tempo_Track.H"
class Tempo_Track;
// #include "Tempo_Point.H"
// #include "Region.H"
@ -76,7 +80,7 @@ struct Timeline {
Fl_Pack *tracks;
Fl_Scrollbar *scrollbar;
Track *tempo_track;
Tempo_Track *tempo_track;
float fpp; /* frames per pixel */
// nframes_t fpp;
@ -103,63 +107,8 @@ struct Timeline {
return x * fpp;
}
float beats_per_minute ( nframes_t when ) const;
void beats_per_minute ( nframes_t when, float bpm );
void draw_measure_lines ( int X, int Y, int W, int H, Fl_Color color );
float
beats_per_minute ( void ) const
{
// TODO: this should check a tempo map.
return _beats_per_minute;
}
float
beats_per_minute ( nframes_t when ) const
{
for ( list <tempo_event>::const_reverse_iterator i = tempo_points.rbegin();
i != tempo_points.rend(); i++ )
{
if ( i->timestamp < when )
return i->beats_per_minute;
}
return _beats_per_minute;
}
void
beats_per_minute ( nframes_t when, float bpm )
{
// tempo_track->add( new Tempo_Point( when, bpm ) );
}
/* /\* return the offset of the closest measure line to /t/ *\/ */
/* nframes_t */
/* snap ( nframes t ) */
/* { */
/* } */
/* draw appropriate measure lines inside the given bounding box */
void
draw_measure_lines ( int X, int Y, int W, int H, Fl_Color color )
{
fl_line_style( FL_DASH, 2 );
fl_color( fl_color_average( FL_BLACK, color, 0.65f ) );
// int measure = ts_to_x( sample_rate * 60 / beats_per_minute() );
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 ) + xoffset ));
if ( 0 == (ts_to_x( xoffset ) + x) % measure )
fl_line( x, Y, x, Y + H );
}
fl_line_style( FL_SOLID, 0 );
}
};

View File

@ -21,6 +21,9 @@
#include "Track.H"
#include <algorithm>
using namespace std;
/* Base class for virtual widget on a track */
class Track_Widget
{

11
main.C
View File

@ -42,7 +42,7 @@
#include "Track.H"
#include "Audio_Track.H"
#include "Timeline.H"
#include "Tempo_Point.H"
#include "Tempo_Track.H"
#include "const.h"
@ -100,11 +100,6 @@ main ( int argc, char **argv )
timeline.length = 48000 * 60 * 2;
timeline.beats_per_minute( 0, 120 );
timeline.beats_per_minute( 48000, 250 );
timeline.beats_per_minute( 48000 * 4, 60 );
timeline.sample_rate = 44100;
timeline.tracks = new Fl_Pack( 0, 0, 800, 5000 );
@ -117,7 +112,7 @@ main ( int argc, char **argv )
// Fl_Group *pack = new Fl_Group( 0, 0, 5000, 600 );
{
Track *tempo_track = new Track( 100, 0, 800, 24 );
Tempo_Track *tempo_track = new Tempo_Track( 100, 0, 800, 24 );
tempo_track->label( "tempo map" );
tempo_track->add( new Tempo_Point( 0, 120 ) );
@ -125,6 +120,8 @@ main ( int argc, char **argv )
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 );