ardour
verbose_cursor.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2000-2011 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 */
19 
20 #include <string>
21 #include <gtkmm/enums.h>
22 #include "pbd/stacktrace.h"
23 #include "ardour/profile.h"
24 
25 #include "canvas/debug.h"
26 #include "canvas/scroll_group.h"
27 #include "canvas/tracking_text.h"
28 
29 #include "ardour_ui.h"
30 #include "audio_clock.h"
31 #include "editor.h"
32 #include "editor_drag.h"
33 #include "global_signals.h"
34 #include "main_clock.h"
35 #include "verbose_cursor.h"
36 
37 #include "i18n.h"
38 
39 using namespace std;
40 using namespace ARDOUR;
41 
43  : _editor (editor)
44 {
45  _canvas_item = new ArdourCanvas::TrackingText (_editor->get_noscroll_group());
46  CANVAS_DEBUG_NAME (_canvas_item, "verbose canvas cursor");
47  _canvas_item->set_font_description (Pango::FontDescription (ARDOUR_UI::config()->get_LargerBoldFont()));
48  color_handler ();
49 
50  ARDOUR_UI_UTILS::ColorsChanged.connect (sigc::mem_fun (*this, &VerboseCursor::color_handler));
51 }
52 
53 void
55 {
56  _canvas_item->set_color (ARDOUR_UI::config()->color_mod ("verbose canvas cursor", "verbose canvas cursor"));
57 }
58 
59 ArdourCanvas::Item *
61 {
62  return _canvas_item;
63 }
64 
67 void
68 VerboseCursor::set (string const & text)
69 {
70  _canvas_item->set (text);
71 }
72 
73 void
75 {
76  _canvas_item->show_and_track (true, true);
77  _canvas_item->parent()->raise_to_top ();
78 }
79 
80 void
82 {
83  _canvas_item->hide ();
84  _canvas_item->parent()->lower_to_bottom ();
85  /* reset back to a sensible default for the next time we display the VC */
86  _canvas_item->set_offset (ArdourCanvas::Duple (10, 10));
87 }
88 
89 void
90 VerboseCursor::set_offset (ArdourCanvas::Duple const & d)
91 {
92  _canvas_item->set_offset (d);
93 }
94 
95 void
97 {
98  char buf[128];
99  Timecode::Time timecode;
100  Timecode::BBT_Time bbt;
101 
102  if (_editor->_session == 0) {
103  return;
104  }
105 
106  /* Take clock mode from the primary clock */
107 
109 
110  switch (m) {
111  case AudioClock::BBT:
112  _editor->_session->bbt_time (frame, bbt);
113  snprintf (buf, sizeof (buf), "%02" PRIu32 "|%02" PRIu32 "|%02" PRIu32, bbt.bars, bbt.beats, bbt.ticks);
114  break;
115 
117  _editor->_session->timecode_time (frame, timecode);
118  snprintf (buf, sizeof (buf), "%s", Timecode::timecode_format_time (timecode).c_str());
119  break;
120 
121  case AudioClock::MinSec:
122  AudioClock::print_minsec (frame, buf, sizeof (buf), _editor->_session->frame_rate());
123  break;
124 
125  default:
126  snprintf (buf, sizeof(buf), "%" PRIi64, frame);
127  break;
128  }
129 
130  _canvas_item->set (buf);
131 }
132 
133 void
135 {
136  char buf[128];
137  Timecode::Time timecode;
138  Timecode::BBT_Time sbbt;
139  Timecode::BBT_Time ebbt;
140  Meter meter_at_start (_editor->_session->tempo_map().meter_at(start));
141 
142  if (_editor->_session == 0) {
143  return;
144  }
145 
147 
148  switch (m) {
149  case AudioClock::BBT:
150  {
151  _editor->_session->bbt_time (start, sbbt);
152  _editor->_session->bbt_time (end, ebbt);
153 
154  /* subtract */
155  /* XXX this computation won't work well if the
156  user makes a selection that spans any meter changes.
157  */
158 
159  /* use signed integers for the working values so that
160  we can underflow.
161  */
162 
163  int ticks = ebbt.ticks;
164  int beats = ebbt.beats;
165  int bars = ebbt.bars;
166 
167  ticks -= sbbt.ticks;
168  if (ticks < 0) {
169  ticks += int (Timecode::BBT_Time::ticks_per_beat);
170  --beats;
171  }
172 
173  beats -= sbbt.beats;
174  if (beats < 0) {
175  beats += int (meter_at_start.divisions_per_bar());
176  --bars;
177  }
178 
179  bars -= sbbt.bars;
180 
181  snprintf (buf, sizeof (buf), "%02" PRIu32 "|%02" PRIu32 "|%02" PRIu32, bars, beats, ticks);
182  break;
183  }
184 
186  _editor->_session->timecode_duration (end - start, timecode);
187  snprintf (buf, sizeof (buf), "%s", Timecode::timecode_format_time (timecode).c_str());
188  break;
189 
190  case AudioClock::MinSec:
191  AudioClock::print_minsec (end - start, buf, sizeof (buf), _editor->_session->frame_rate());
192  break;
193 
194  default:
195  snprintf (buf, sizeof(buf), "%" PRIi64, end - start);
196  break;
197  }
198 
199  _canvas_item->set (buf);
200 }
201 
202 bool
204 {
205  return _canvas_item->visible();
206 }
void timecode_duration(framecnt_t, Timecode::Time &) const
void set_offset(ArdourCanvas::Duple const &)
MainClock * primary_clock
Definition: ardour_ui.h:229
static ARDOUR_UI * instance()
Definition: ardour_ui.h:187
TempoMap & tempo_map()
Definition: session.h:596
Definition: Beats.hpp:239
LIBARDOUR_API PBD::PropertyDescriptor< framepos_t > start
Definition: region.cc:63
framecnt_t frame_rate() const
Definition: session.h:365
ArdourCanvas::TrackingText * _canvas_item
const Meter & meter_at(framepos_t) const
Definition: tempo.cc:1652
Mode mode() const
Definition: audio_clock.h:56
ArdourCanvas::Container * get_noscroll_group() const
Definition: editor.h:508
VerboseCursor(Editor *)
Definition: amp.h:29
Editor * _editor
void set_duration(framepos_t, framepos_t)
int64_t framepos_t
Definition: types.h:66
bool visible() const
void set_time(framepos_t)
Definition: editor.h:134
static UIConfiguration * config()
Definition: ardour_ui.h:188
sigc::signal< void > ColorsChanged
void timecode_time(Timecode::Time &)
void color_handler()
void set(std::string const &)
ArdourCanvas::Item * canvas_item() const
void bbt_time(framepos_t when, Timecode::BBT_Time &)
Definition: session_time.cc:47
ARDOUR::Session * _session
static void print_minsec(framepos_t, char *buf, size_t bufsize, float frame_rate)