Preferences/Config changes for image-surface settings
[ardour.git] / gtk2_ardour / audio_region_editor.cc
index e06e50f113558e363c312b2cb724890ce601a261..df57b57c71b09ac95c21b94835f67c9f36358494 100644 (file)
@@ -1,41 +1,42 @@
 /*
-    Copyright (C) 2001 Paul Davis
+ * Copyright (C) 2006-2012 David Robillard <d@drobilla.net>
+ * Copyright (C) 2006-2015 Tim Mayberry <mojofunk@gmail.com>
+ * Copyright (C) 2006-2016 Paul Davis <paul@linuxaudiosystems.com>
+ * Copyright (C) 2009-2011 Carl Hetherington <carl@carlh.net>
+ * Copyright (C) 2014-2016 Robin Gareus <robin@gareus.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
 
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#include <cmath>
 
-*/
+#include <gtkmm2ext/utils.h>
 
 #include "pbd/memento_command.h"
 #include "pbd/stateful_diff_command.h"
 #include "pbd/pthread_utils.h"
 
-#include "ardour/session.h"
 #include "ardour/audioregion.h"
-#include "ardour/playlist.h"
-#include "ardour/utils.h"
+#include "ardour/session_event.h"
 #include "ardour/dB.h"
-#include <gtkmm2ext/utils.h>
-#include <cmath>
 
 #include "audio_region_editor.h"
 #include "audio_region_view.h"
-#include "ardour_ui.h"
-#include "utils.h"
 #include "gui_thread.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace ARDOUR;
 using namespace PBD;
@@ -45,7 +46,6 @@ using namespace Gtkmm2ext;
 static void *
 _peak_amplitude_thread (void* arg)
 {
-       SessionEvent::create_per_thread_pool ("peak amplitude events", 64);
        static_cast<AudioRegionEditor*>(arg)->peak_amplitude_thread ();
        return 0;
 }
@@ -90,14 +90,17 @@ AudioRegionEditor::AudioRegionEditor (Session* s, boost::shared_ptr<AudioRegion>
        _peak_amplitude.set_text (_("Calculating..."));
 
        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');
+
+       char name[64];
+       snprintf (name, 64, "peak amplitude-%p", this);
+       pthread_create_and_store (name, &_peak_amplitude_thread_handle, _peak_amplitude_thread, this);
+       signal_peak_thread ();
 }
 
 AudioRegionEditor::~AudioRegionEditor ()
 {
        void* v;
-       pthread_cancel_one (_peak_amplitude_thread_handle);
+       _peak_channel.deliver ('t');
        pthread_join (_peak_amplitude_thread_handle, &v);
 }
 
@@ -112,7 +115,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,14 +136,24 @@ AudioRegionEditor::gain_adjustment_changed ()
        }
 }
 
+void
+AudioRegionEditor::signal_peak_thread ()
+{
+       _peak_channel.deliver ('c');
+}
+
 void
 AudioRegionEditor::peak_amplitude_thread ()
 {
        while (1) {
-               /* await instructions to run */
                char msg;
+               /* await instructions to run */
                _peak_channel.receive (msg);
 
+               if (msg == 't') {
+                       break;
+               }
+
                /* compute peak amplitude and signal the fact */
                PeakAmplitudeFound (accurate_coefficient_to_dB (_audio_region->maximum_amplitude ())); /* EMIT SIGNAL */
        }