"toll free bridging" between smf_tempo_t and Evoral::SMF::Tempo
authorPaul Davis <paul@linuxaudiosystems.com>
Fri, 16 Dec 2016 13:45:43 +0000 (13:45 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Fri, 16 Dec 2016 13:45:43 +0000 (13:45 +0000)
libs/evoral/evoral/SMF.hpp
libs/evoral/src/SMF.cpp

index 0c312890b25e5a0ef39b31c6a4c3a7f8da7189b1..f0757929bdea0e80ce95bb6d5f83a44259ee5997 100644 (file)
@@ -93,7 +93,26 @@ public:
 
        int num_tempos () const;
 
-       typedef smf_tempo_t Tempo;
+       /* This is exactly modelled on smf_tempo_t */
+       struct Tempo {
+               size_t time_pulses;
+               double time_seconds;
+               int    microseconds_per_quarter_note;
+               int    numerator;
+               int    denominator;
+               int    clocks_per_click;
+               int    notes_per_note;
+
+               Tempo ()
+                       : time_pulses (0)
+                       , time_seconds (0)
+                       , microseconds_per_quarter_note (-1)
+                       , numerator (-1)
+                       , denominator (-1)
+                       , clocks_per_click (-1)
+                       , notes_per_note (-1) {}
+               Tempo (smf_tempo_t*);
+       };
 
        Tempo* tempo_at_smf_pulse (size_t smf_pulse) const;
        Tempo* tempo_at_seconds (double seconds) const;
index 63050b63bea687896ac25a063f8c80d92e928a00..b5d34aa53839ecdf613c4c2b8c5b5a8b9d903be8 100644 (file)
@@ -522,6 +522,17 @@ SMF::instrument_names(vector<string>& names) const
        }
 }
 
+SMF::Tempo::Tempo (smf_tempo_t* smft)
+       : time_pulses (smft->time_pulses)
+       , time_seconds (smft->time_seconds)
+       , microseconds_per_quarter_note (smft->microseconds_per_quarter_note)
+       , numerator (smft->numerator)
+       , denominator (smft->denominator)
+       , clocks_per_click (smft->clocks_per_click)
+       , notes_per_note (smft->notes_per_note)
+{
+}
+
 int
 SMF::num_tempos () const
 {
@@ -532,13 +543,21 @@ SMF::num_tempos () const
 SMF::Tempo*
 SMF::tempo_at_smf_pulse (size_t smf_pulse) const
 {
-       return smf_get_tempo_by_seconds (_smf, smf_pulse);
+       smf_tempo_t* t = smf_get_tempo_by_seconds (_smf, smf_pulse);
+       if (!t) {
+               return 0;
+       }
+       return new Tempo (t);
 }
 
 SMF::Tempo*
 SMF::tempo_at_seconds (double seconds) const
 {
-       return smf_get_tempo_by_seconds (_smf, seconds);
+       smf_tempo_t* t = smf_get_tempo_by_seconds (_smf, seconds);
+       if (!t) {
+               return 0;
+       }
+       return new Tempo (t);
 }
 
 SMF::Tempo*
@@ -546,7 +565,12 @@ SMF::nth_tempo (size_t n) const
 {
        assert (_smf);
 
-       return smf_get_tempo_by_number (_smf, n);
+       smf_tempo_t* t = smf_get_tempo_by_number (_smf, n);
+       if (!t) {
+               return 0;
+       }
+
+       return new Tempo (t);
 }
 
 } // namespace Evoral