Trim some duplicate code.
authorCarl Hetherington <carl@carlh.net>
Thu, 17 Feb 2011 20:25:09 +0000 (20:25 +0000)
committerCarl Hetherington <carl@carlh.net>
Thu, 17 Feb 2011 20:25:09 +0000 (20:25 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@8893 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/ardour/session.h
libs/ardour/session_click.cc

index dfa09fd3577e8d0286a0b8a9e56040920147838e..6b874d804112cfb245c503a1cfce001799072eda 100644 (file)
@@ -1379,6 +1379,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
        Click *get_click();
        void   setup_click_sounds (int which);
+       void   setup_click_sounds (Sample**, Sample const *, framecnt_t*, framecnt_t, std::string const &);
        void   clear_clicks ();
        void   click (framepos_t start, framecnt_t nframes);
 
index 0a83a0f6d98b875022f7c8483e7b54d30a755cf5..2a1b4122e4826644e0f8e67100f64faeca777525 100644 (file)
@@ -131,85 +131,69 @@ Session::click (framepos_t start, framecnt_t nframes)
 }
 
 void
-Session::setup_click_sounds (int which)
+Session::setup_click_sounds (Sample** data, Sample const * default_data, framecnt_t* length, framecnt_t default_length, string const & path)
 {
-       SNDFILE *sndfile;
-       SF_INFO info;
-
-       clear_clicks();
-
-       if ((which == 0 || which == 1)) {
-
-               if (click_data != default_click) {
-                       delete [] click_data;
-                       click_data = 0;
-               }
-
-               string path = Config->get_click_sound();
-
-               if (path.empty()) {
-
-                       click_data = const_cast<Sample*> (default_click);
-                       click_length = default_click_length;
-
-               } else {
-
-                       info.format = 0;
-                       if ((sndfile = sf_open (path.c_str(), SFM_READ, &info)) == 0) {
-                               char errbuf[256];
-                               sf_error_str (0, errbuf, sizeof (errbuf) - 1);
-                               warning << string_compose (_("cannot open click soundfile %1 (%2)"), path, errbuf) << endmsg;
-                               _clicking = false;
-                               return;
-                       }
+       if (*data != default_data) {
+               delete[] *data;
+               *data = 0;
+       }
 
-                       click_data = new Sample[info.frames];
-                       click_length = info.frames;
+       if (path.empty ()) {
 
-                       if (sf_read_float (sndfile, click_data, info.frames) != info.frames) {
-                               warning << _("cannot read data from click soundfile") << endmsg;
-                               delete click_data;
-                               click_data = 0;
-                               _clicking = false;
-                       }
+               *data = const_cast<Sample*> (default_data);
+               *length = default_length;
 
-                       sf_close (sndfile);
+       } else {
 
+               SF_INFO info;
+               SNDFILE* sndfile;
+               
+               info.format = 0;
+               if ((sndfile = sf_open (path.c_str(), SFM_READ, &info)) == 0) {
+                       char errbuf[256];
+                       sf_error_str (0, errbuf, sizeof (errbuf) - 1);
+                       warning << string_compose (_("cannot open click soundfile %1 (%2)"), path, errbuf) << endmsg;
+                       _clicking = false;
+                       return;
                }
-       }
 
-       if ((which == 0 || which == -1)) {
-
-               if (click_emphasis_data != default_click_emphasis) {
-                       delete [] click_emphasis_data;
-                       click_emphasis_data = 0;
+               *data = new Sample[info.frames];
+               *length = info.frames;
+               
+               if (sf_read_float (sndfile, *data, info.frames) != info.frames) {
+                       warning << _("cannot read data from click soundfile") << endmsg;
+                       delete *data;
+                       *data = 0;
+                       _clicking = false;
                }
+               
+               sf_close (sndfile);
+       }
+}
 
-               string path = Config->get_click_emphasis_sound();
-
-               if (path.empty()) {
-                       click_emphasis_data = const_cast<Sample*> (default_click_emphasis);
-                       click_emphasis_length = default_click_emphasis_length;
-               } else {
-                       info.format = 0;
-                       if ((sndfile = sf_open (path.c_str(), SFM_READ, &info)) == 0) {
-                               char errbuf[256];
-                               sf_error_str (0, errbuf, sizeof (errbuf) - 1);
-                               warning << string_compose (_("cannot open click emphasis soundfile %1 (%2)"), path, errbuf) << endmsg;
-                               return;
-                       }
-
-                       click_emphasis_data = new Sample[info.frames];
-                       click_emphasis_length = info.frames;
-
-                       if (sf_read_float (sndfile, click_emphasis_data, info.frames) != info.frames) {
-                               warning << _("cannot read data from click emphasis soundfile") << endmsg;
-                               delete click_emphasis_data;
-                               click_emphasis_data = 0;
-                       }
+void
+Session::setup_click_sounds (int which)
+{
+       clear_clicks ();
+
+       if (which == 0 || which == 1) {
+               setup_click_sounds (
+                       &click_data,
+                       default_click,
+                       &click_length,
+                       default_click_length,
+                       Config->get_click_sound ()
+                       );
+       }
 
-                       sf_close (sndfile);
-               }
+       if (which == 0 || which == -1) {
+               setup_click_sounds (
+                       &click_emphasis_data,
+                       default_click_emphasis,
+                       &click_emphasis_length,
+                       default_click_emphasis_length,
+                       Config->get_click_emphasis_sound ()
+                       );
        }
 }