try to fix async peaks issue; fix crasher caused by previous lock changes in AudioSou...
authorPaul Davis <paul@linuxaudiosystems.com>
Tue, 11 Sep 2007 02:57:05 +0000 (02:57 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Tue, 11 Sep 2007 02:57:05 +0000 (02:57 +0000)
git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@2450 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/ardour_ui_ed.cc
gtk2_ardour/editor_audio_import.cc
gtk2_ardour/opts.cc
gtk2_ardour/sfdb_ui.cc
gtk2_ardour/sfdb_ui.h
libs/ardour/ardour/audiosource.h
libs/ardour/audiofilesource.cc
libs/ardour/audiosource.cc
libs/ardour/globals.cc
libs/ardour/sndfilesource.cc
libs/ardour/source_factory.cc

index b5a6281c1bbe8efd160c77593b06f87ef1a9d106..4777617a77e82819906598ab4c01277c0a43c8c2 100644 (file)
@@ -423,22 +423,41 @@ ARDOUR_UI::install_actions ()
        RadioAction::Group denormal_group;
 
        ActionManager::register_toggle_action (option_actions, X_("DenormalProtection"), _("Use DC bias"), mem_fun (*this, &ARDOUR_UI::toggle_denormal_protection));
-       
-       FPU fpu;
 
        ActionManager::register_radio_action (option_actions, denormal_group, X_("DenormalNone"), _("No processor handling"), bind (mem_fun (*this, &ARDOUR_UI::set_denormal_model), DenormalNone));
 
-       act = ActionManager::register_radio_action (option_actions, denormal_group, X_("DenormalFTZ"), _("Use FlushToZero"), bind (mem_fun (*this, &ARDOUR_UI::set_denormal_model), DenormalFTZ));
-       if (!fpu.has_flush_to_zero()) {
+       // as of September 10th 2007, Valgrind cannot handle various FPU flag setting instructions
+       // so avoid them
+
+       if (getenv ("ARDOUR_RUNNING_UNDER_VALGRIND")) {
+
+               /* we still need these actions to exist, but make them all insensitive */
+
+               act = ActionManager::register_radio_action (option_actions, denormal_group, X_("DenormalFTZ"), _("Use FlushToZero"), bind (mem_fun (*this, &ARDOUR_UI::set_denormal_model), DenormalFTZ));
                act->set_sensitive (false);
-       }
-       act = ActionManager::register_radio_action (option_actions, denormal_group, X_("DenormalDAZ"), _("Use DenormalsAreZero"), bind (mem_fun (*this, &ARDOUR_UI::set_denormal_model), DenormalDAZ));
-       if (!fpu.has_denormals_are_zero()) {
+               act = ActionManager::register_radio_action (option_actions, denormal_group, X_("DenormalDAZ"), _("Use DenormalsAreZero"), bind (mem_fun (*this, &ARDOUR_UI::set_denormal_model), DenormalDAZ));
                act->set_sensitive (false);
-       }
-       act = ActionManager::register_radio_action (option_actions, denormal_group, X_("DenormalFTZDAZ"), _("Use FlushToZero & DenormalsAreZero"), bind (mem_fun (*this, &ARDOUR_UI::set_denormal_model), DenormalFTZDAZ));
-       if (!fpu.has_flush_to_zero() || !fpu.has_denormals_are_zero()) {
+               act = ActionManager::register_radio_action (option_actions, denormal_group, X_("DenormalFTZDAZ"), _("Use FlushToZero & DenormalsAreZero"), bind (mem_fun (*this, &ARDOUR_UI::set_denormal_model), DenormalFTZDAZ));
                act->set_sensitive (false);
+
+       } else {
+
+               FPU fpu;
+
+               act = ActionManager::register_radio_action (option_actions, denormal_group, X_("DenormalFTZ"), _("Use FlushToZero"), bind (mem_fun (*this, &ARDOUR_UI::set_denormal_model), DenormalFTZ));
+               if (!fpu.has_flush_to_zero()) {
+                       act->set_sensitive (false);
+               }
+
+               act = ActionManager::register_radio_action (option_actions, denormal_group, X_("DenormalDAZ"), _("Use DenormalsAreZero"), bind (mem_fun (*this, &ARDOUR_UI::set_denormal_model), DenormalDAZ));
+               if (!fpu.has_denormals_are_zero()) {
+                       act->set_sensitive (false);
+               }
+
+               act = ActionManager::register_radio_action (option_actions, denormal_group, X_("DenormalFTZDAZ"), _("Use FlushToZero & DenormalsAreZero"), bind (mem_fun (*this, &ARDOUR_UI::set_denormal_model), DenormalFTZDAZ));
+               if (!fpu.has_flush_to_zero() || !fpu.has_denormals_are_zero()) {
+                       act->set_sensitive (false);
+               }
        }
 
        act = ActionManager::register_toggle_action (option_actions, X_("DoNotRunPluginsWhileRecording"), _("Do not run plugins while recording"), mem_fun (*this, &ARDOUR_UI::toggle_DoNotRunPluginsWhileRecording));
index ac29b5264eb41e711ba566e4b168fb060f3bb9fc..a4a9a7a420155dee2f515c7dd6bd8b5cd120d67f 100644 (file)
@@ -135,6 +135,7 @@ Editor::external_audio_dialog ()
        }
 
        if (response == RESPONSE_APPLY) {
+               sfbrowser->clear_selection ();
                goto again;
        }
 }
