[ardour-dev] rulers clean/fix
nick mainsbridge
beatroot at optushome.com.au
Fri Apr 16 11:07:44 PDT 2004
hi,
here are a couple of ruler-fixing patches.
less lines of code is good, right?
:)
--
nick mainsbridge <beatroot at optushome.com.au>
-------------- next part --------------
--- /home/nick/ardour/gtk_ardour/editor_rulers.cc Wed Apr 7 13:49:31 2004
+++ editor_rulers.cc Sat Apr 17 03:50:27 2004
@@ -824,27 +824,19 @@
if (lower > (spacer = (jack_nframes_t)(128 * Editor::get_current_zoom ()))) {
lower = lower - spacer;
} else {
- upper = upper + spacer - lower;
- lower = 0;
+ upper = upper + spacer - lower;
+ lower = 0;
}
range = upper - lower;
- if (range < session->frames_per_smpte_frame()) {
+ if (range <= (fr / 10)) { /* 0-0.1 second */
if ((int)session->smpte_frames_per_second == session->smpte_frames_per_second) {
- mark_interval = (fr / (2 * (int)session->smpte_frames_per_second));
+ mark_interval = (fr / (10 * (int)session->smpte_frames_per_second));
} else {
- mark_interval = (jack_nframes_t)(fr / (2 * session->smpte_frames_per_second));
+ mark_interval = (jack_nframes_t)(fr / (10 * session->smpte_frames_per_second));
}
mark_modulo = 10;
show_bits = true;
- } else if (range <= (fr / 10)) { /* 0-0.1 second */
- if ((int)session->smpte_frames_per_second == session->smpte_frames_per_second) {
- mark_interval = fr / (int)session->smpte_frames_per_second;/* show single frames */
- } else {
- mark_interval = (jack_nframes_t)(fr / session->smpte_frames_per_second);/* show single frames */
- }
- mark_modulo = 1;
- show_frames = true;
} else if (range <= (fr / 4)) { /* 0-0.250 second */
if ((int)session->smpte_frames_per_second == session->smpte_frames_per_second) {
mark_interval = fr / (int)session->smpte_frames_per_second;/* show single frames */
@@ -864,16 +856,18 @@
mark_modulo = (gint)(session->smpte_frames_per_second / 2);
if (session->smpte_frames_per_second == 24) {
if ((int)session->smpte_frames_per_second == session->smpte_frames_per_second) {
- mark_interval = 4 * (fr / (int)session->smpte_frames_per_second);/* show single frames */
+ mark_interval = 4 * (fr / (int)session->smpte_frames_per_second);/* show four frames */
} else {
mark_interval = (jack_nframes_t)(4 * fr / session->smpte_frames_per_second);/* show 4 frames */
}
+ skip_factor = 4;
} else {
if ((int)session->smpte_frames_per_second == session->smpte_frames_per_second) {
- mark_interval = 5 * (fr / (int)session->smpte_frames_per_second);/* show single frames */
+ mark_interval = 5 * (fr / (int)session->smpte_frames_per_second);/* show five frames */
} else {
mark_interval = (jack_nframes_t)(5 * fr / session->smpte_frames_per_second);/* show 5 frames */
}
+ skip_factor = 5;
}
show_frames = true;
} else if (range <= 8 * fr) { /* 2-5 seconds */
@@ -884,27 +878,19 @@
} else {
mark_interval = (jack_nframes_t)(4 * fr / session->smpte_frames_per_second);/* show 4 frames */
}
+ skip_factor = 4;
} else {
if ((int)session->smpte_frames_per_second == session->smpte_frames_per_second) {
mark_interval = 5 * (fr / (int)session->smpte_frames_per_second);/* show single frames */
} else {
mark_interval = (jack_nframes_t)(5 * fr / session->smpte_frames_per_second);/* show 5 frames */
}
+ skip_factor = 5;
}
show_frames = true;
- } else if (range <= 16 * fr) { /* 8-16 seconds */
- mark_interval = fr; /* show seconds */
- show_seconds = true;
- skip_factor = 1;
} else if (range <= 30 * fr) { /* 10-30 seconds */
- mark_interval = fr; /* show 2 seconds */
- show_seconds = true;
- skip_factor = 1;
- } else if (range <= 60 * fr) { /* 30-60 seconds */
- mark_interval = 5 * fr; /* show 5 seconds */
+ mark_interval = fr; /* show seconds */
show_seconds = true;
- mark_modulo = 3;
- skip_factor = 5;
} else if (range <= 2 * 60 * fr) { /* 1-2 minutes */
mark_interval = 5 * fr; /* show 5 seconds */
show_seconds = true;
@@ -923,7 +909,6 @@
} else if (range <= 30 * 60 * fr) { /* 10-30 minutes */
mark_interval = 60 * fr; /* show 1 minute */
show_minutes = true;
- skip_factor = 1;
if (session->smpte_drop_frames) {
mark_interval -= 2 * session->frames_per_smpte_frame();
}
@@ -936,7 +921,7 @@
mark_interval -= 2 * skip_factor * session->frames_per_smpte_frame();
}
} else if (range <= 4 * 60 * 60 * fr) { /* 1 - 4 hrs*/
- mark_interval = 5 * 60 * fr; /* show 10 minutes */
+ mark_interval = 5 * 60 * fr; /* show 5 minutes */
show_minutes = true;
mark_modulo = 30;
skip_factor = 5;
@@ -944,7 +929,7 @@
mark_interval -= 2 * skip_factor * session->frames_per_smpte_frame();
}
} else if (range <= 8 * 60 * 60 * fr) { /* 4 - 8 hrs*/
- mark_interval = 10 * 60 * fr; /* show 20 minutes */
+ mark_interval = 10 * 60 * fr; /* show 10 minutes */
show_minutes = true;
mark_modulo = 60;
skip_factor = 10;
@@ -1027,8 +1012,10 @@
if (smpte.seconds == 0) {
(*marks)[n].style = GtkCustomRulerMarkMajor;
(*marks)[n].position = pos;
- if ((session->smpte_drop_frames) && (smpte.minutes % 10 != 0) &&(smpte.frames == 2) && (mark_interval > (2 * session->frames_per_smpte_frame()))) {
- pos -= 2 * session->frames_per_smpte_frame();
+ if (session->smpte_drop_frames) {
+ if ((smpte.minutes % 10 != 0) && (smpte.frames == 2)) {
+ pos -= 2 * session->frames_per_smpte_frame();
+ }
}
} else {
(*marks)[n].style = GtkCustomRulerMarkMinor;
@@ -1088,7 +1075,7 @@
(*marks)[n].label = g_strdup (buf);
(*marks)[n].position = pos;
}
- } else {
+ } else { // show frames
for (n = 0; n < nmarks; pos += mark_interval, ++n) {
session->smpte_time (pos, smpte);
if ((smpte.frames % mark_modulo) == 0) {
@@ -1099,19 +1086,22 @@
} else {
snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld:%02ld", smpte.hours, smpte.minutes, smpte.seconds, smpte.frames);
}
- } else if (session->smpte_drop_frames && (smpte.seconds == 0) && (smpte.frames == 2)) {
+ } else if (!session->smpte_drop_frames) {
+ snprintf (buf, sizeof(buf)," ");
+ (*marks)[n].style = GtkCustomRulerMarkMicro;
+ (*marks)[n].position = pos;
+
+ } else if ((smpte.seconds == 0) && (smpte.minutes % 10 != 0) && (smpte.frames == 2)) {
(*marks)[n].style = GtkCustomRulerMarkMajor;
(*marks)[n].position = pos;
- if ((session->smpte_drop_frames) && (smpte.minutes % 10 != 0) && (smpte.frames == 2)) {
- if (mark_interval > (2 * session->frames_per_smpte_frame())) {
- pos -= 2 * session->frames_per_smpte_frame();
- }
- }
if (smpte.negative) {
snprintf (buf, sizeof(buf), "-%02ld:%02ld:%02ld:%02ld", smpte.hours, smpte.minutes, smpte.seconds, smpte.frames);
} else {
snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld:%02ld", smpte.hours, smpte.minutes, smpte.seconds, smpte.frames);
}
+ if (skip_factor > 2) {
+ pos -= 2 * session->frames_per_smpte_frame();
+ }
} else {
snprintf (buf, sizeof(buf)," ");
(*marks)[n].style = GtkCustomRulerMarkMicro;
@@ -1174,7 +1164,7 @@
skip = (unsigned long) (Meter::ticks_per_beat / bbt_beat_subdivision);
- frame_one_beats_worth = (jack_nframes_t) ::floor ((double) session->frame_rate() * 60 / 20 ); //one beat @ 20 bpm
+ frame_one_beats_worth = session->frame_rate() * 3; //one beat @ 20 bpm
zoomed_bbt_points = session->tempo_map().get_points((lower >= frame_one_beats_worth) ? lower - frame_one_beats_worth : 0, upper );
if (current_bbt_points == 0 || zoomed_bbt_points == 0 || zoomed_bbt_points->empty()) {
@@ -1422,7 +1412,6 @@
static void
sample_to_clock_parts ( jack_nframes_t sample,
jack_nframes_t sample_rate,
-// float smpte_fps,
long *hrs_p,
long *mins_p,
long *secs_p,
@@ -1502,18 +1491,10 @@
} else if (range <= 8 * fr) { /* 2-5 seconds */
mark_interval = fr / 5; /* show 2 seconds */
mark_modulo = 1000;
- } else if (range <= 16 * fr) { /* 8-16 seconds */
- mark_interval = fr; /* show 1 seconds */
- show_seconds = true;
- mark_modulo = 5;
} else if (range <= 30 * fr) { /* 10-30 seconds */
- mark_interval = fr; /* show 10 seconds */
+ mark_interval = fr; /* show 1 second */
show_seconds = true;
mark_modulo = 5;
- } else if (range <= 60 * fr) { /* 30-60 seconds */
- mark_interval = 5 * fr; /* show 5 seconds */
- show_seconds = true;
- mark_modulo = 3;
} else if (range <= 2 * 60 * fr) { /* 1-2 minutes */
mark_interval = 5 * fr; /* show 5 seconds */
show_seconds = true;
@@ -1561,13 +1542,12 @@
for (n = 0; n < nmarks; pos += mark_interval, ++n) {
sample_to_clock_parts (pos, fr, &hrs, &mins, &secs, &millisecs);
if (secs % mark_modulo == 0) {
- if (secs == 0) {
+ if (secs == 0) {
(*marks)[n].style = GtkCustomRulerMarkMajor;
- snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld.%03ld", hrs, mins, secs, millisecs);
- } else {
+ } else {
(*marks)[n].style = GtkCustomRulerMarkMinor;
- snprintf (buf, sizeof(buf), ":%02ld.%03ld", secs, millisecs);
}
+ snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld.%03ld", hrs, mins, secs, millisecs);
} else {
snprintf (buf, sizeof(buf), " ");
(*marks)[n].style = GtkCustomRulerMarkMicro;
@@ -1581,11 +1561,10 @@
if (mins % mark_modulo == 0) {
if (mins == 0) {
(*marks)[n].style = GtkCustomRulerMarkMajor;
- snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld.%03ld", hrs, mins, secs, millisecs);
} else {
(*marks)[n].style = GtkCustomRulerMarkMinor;
- snprintf (buf, sizeof(buf), ":%02ld:%02ld.%03ld", mins, secs, millisecs);
}
+ snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld.%03ld", hrs, mins, secs, millisecs);
} else {
snprintf (buf, sizeof(buf), " ");
(*marks)[n].style = GtkCustomRulerMarkMicro;
@@ -1612,11 +1591,10 @@
if (millisecs % mark_modulo == 0) {
if (millisecs == 0) {
(*marks)[n].style = GtkCustomRulerMarkMajor;
- snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld.%03ld", hrs, mins, secs, millisecs);
} else {
(*marks)[n].style = GtkCustomRulerMarkMinor;
- snprintf (buf, sizeof(buf), ".%03ld", millisecs);
}
+ snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld.%03ld", hrs, mins, secs, millisecs);
} else {
snprintf (buf, sizeof(buf), " ");
(*marks)[n].style = GtkCustomRulerMarkMicro;
@@ -1628,3 +1606,4 @@
return nmarks;
}
+
-------------- next part --------------
--- /home/nick/ardour/libs/ardour/session_time.cc Wed Apr 7 11:55:02 2004
+++ ../libs/ardour/session_time.cc Sat Apr 17 01:46:16 2004
@@ -92,6 +92,42 @@
SMPTEOffsetChanged (); /* EMIT SIGNAL */
}
+static void
+nondrop_to_drop(long fps_int,
+ long* hrs,
+ long* mins,
+ long* secs,
+ long* frames
+ )
+{
+ long extra_frames = 0;
+ long i;
+ long total_minutes = 0;
+
+ total_minutes = *mins + (*hrs * 60);
+ extra_frames = (2 * total_minutes) - (2 * (total_minutes / 10));
+ for (i = 1; i <= extra_frames; i++ ) {
+ *frames += 1;
+ if (*frames > (fps_int - 1)) {
+ *secs += *frames / fps_int;
+ *frames -= (fps_int * (*frames / fps_int));
+ }
+ if (*secs > 59) {
+ *mins += 1;
+ *secs -= 60;
+ if (!(*mins % 10) == 0) {
+ extra_frames += 2; // dropped frames due to our extra frames
+ }
+ }
+ if (*mins > 59) {
+ *hrs += 1;
+ *mins -= 60;
+ }
+ }
+
+ return;
+}
+
void
Session::smpte_time (jack_nframes_t when, SMPTE_Time& smpte)
{
@@ -147,34 +183,9 @@
}
}
if (smpte_drop_frames) {
-
- long extra_frames = 0;
- long i;
- long total_minutes = 0;
-
- total_minutes = mins + (hrs * 60);
- extra_frames = (2 * total_minutes) - (2 * (total_minutes / 10));
- for (i = 1; i <= extra_frames; i++ ) {
- frames += 1;
- if (frames > (fps_int - 1)) {
- secs += frames / fps_int;
- frames -= (fps_int * (frames / fps_int));
- }
- if (secs > 59) {
- mins += 1;
- secs -= 60;
- if (!(mins % 10) == 0) {
- extra_frames += 2; // dropped frames from our extra frames
- }
- }
- if (mins > 59) {
- hrs += 1;
- mins -= 60;
- }
- }
+ nondrop_to_drop (fps_int, &hrs, &mins, &secs, &frames);
}
-
smpte.frames = frames;
smpte.seconds = secs;
smpte.minutes = mins;
@@ -240,34 +251,9 @@
/* eighty bits in a SMPTE frame */
subframes = (int) floor (left / (frame_rate() / (smpte_frames_per_second * 80)));
}
- if (smpte_drop_frames) {
-
- long extra_frames = 0;
- long i;
- long total_minutes = 0;
-
- total_minutes = mins + (hrs * 60);
- extra_frames = (2 * total_minutes) - (2 * (total_minutes / 10));
- for (i = 1; i <= extra_frames; i++ ) {
- frames += 1;
- if (frames > (fps_int - 1)) {
- secs += frames / fps_int;
- frames -= (fps_int * (frames / fps_int));
- }
- if (secs > 59) {
- mins += 1;
- secs -= 60;
- if (!(mins % 10) == 0) {
- extra_frames += 2; //add drop frames to our extra frames
- }
- }
- if (mins > 59) {
- hrs += 1;
- mins -= 60;
- }
- }
- }
-
+ if (smpte_drop_frames) { // subframes aren't affected
+ nondrop_to_drop (fps_int, &hrs, &mins, &secs, &frames);
+ }
smpte.subframes = subframes;
smpte.frames = frames;
smpte.seconds = secs;
@@ -323,66 +309,15 @@
subframes = (int) floor (left / (frame_rate() / (smpte_frames_per_second * 80)));
}
if (smpte_drop_frames) {
-
- long extra_frames = 0;
- long i;
- long total_minutes = 0;
-
- total_minutes = mins + (hrs * 60);
- extra_frames = (2 * total_minutes) - (2 * (total_minutes / 10));
- for (i = 1; i <= extra_frames; i++ ) {
- frames += 1;
- if (frames > (fps_int - 1)) {
- secs += frames / fps_int;
- frames -= (fps_int * (frames / fps_int));
- }
- if (secs > 59) {
- mins += 1;
- secs -= 60;
- if (!(mins % 10) == 0) {
- extra_frames += 2; //add drop frames to our extra frames
- }
- }
- if (mins > 59) {
- hrs += 1;
- mins -= 60;
- }
- }
- }
-
+ nondrop_to_drop (fps_int, &hrs, &mins, &secs, &frames);
+ }
+
smpte.subframes = subframes;
smpte.frames = frames;
smpte.seconds = secs;
smpte.minutes = mins;
smpte.hours = hrs;
-/* i've left the original here.. i can't really test the new one.
-it was only accurate to frames. maybe it was intentional ..nm
-
- double sample;
- double secs;
- double computed_secs;
- double approx_secs;
- long hrs;
- long mins;
-
- sample = when;
-
- approx_secs = (sample / frame_rate());
- secs = approx_secs;
- hrs = (long) floor (secs / 3600.0);
- secs -= (hrs * 3600.0);
- mins = (long) floor (secs / 60.0);
- secs -= (mins * 60.0);
-
- computed_secs = (hrs * 3600.0) + (mins * 60.0) + floor (secs);
-
- smpte.frames = (long) ((approx_secs - computed_secs) * smpte_frames_per_second);
- smpte.seconds = (long) secs;
- smpte.minutes = mins;
- smpte.hours = hrs;
-
-*/
}
void
More information about the Ardour-Dev
mailing list