remove additional "mid" color from ArdourButton; replace Active/Mid widget state...
[ardour.git] / gtk2_ardour / audio_region_editor.cc
index e47f145c7e2e4caabbdde6f03e962e0c89f077c4..e06e50f113558e363c312b2cb724890ce601a261 100644 (file)
@@ -53,8 +53,8 @@ _peak_amplitude_thread (void* arg)
 AudioRegionEditor::AudioRegionEditor (Session* s, boost::shared_ptr<AudioRegion> r)
        : 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)        
-       , _peak_amplitude_found (false)
+       , gain_adjustment(accurate_coefficient_to_dB(_audio_region->scale_amplitude()), -40.0, +40.0, 0.1, 1.0, 0)
+       , _peak_channel (false)
 {
 
        Gtk::HBox* b = Gtk::manage (new Gtk::HBox);
@@ -74,14 +74,14 @@ AudioRegionEditor::AudioRegionEditor (Session* s, boost::shared_ptr<AudioRegion>
        b->set_spacing (6);
        b->pack_start (_peak_amplitude);
        b->pack_start (*Gtk::manage (new Gtk::Label (_("dBFS"))), false, false);
-       
+
        _peak_amplitude_label.set_name ("AudioRegionEditorLabel");
        _peak_amplitude_label.set_text (_("Peak amplitude:"));
        _peak_amplitude_label.set_alignment (1, 0.5);
        _table.attach (_peak_amplitude_label, 0, 1, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
        _table.attach (*b, 1, 2, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
        ++_table_row;
-       
+
        gain_changed ();
 
        gain_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &AudioRegionEditor::gain_adjustment_changed));
@@ -91,24 +91,29 @@ 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');
 }
 
 AudioRegionEditor::~AudioRegionEditor ()
 {
-       pthread_cancel_one (_peak_amplitude_thread_handle);
        void* v;
-       int const r = pthread_join (_peak_amplitude_thread_handle, &v);
-       assert (r == 0);
+       pthread_cancel_one (_peak_amplitude_thread_handle);
+       pthread_join (_peak_amplitude_thread_handle, &v);
 }
 
 void
 AudioRegionEditor::region_changed (const PBD::PropertyChange& what_changed)
 {
        RegionEditor::region_changed (what_changed);
-       
+
        if (what_changed.contains (ARDOUR::Properties::scale_amplitude)) {
                gain_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');
+       }
 }
 void
 AudioRegionEditor::gain_changed ()
@@ -131,7 +136,14 @@ AudioRegionEditor::gain_adjustment_changed ()
 void
 AudioRegionEditor::peak_amplitude_thread ()
 {
-       PeakAmplitudeFound (accurate_coefficient_to_dB (_audio_region->maximum_amplitude ())); /* EMIT SIGNAL */
+       while (1) {
+               /* await instructions to run */
+               char msg;
+               _peak_channel.receive (msg);
+
+               /* compute peak amplitude and signal the fact */
+               PeakAmplitudeFound (accurate_coefficient_to_dB (_audio_region->maximum_amplitude ())); /* EMIT SIGNAL */
+       }
 }
 
 void