diff --git a/Scalebar.H b/Scalebar.H new file mode 100644 index 0000000..c49ba9b --- /dev/null +++ b/Scalebar.H @@ -0,0 +1,70 @@ + +/*******************************************************************************/ +/* 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 +#include +#include + +#include + +class Scalebar : public Fl_Scrollbar +{ + double _zoom; + +public: + + Scalebar ( int X, int Y, int W, int H ) : Fl_Scrollbar ( X, Y, W, H ) + { + _zoom = 1.0f; + + step( 1 ); + } + + double zoom ( void ) const { return _zoom; } + double value ( void ) const { return Fl_Slider::value(); } + + int + handle ( int m ) + { + switch ( m ) + { + case FL_MOUSEWHEEL: + { + int d = Fl::event_dy(); + + if ( d < 0 ) + while ( d++ ) + _zoom /= 2; + else + while ( d-- ) + _zoom *= 2; + + do_callback(); + + slider_size( w() / maximum() ); + + return 1; + } + default: + return Fl_Scrollbar::handle( m ); + } + } +}; diff --git a/Timeline.H b/Timeline.H index f94552a..1898136 100644 --- a/Timeline.H +++ b/Timeline.H @@ -76,6 +76,8 @@ struct Timeline { nframes_t xoffset; + nframes_t length; + int _beats_per_bar; float _beats_per_minute; diff --git a/main.C b/main.C index 6ef9348..24e4e5d 100644 --- a/main.C +++ b/main.C @@ -22,11 +22,14 @@ #include #include #include -#include +// #include #include #include #include + +#include "Scalebar.H" + // #include "Waveform.H" #include "Region.H" @@ -45,34 +48,22 @@ Timeline timeline; -void -cb_zoom ( Fl_Widget *w, void *v ) -{ - timeline.fpp = ((Fl_Slider*)w)->value(); - - -/* for ( int i = timeline.tracks->children(); i-- ; ) */ -/* { */ -/* Fl_Group *track = (Fl_Group*)timeline.tracks->child( i ); */ -/* for ( int j = track->children(); j-- ; ) */ -/* ((Region*)(track->child( j )))->resize(); */ -/* } */ - - - timeline.scroll->redraw(); - - if ( timeline.fpp < FRAMES_PER_PEAK ) - w->selection_color( FL_RED ); - else - w->selection_color( FL_GRAY ); - - printf( "%f\n", timeline.fpp ); -} void cb_scroll ( Fl_Widget *w, void *v ) { - timeline.xoffset = timeline.x_to_ts( ((Fl_Slider*)w)->value() ); + Scalebar *sb = (Scalebar*)w; + + timeline.fpp = sb->zoom() * 256; + timeline.fpp = max( min( timeline.fpp, 4096.0f ), (float)2 ); + + int maxx = timeline.ts_to_x( timeline.length ); + sb->range( 0, maxx ); +// sb->value( sb->value(), maxx +// 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(); @@ -101,10 +92,11 @@ main ( int argc, char **argv ) 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, 0, 800, 600 - 24 ); timeline.scroll->type( Fl_Scroll::VERTICAL ); timeline.fpp = 256; timeline._beats_per_minute = 120; + timeline.length = 48000 * 60 * 2; timeline.beats_per_minute( 0, 120 ); @@ -181,17 +173,9 @@ main ( int argc, char **argv ) timeline.tracks->end(); timeline.scroll->end(); - Fl_Slider *zoom_slider = new Fl_Slider( 0, 0, 800, 24 ); - zoom_slider->type( FL_HOR_SLIDER ); - zoom_slider->callback( cb_zoom, 0 ); - zoom_slider->range( 2, 4096 ); - zoom_slider->step( 1 ); - zoom_slider->value( 256 ); - - timeline.scrollbar = new Fl_Scrollbar( 0, 600 - 24, 800, 24 ); + timeline.scrollbar = new Scalebar( 0, 600 - 24, 800, 24 ); timeline.scrollbar->range( 0, 48000 * 2 ); timeline.scrollbar->type( 1 ); - timeline.scrollbar->step( 1 ); timeline.scrollbar->callback( cb_scroll, 0 ); main_window->end();