Add Track_Point class for track widgets with no meaningful length.

This commit is contained in:
Jonathan Moore Liles 2008-02-20 22:03:48 -06:00
parent 4a266bc86a
commit a1dd1192cc
2 changed files with 47 additions and 36 deletions

View File

@ -75,6 +75,10 @@ public:
virtual int w ( void ) const { return timeline.ts_to_x( _end - _start ); } virtual int w ( void ) const { return timeline.ts_to_x( _end - _start ); }
// int w ( void ) const { return timeline.ts_to_x( (_end - _start) - ( timeline.xoffset - _offset) ); } // int w ( void ) const { return timeline.ts_to_x( (_end - _start) - ( timeline.xoffset - _offset) ); }
int abs_x ( void ) const { return timeline.ts_to_x( timeline.xoffset ); }
int abs_w ( void ) const { return timeline.ts_to_x( _end - _start ); }
Fl_Color color ( void ) { return _color; } Fl_Color color ( void ) { return _color; }
Fl_Color box_color ( void ) { return _box_color; } Fl_Color box_color ( void ) { return _box_color; }
@ -218,26 +222,23 @@ public:
}; };
class Tempo_Point : public Track_Widget class Track_Point : public Track_Widget
{ {
float _tempo;
protected:
char *_label;
public: public:
/* Tempo_Point ( ) */
/* { */
/* _tempo = 120; */
/* } */
Tempo_Point ( nframes_t when, float bpm )
{
_tempo = bpm;
_offset = when;
}
int w ( void ) const { return 10; } int w ( void ) const { return 10; }
nframes_t length ( void ) const { return timeline.x_to_ts( w() ); } nframes_t length ( void ) const { return timeline.x_to_ts( w() ); }
Track_Point ( )
{
_label = NULL;
}
void void
draw ( int X, int Y, int W, int H ) draw ( int X, int Y, int W, int H )
{ {
@ -246,14 +247,34 @@ public:
Track_Widget::draw( x(), Y, w(), H ); Track_Widget::draw( x(), Y, w(), H );
draw_label( _label, FL_ALIGN_RIGHT );
char pat[40];
snprintf( pat, 40, "%.1f", _tempo );
draw_label( pat, FL_ALIGN_RIGHT );
} }
};
class Tempo_Point : public Track_Point
{
float _tempo;
void
_make_label ( void )
{
if ( ! _label )
_label = new char[40];
snprintf( _label, 40, "%.1f", _tempo );
}
public:
Tempo_Point ( nframes_t when, float bpm )
{
_tempo = bpm;
_offset = when;
_make_label();
}
~Tempo_Point ( )
{ if ( _label ) delete[] _label; }
}; };

10
main.C
View File

@ -36,19 +36,11 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
Fl_Color velocity_colors[128];
#include "Track.H" #include "Track.H"
#include "Timeline.H" #include "Timeline.H"
#include "const.h" #include "const.h"
void
init_colors ( void )
{
for ( int i = 128; i--; )
velocity_colors[i] = fl_rgb_color( 23, 255 - i * 2, 32 );
}
Timeline timeline; Timeline timeline;
@ -106,8 +98,6 @@ int
main ( int argc, char **argv ) main ( int argc, char **argv )
{ {
init_colors();
Fl_Double_Window *main_window = new Fl_Double_Window( 0, 0, 800, 600 ); Fl_Double_Window *main_window = new Fl_Double_Window( 0, 0, 800, 600 );
timeline.scroll = new Fl_Scroll( 0, 24, 800, 600 - (24 * 2) ); timeline.scroll = new Fl_Scroll( 0, 24, 800, 600 - (24 * 2) );