summaryrefslogtreecommitdiff
path: root/gtk2_ardour
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2011-11-21 16:34:02 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2011-11-21 16:34:02 +0000
commitaef0319864964493def21510fa4a943bf26b8792 (patch)
treef99775b8282aaa6ef0edcf20e586f0532ead79aa /gtk2_ardour
parentd59359b78ffd74ba2679ce27de434de73bcba0b4 (diff)
fix (?) all aspects of audio clock editing
git-svn-id: svn://localhost/ardour2/branches/3.0@10730 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'gtk2_ardour')
-rw-r--r--gtk2_ardour/audio_clock.cc133
1 files changed, 57 insertions, 76 deletions
diff --git a/gtk2_ardour/audio_clock.cc b/gtk2_ardour/audio_clock.cc
index 9423d3847f..2e7826ef6c 100644
--- a/gtk2_ardour/audio_clock.cc
+++ b/gtk2_ardour/audio_clock.cc
@@ -336,30 +336,36 @@ AudioClock::render (cairo_t* cr)
if (!insert_map.empty()) {
- Pango::Rectangle cursor;
-
- if (input_string.empty()) {
- /* nothing entered yet, put cursor at the end
- of string
- */
- cursor = _layout->get_cursor_strong_pos (edit_string.length() - 1);
- } else {
- cursor = _layout->get_cursor_strong_pos (insert_map[input_string.length()-1]);
- }
-
- cairo_set_source_rgba (cr, cursor_r, cursor_g, cursor_b, cursor_a);
- if (!_fixed_width) {
- cairo_rectangle (cr,
- layout_x_offset + cursor.get_x()/PANGO_SCALE + cursor_width,
- 0,
- 2.0, cursor.get_height()/PANGO_SCALE);
+
+ if (input_string.length() < insert_map.size()) {
+ Pango::Rectangle cursor;
+
+ if (input_string.empty()) {
+ /* nothing entered yet, put cursor at the end
+ of string
+ */
+ cursor = _layout->get_cursor_strong_pos (edit_string.length() - 1);
+ } else {
+ cursor = _layout->get_cursor_strong_pos (insert_map[input_string.length()]);
+ }
+
+ cairo_set_source_rgba (cr, cursor_r, cursor_g, cursor_b, cursor_a);
+ if (!_fixed_width) {
+ cairo_rectangle (cr,
+ layout_x_offset + cursor.get_x()/PANGO_SCALE + cursor_width,
+ 0,
+ 2.0, cursor.get_height()/PANGO_SCALE);
+ } else {
+ cairo_rectangle (cr,
+ layout_x_offset + cursor.get_x()/PANGO_SCALE + cursor_width,
+ (upper_height - layout_height)/2.0,
+ 2.0, cursor.get_height()/PANGO_SCALE);
+ }
+ cairo_fill (cr);
} else {
- cairo_rectangle (cr,
- layout_x_offset + cursor.get_x()/PANGO_SCALE + cursor_width,
- (upper_height - layout_height)/2.0,
- 2.0, cursor.get_height()/PANGO_SCALE);
+ /* we've entered all possible digits, no cursor */
}
- cairo_fill (cr);
+
} else {
if (input_string.empty()) {
cairo_set_source_rgba (cr, cursor_r, cursor_g, cursor_b, cursor_a);
@@ -736,24 +742,18 @@ AudioClock::parse_as_bbt_distance (const std::string& str)
framecnt_t
AudioClock::parse_as_distance (const std::string& instr)
{
- string str = instr;
-
- /* the input string is in reverse order */
-
- std::reverse (str.begin(), str.end());
-
switch (_mode) {
case Timecode:
- return parse_as_timecode_distance (str);
+ return parse_as_timecode_distance (instr);
break;
case Frames:
- return parse_as_frames_distance (str);
+ return parse_as_frames_distance (instr);
break;
case BBT:
- return parse_as_bbt_distance (str);
+ return parse_as_bbt_distance (instr);
break;
case MinSec:
- return parse_as_minsec_distance (str);
+ return parse_as_minsec_distance (instr);
break;
}
return 0;
@@ -1197,10 +1197,9 @@ AudioClock::on_key_press_event (GdkEventKey* ev)
case GDK_Delete:
case GDK_BackSpace:
if (!input_string.empty()) {
- /* delete the last key entered, which is at the FRONT
- of the input_string
+ /* delete the last key entered
*/
- input_string = input_string.substr (1, input_string.length() - 1);
+ input_string = input_string.substr (0, input_string.length() - 1);
}
goto use_input_string;
@@ -1213,14 +1212,11 @@ AudioClock::on_key_press_event (GdkEventKey* ev)
return true;
}
- input_string.insert (input_string.begin(), new_char);
+ input_string.push_back (new_char);
use_input_string:
- string::reverse_iterator ri;
- vector<int> insert_at;
int highlight_length = 0;
- char buf[32];
framepos_t pos;
/* merge with pre-edit-string into edit string */
@@ -1234,52 +1230,37 @@ AudioClock::on_key_press_event (GdkEventKey* ev)
edit_string = edit_string.substr (0, edit_string.length() - 1);
}
if (!edit_string.empty()) {
+ char buf[32];
sscanf (edit_string.c_str(), "%" PRId64, &pos);
snprintf (buf, sizeof (buf), " %10" PRId64, pos);
edit_string = buf;
}
+ /* highlight the whole thing */
highlight_length = edit_string.length();
break;
default:
- if (!input_string.empty()) {
- edit_string = pre_edit_string;
-
- /* backup through the original string, till we have
- * enough digits locations to put all the digits from
- * the input string.
- */
-
- for (ri = edit_string.rbegin(); ri != edit_string.rend(); ++ri) {
- if (isdigit (*ri)) {
- insert_at.push_back (edit_string.length() - (ri - edit_string.rbegin()) - 1);
- if (insert_at.size() == input_string.length()) {
- break;
- }
- }
- }
-
- if (insert_at.size() != input_string.length()) {
- error << "something went wrong, insert at = " << insert_at.size() << " is.len() = " << input_string.length() << endmsg;
- } else {
- for (int i = input_string.length() - 1; i >= 0; --i) {
- edit_string[insert_at[i]] = input_string[i];
- }
-
- highlight_length = edit_string.length() - insert_at.back();
- }
- } else {
- edit_string = pre_edit_string;
+ edit_string = pre_edit_string;
+
+ if (input_string.empty()) {
highlight_length = 0;
+ } else {
+ // for (int i = input_string.length() - 1; i >= 0; --i) {
+ string::size_type target;
+ for (string::size_type i = 0; i < input_string.length(); ++i) {
+ target = insert_map[input_string.length() - 1 - i];
+ edit_string[target] = input_string[i];
+ }
+ /* highlight from end to wherever the last character was added */
+ highlight_length = edit_string.length() - insert_map[input_string.length()-1];
}
break;
}
- if (edit_string != _layout->get_text()) {
- show_edit_status (highlight_length);
- _layout->set_text (edit_string);
- queue_draw ();
- }
+
+ show_edit_status (highlight_length);
+ _layout->set_text (edit_string);
+ queue_draw ();
return true;
}
@@ -1874,14 +1855,14 @@ AudioClock::set_mode (Mode m)
switch (_mode) {
case Timecode:
mode_based_info_ratio = 0.5;
+ insert_map.push_back (11);
insert_map.push_back (10);
- insert_map.push_back (9);
+ insert_map.push_back (8);
insert_map.push_back (7);
- insert_map.push_back (6);
+ insert_map.push_back (5);
insert_map.push_back (4);
- insert_map.push_back (3);
+ insert_map.push_back (2);
insert_map.push_back (1);
- insert_map.push_back (0);
break;
case BBT: