diff options
author | Carl Hetherington <carl@carlh.net> | 2011-02-17 20:25:09 +0000 |
---|---|---|
committer | Carl Hetherington <carl@carlh.net> | 2011-02-17 20:25:09 +0000 |
commit | ff102f4cacb9208cd6d400186d7fe93bdb028e27 (patch) | |
tree | 976db1d1008a36703e9a8c30149e24a79da36a2d /libs/ardour/session_click.cc | |
parent | e9e1800d86ef4b37f42ecb18e8efbf6095b5a92b (diff) |
Trim some duplicate code.
git-svn-id: svn://localhost/ardour2/branches/3.0@8893 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/session_click.cc')
-rw-r--r-- | libs/ardour/session_click.cc | 122 |
1 files changed, 53 insertions, 69 deletions
diff --git a/libs/ardour/session_click.cc b/libs/ardour/session_click.cc index 0a83a0f6d9..2a1b4122e4 100644 --- a/libs/ardour/session_click.cc +++ b/libs/ardour/session_click.cc @@ -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 () + ); } } |