index e9be9e49ec87300d483dbcad3a5fa6890a9d9e8f..6a78be9cb9286d9e720f7a7edb6f63187ec8f01e 100644 (file)
@@ -91,7 +91,7 @@ ARDOUR_COMMAND_LINE::parse_opts (int argc, char *argv[])
                { "novst", 0, 0, 'V' },
                { "new", 1, 0, 'N' },
                { "no-hw-optimizations", 0, 0, 'O' },
-               { "sync", 0, 0, 'O' },
+               { "sync", 0, 0, 'S' },
                { "curvetest", 1, 0, 'C' },
                { "sillyAppleUndocumentedFinderFeature", 1, 0, 'p' },
                { 0, 0, 0, 0 }
index e239f432d535d3026ae7fcbdb0366f5b882c8d6b..af950d8e6ef5b43f268d2353e8a84f1946205955 100644 (file)
@@ -175,7 +175,7 @@ SoundFileBox::set_session(Session* s)
 bool
 SoundFileBox::setup_labels (const ustring& filename) 
 {
-       if (path.empty()) {
+       if (!path.empty()) {
                // save existing tags
                tags_changed ();
        }
@@ -406,6 +406,13 @@ SoundFileBrowser::~SoundFileBrowser ()
        persistent_folder = chooser.get_current_folder();
 }
 
+void
+SoundFileBrowser::clear_selection ()
+{
+       chooser.unselect_all ();
+       found_list_view.get_selection()->unselect_all ();
+}
+
 void
 SoundFileBrowser::chooser_file_activated ()
 {
@@ -499,13 +506,13 @@ SoundFileBrowser::get_paths ()
        if (n == 0) {
                vector<ustring> filenames = chooser.get_filenames();
                vector<ustring>::iterator i;
+
                for (i = filenames.begin(); i != filenames.end(); ++i) {
                        struct stat buf;
                        if ((!stat((*i).c_str(), &buf)) && S_ISREG(buf.st_mode)) {
                                results.push_back (*i);
                        }
                }
-               return results;
                
        } else {
                
@@ -518,8 +525,9 @@ SoundFileBrowser::get_paths ()
                        
                        results.push_back (str);
                }
-               return results;
        }
+
+       return results;
 }
 
 void
index 4670796700d612c8cdc7df81a77b9656519a9b9b..ec057814bee4799a68969f3f0d140c62cdc51795 100644 (file)
@@ -122,6 +122,8 @@ class SoundFileBrowser : public ArdourDialog
        virtual void set_session (ARDOUR::Session*);
        std::vector<Glib::ustring> get_paths ();
        
+       void clear_selection ();
+
        Gtk::FileChooserWidget chooser;
        Gtk::TreeView found_list_view;
 
