Use PBD::GlibSemaphore on windows to signal peak
authorPaul Davis <paul@linuxaudiosystems.com>
Sat, 13 Jul 2013 12:27:56 +0000 (08:27 -0400)
committerPaul Davis <paul@linuxaudiosystems.com>
Sat, 13 Jul 2013 12:27:56 +0000 (08:27 -0400)
gtk2_ardour/audio_region_editor.cc
gtk2_ardour/audio_region_editor.h

index 2aeb2dbe60aae44ffe7cfcd737c19cf5dd3d8691..03d3e472640e4204ee8c00fce2619f34e633a2a6 100644 (file)
@@ -54,7 +54,9 @@ AudioRegionEditor::AudioRegionEditor (Session* s, boost::shared_ptr<AudioRegion>
        : RegionEditor (s, r)
        , _audio_region (r)
        , gain_adjustment(accurate_coefficient_to_dB(_audio_region->scale_amplitude()), -40.0, +40.0, 0.1, 1.0, 0)
+#ifndef WIN32
        , _peak_channel (false)
+#endif
 {
 
        Gtk::HBox* b = Gtk::manage (new Gtk::HBox);
@@ -91,7 +93,7 @@ AudioRegionEditor::AudioRegionEditor (Session* s, boost::shared_ptr<AudioRegion>
 
        PeakAmplitudeFound.connect (_peak_amplitude_connection, invalidator (*this), boost::bind (&AudioRegionEditor::peak_amplitude_found, this, _1), gui_context ());
        pthread_create_and_store (X_("peak-amplitude"), &_peak_amplitude_thread_handle, _peak_amplitude_thread, this);
-       _peak_channel.deliver ('c');
+       signal_peak_thread ();
 }
 
 AudioRegionEditor::~AudioRegionEditor ()
@@ -112,7 +114,7 @@ AudioRegionEditor::region_changed (const PBD::PropertyChange& what_changed)
 
        if (what_changed.contains (ARDOUR::Properties::start) || what_changed.contains (ARDOUR::Properties::length)) {
                /* ask the peak thread to run again */
-               _peak_channel.deliver ('c');
+               signal_peak_thread ();
        }
 }
 void
@@ -133,13 +135,33 @@ AudioRegionEditor::gain_adjustment_changed ()
        }
 }
 
+void
+AudioRegionEditor::signal_peak_thread ()
+{
+#ifdef WIN32
+       m_peak_sem.post ();
+#else
+       _peak_channel.deliver ('c');
+#endif
+}
+
+void
+AudioRegionEditor::wait_for_signal ()
+{
+#ifdef WIN32
+       m_peak_sem.wait ();
+#else
+       char msg;
+       _peak_channel.receive (msg);
+#endif
+}
+
 void
 AudioRegionEditor::peak_amplitude_thread ()
 {
        while (1) {
                /* await instructions to run */
-               char msg;
-               _peak_channel.receive (msg);
+               wait_for_signal ();
 
                /* compute peak amplitude and signal the fact */
                PeakAmplitudeFound (accurate_coefficient_to_dB (_audio_region->maximum_amplitude ())); /* EMIT SIGNAL */
index dd65a3fb31d48f4f919afb343b9e0208ce1cbcd2..0d9292b483d84e16ebb30823a2e9c2377355d302 100644 (file)
 #include <libgnomecanvas/libgnomecanvas.h>
 
 #include "pbd/signals.h"
+#ifdef WIN32
+#include "pbd/glib_semaphore.h"
+#else
 #include "pbd/crossthread.h"
+#endif
 
 #include "audio_clock.h"
 #include "ardour_dialog.h"
@@ -74,11 +78,17 @@ class AudioRegionEditor : public RegionEditor
        Gtk::Label _peak_amplitude_label;
        Gtk::Entry _peak_amplitude;
 
+       void signal_peak_thread ();
+       void wait_for_signal ();
        pthread_t _peak_amplitude_thread_handle;
        void peak_amplitude_found (double);
        PBD::Signal1<void, double> PeakAmplitudeFound;
        PBD::ScopedConnection _peak_amplitude_connection;
+#ifdef WIN32
+       PBD::GlibSemaphore m_peak_sem;
+#else
        CrossThreadChannel _peak_channel;
+#endif
 };
 
 #endif /* __gtk_ardour_audio_region_edit_h__ */