Fly my pretties!
[ardour.git] / gtk2_ardour / audio_clock.h
1 /*
2     Copyright (C) 1999 Paul Davis 
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18     $Id$
19 */
20
21 #ifndef __audio_clock_h__
22 #define __audio_clock_h__
23
24 #include <gtkmm.h>
25 #include <ardour/ardour.h>
26
27 namespace ARDOUR {
28         class Session;
29 };
30
31 class AudioClock : public Gtk::HBox
32 {
33   public:
34         enum Mode {
35                 SMPTE,
36                 BBT,
37                 MinSec,
38                 Frames,
39                 Off,
40         };
41         
42         AudioClock (const string& name, bool editable, bool is_duration = false, bool with_tempo_meter = false);
43
44         Mode mode() const { return _mode; }
45         
46         void set (jack_nframes_t, bool force = false);
47         void set_mode (Mode);
48
49         jack_nframes_t current_time (jack_nframes_t position = 0) const;
50         jack_nframes_t current_duration (jack_nframes_t position = 0) const;
51         void set_session (ARDOUR::Session *s);
52
53         sigc::signal<void> ValueChanged;
54
55   private:
56         ARDOUR::Session  *session;
57         Mode             _mode;
58         uint32_t      key_entry_state;
59         bool              is_duration;
60         bool              editable;
61
62         Gtk::Menu  *ops_menu;
63
64         Gtk::HBox   smpte_packer_hbox;
65         Gtk::HBox   smpte_packer;
66
67         Gtk::HBox   minsec_packer_hbox;
68         Gtk::HBox   minsec_packer;
69
70         Gtk::HBox   bbt_packer_hbox;
71         Gtk::HBox   bbt_packer;
72
73         Gtk::HBox   frames_packer_hbox;
74        
75         enum Field {
76                 SMPTE_Hours,
77                 SMPTE_Minutes,
78                 SMPTE_Seconds,
79                 SMPTE_Frames,
80                 MS_Hours,
81                 MS_Minutes,
82                 MS_Seconds,
83                 Bars,
84                 Beats, 
85                 Ticks,
86                 AudioFrames,
87         };
88
89         Gtk::EventBox  audio_frames_ebox;
90         Gtk::Label     audio_frames_label;
91
92         Gtk::EventBox  hours_ebox;
93         Gtk::EventBox  minutes_ebox;
94         Gtk::EventBox  seconds_ebox;
95         Gtk::EventBox  frames_ebox;
96
97         Gtk::EventBox  ms_hours_ebox;
98         Gtk::EventBox  ms_minutes_ebox;
99         Gtk::EventBox  ms_seconds_ebox;
100
101         Gtk::EventBox  bars_ebox;
102         Gtk::EventBox  beats_ebox;
103         Gtk::EventBox  ticks_ebox;
104
105         Gtk::Label  hours_label;
106         Gtk::Label  minutes_label;
107         Gtk::Label  seconds_label;
108         Gtk::Label  frames_label;
109         Gtk::Label  colon1, colon2, colon3;
110
111         Gtk::Label  ms_hours_label;
112         Gtk::Label  ms_minutes_label;
113         Gtk::Label  ms_seconds_label;
114         Gtk::Label  colon4, colon5;
115
116         Gtk::Label  bars_label;
117         Gtk::Label  beats_label;
118         Gtk::Label  ticks_label;
119         Gtk::Label  b1;
120         Gtk::Label  b2;
121
122         Gtk::Label*  tempo_label;
123         Gtk::Label*  meter_label;
124
125         Gtk::VBox   tempo_meter_box;
126
127         Gtk::EventBox  clock_base;
128         Gtk::Frame     clock_frame;
129
130         jack_nframes_t last_when;
131
132         long last_hrs;
133         long last_mins;
134         long last_secs;
135         long last_frames;
136         bool last_negative;
137
138         long  ms_last_hrs;
139         long  ms_last_mins;
140         float ms_last_secs;
141
142         bool dragging;
143         double drag_start_y;
144         double drag_y;
145         double drag_accum;
146
147         void realize_impl ();
148         
149         gint field_motion_notify_event (GdkEventMotion *ev, Field);
150         gint field_button_press_event (GdkEventButton *ev, Field);
151         gint field_button_release_event (GdkEventButton *ev, Field);
152         gint field_key_release_event (GdkEventKey *, Field);
153         gint field_focus_in_event (GdkEventFocus *, Field);
154         gint field_focus_out_event (GdkEventFocus *, Field);
155
156         void set_smpte (jack_nframes_t, bool);
157         void set_bbt (jack_nframes_t, bool);
158         void set_minsec (jack_nframes_t, bool);
159         void set_frames (jack_nframes_t, bool);
160
161         jack_nframes_t get_frames (Field,jack_nframes_t pos = 0,int dir=1);
162         
163         void smpte_sanitize_display();
164         jack_nframes_t smpte_frame_from_display () const;
165         jack_nframes_t bbt_frame_from_display (jack_nframes_t) const;
166         jack_nframes_t bbt_frame_duration_from_display (jack_nframes_t) const;
167         jack_nframes_t minsec_frame_from_display () const;
168         jack_nframes_t audio_frame_from_display () const;
169
170         void build_ops_menu ();
171         void setup_events ();
172
173         static const uint32_t field_length[(int)AudioFrames+1];
174 };
175
176 #endif /* __audio_clock_h__ */