index fefc5d8964982e0311c1e75e5920177691212d95..fd97ae837743b380d1bd785af884e3d7f3206ade 100644 (file)
@@ -115,7 +115,7 @@ const nframes_t frames_per_peak = 256;
        static bool _build_peakfiles;
 
        bool                 _peaks_built;
-       mutable Glib::RWLock _lock;
+       mutable Glib::Mutex  _lock;
        mutable Glib::Mutex  _peaks_ready_lock;
        nframes_t            _length;
        ustring               peakpath;
index 39b02287919dbe802b84e74cb6bfb03e54c16195..a2a457b023abf1f9c2ce60d994d17c493d81c634 100644 (file)
@@ -269,7 +269,7 @@ AudioFileSource::mark_streaming_write_completed ()
           but we must hold a solid lock on PeaksReady.
        */
 
-       Glib::RWLock::WriterLock lm (_lock);
+       Glib::Mutex::Lock lm (_lock);
        
        if (_peaks_built) {
                PeaksReady (); /* EMIT SIGNAL */
@@ -568,7 +568,7 @@ AudioFileSource::set_allow_remove_if_empty (bool yn)
 int
 AudioFileSource::set_name (ustring newname, bool destructive)
 {
-       Glib::RWLock::WriterLock lm (_lock);
+       Glib::Mutex::Lock lm (_lock);
        ustring oldpath = _path;
        ustring newpath = Session::change_audio_path_by_name (oldpath, _name, newname, destructive);
 
index b0bab54559b081eceac1ef352e3f373d3c53962f..c8a557808c96560b44e1173606787eada2fffccb 100644 (file)
@@ -246,21 +246,21 @@ AudioSource::initialize_peakfile (bool newfile, ustring audio_path)
 nframes_t
 AudioSource::read (Sample *dst, nframes_t start, nframes_t cnt) const
 {
-       Glib::RWLock::ReaderLock lm (_lock);
+       Glib::Mutex::Lock lm (_lock);
        return read_unlocked (dst, start, cnt);
 }
 
 nframes_t
 AudioSource::write (Sample *dst, nframes_t cnt)
 {
-       Glib::RWLock::WriterLock lm (_lock);
+       Glib::Mutex::Lock lm (_lock);
        return write_unlocked (dst, cnt);
 }
 
 int 
 AudioSource::read_peaks (PeakData *peaks, nframes_t npeaks, nframes_t start, nframes_t cnt, double samples_per_visual_peak) const
 {
-       Glib::RWLock::ReaderLock lm (_lock);
+       Glib::Mutex::Lock lm (_lock);
        double scale;
        double expected_peaks;
        PeakData::PeakDatum xmax;
@@ -584,14 +584,15 @@ AudioSource::build_peaks_from_scratch ()
        nframes_t cnt;
        Sample* buf = 0;
        nframes_t frames_read;
-       nframes_t frames_to_read = 65536; // 256kB reads from disk, roughly ideal
+       nframes_t frames_to_read;
+       const nframes_t bufsize = 65536; // 256kB per disk read for mono data is about ideal
 
        int ret = -1;
 
        {
                /* hold lock while building peaks */
 
-               Glib::RWLock::ReaderLock lp (_lock);
+               Glib::Mutex::Lock lp (_lock);
                
                if (prepare_for_peakfile_writes ()) {
                        goto out;
@@ -600,18 +601,18 @@ AudioSource::build_peaks_from_scratch ()
                current_frame = 0;
                cnt = _length;
                _peaks_built = false;
-               buf = new Sample[frames_to_read];
+               buf = new Sample[bufsize];
                
                while (cnt) {
                        
-                       frames_to_read = min (frames_per_peak, cnt);
+                       frames_to_read = min (bufsize, cnt);
 
                        if ((frames_read = read_unlocked (buf, current_frame, frames_to_read)) != frames_to_read) {
                                error << string_compose(_("%1: could not write read raw data for peak computation (%2)"), _name, strerror (errno)) << endmsg;
                                done_with_peakfile_writes (false);
                                goto out;
                        }
-                       
+
                        if (compute_and_write_peaks (buf, current_frame, frames_read, true, false)) {
                                break;
                        }
@@ -623,10 +624,9 @@ AudioSource::build_peaks_from_scratch ()
                if (cnt == 0) {
                        /* success */
                        truncate_peakfile();
-                       _peaks_built = true;
                } 
 
-               done_with_peakfile_writes ();
+               done_with_peakfile_writes ((cnt == 0));
        }
        
        {
@@ -724,9 +724,7 @@ AudioSource::compute_and_write_peaks (Sample* buf, nframes_t first_frame, nframe
                                PeakRangeReady (peak_leftover_frame, peak_leftover_cnt); /* EMIT SIGNAL */
                                if (intermediate_peaks_ready) {
                                        PeaksReady (); /* EMIT SIGNAL */
-                               }  else {
-                                       cerr << "Skip PR at A\n";
-                               }
+                               } 
                        }
 
                        /* left overs are done */
@@ -838,10 +836,7 @@ AudioSource::compute_and_write_peaks (Sample* buf, nframes_t first_frame, nframe
                PeakRangeReady (first_frame, frames_done); /* EMIT SIGNAL */
                if (intermediate_peaks_ready) {
                        PeaksReady (); /* EMIT SIGNAL */
-               } else {
-                       cerr << "Skip PR at A\n";
                }
-
        }
 
        ret = 0;
index e5c9d27d5e19089a464c67c7cc012e144e0bd2e2..b4286c089fa983286c10a3719ce3662cf6f0dfaf 100644 (file)
@@ -206,10 +206,11 @@ void
 setup_hardware_optimization (bool try_optimization)
 {
         bool generic_mix_functions = true;
-       FPU fpu;
 
        if (try_optimization) {
 
+               FPU fpu;
+
 #if defined (ARCH_X86) && defined (BUILD_SSE_OPTIMIZATIONS)
                
                if (fpu.has_sse()) {
@@ -245,6 +246,10 @@ setup_hardware_optimization (bool try_optimization)
                         info << "Apple VecLib H/W specific optimizations in use" << endmsg;
                 }
 #endif
+
+               /* consider FPU denormal handling to be "h/w optimization" */
+
+               setup_fpu ();
         }
 
         if (generic_mix_functions) {
@@ -258,8 +263,6 @@ setup_hardware_optimization (bool try_optimization)
                info << "No H/W specific optimizations in use" << endmsg;
        }
 
-       setup_fpu ();
-
 }
 
 int
@@ -518,6 +521,12 @@ ARDOUR::LocaleGuard::~LocaleGuard ()
 void
 ARDOUR::setup_fpu ()
 {
+       if (getenv ("ARDOUR_RUNNING_UNDER_VALGRIND")) {
+               // valgrind doesn't understand this assembler stuff
+               // September 10th, 2007
+               return;
+       }
+
 #if defined(ARCH_X86) && defined(USE_XMMINTRIN)
 
        int MXCSR;
index 0ed8c9cc341e52fab667ea09c3324169b459f947..9b0d5fabb3be45988c7f74dceca68a105321c1b6 100644 (file)
@@ -25,6 +25,7 @@
 #include <sys/stat.h>
 
 #include <glibmm/miscutils.h>
+#include <pbd/stacktrace.h>
 
 #include <ardour/sndfilesource.h>
 #include <ardour/sndfile_helpers.h>
index 405f0a064f3cdd20afd8f66641c9f870da8991e1..dbb437edaa2da6e2158e439bdbc2cb71b7e00aa3 100644 (file)
@@ -54,10 +54,11 @@ peak_thread_work ()
 
                SourceFactory::peak_building_lock.lock ();
 
+         wait:
                SourceFactory::PeaksToBuild->wait (SourceFactory::peak_building_lock);
 
                if (SourceFactory::files_with_peaks.empty()) {
-                       continue;
+                       goto wait;
                }
                
                boost::shared_ptr<AudioSource> as (SourceFactory::files_with_peaks.front().lock());
@@ -67,7 +68,7 @@ peak_thread_work ()
                if (!as) {
                        continue;
                }
-               
+
                as->setup_peakfile ();
        }
 }