From 9a951bcd20a7cd814da3ad34e4c931231d824947 Mon Sep 17 00:00:00 2001 From: Taybin Rutkin Date: Wed, 11 Jan 2006 21:27:59 +0000 Subject: [PATCH] Use compiler provided __BIG_ENDIAN__ instead of WORD_BIGENDIAN Auditioning in sfdb_ui works. CoreAudioSource updates. git-svn-id: svn://localhost/trunk/ardour2@263 d708f5d6-7413-0410-9779-e7cbd77b26cf --- SConstruct | 11 +--- gtk2_ardour/sfdb_ui.cc | 106 +++++++++++++++++++++++++++++--- gtk2_ardour/sfdb_ui.h | 2 +- libs/ardour/coreaudio_source.cc | 15 +++-- libs/ardour/filesource.cc | 2 +- 5 files changed, 107 insertions(+), 29 deletions(-) diff --git a/SConstruct b/SConstruct index 2dfdd79476..7d07513e46 100644 --- a/SConstruct +++ b/SConstruct @@ -349,7 +349,7 @@ env.Append (BUILDERS = {'Tarball' : tarball_bld}) libraries = { } -libraries['core'] = LibraryInfo (CPPPATH = [ '#libs']) +libraries['core'] = LibraryInfo (CCFLAGS = '-Ilibs') libraries['sndfile'] = LibraryInfo() libraries['sndfile'].ParseConfig('pkg-config --cflags --libs sndfile') @@ -663,15 +663,6 @@ env.Append(CCFLAGS="-Wall") if env['VST']: env.Append(CCFLAGS="-DVST_SUPPORT") - -# check endianness -if sys.byteorder == "big": - print "Host is big endian" - env.Append(CCFLAGS="-DWORDS_BIGENDIAN") -else: - print "Host is little endian" - - # # everybody needs this # diff --git a/gtk2_ardour/sfdb_ui.cc b/gtk2_ardour/sfdb_ui.cc index d8e629b176..c86e26fc12 100644 --- a/gtk2_ardour/sfdb_ui.cc +++ b/gtk2_ardour/sfdb_ui.cc @@ -19,18 +19,27 @@ */ +#include + #include +#include + #include #include #include +#include #include +#include #include "sfdb_ui.h" +#include "gui_thread.h" #include "i18n.h" +using namespace ARDOUR; + std::string length2string (const int32_t frames, const int32_t sample_rate); SoundFileBox::SoundFileBox () @@ -64,6 +73,9 @@ SoundFileBox::SoundFileBox () main_box.pack_start(bottom_box, false, false); field_view.set_size_request(200, 150); + field_view.append_column (_("Field"), label_columns.field); + field_view.append_column_editable (_("Value"), label_columns.data); + top_box.set_homogeneous(true); top_box.pack_start(add_field_btn); top_box.pack_start(remove_field_btn); @@ -83,14 +95,14 @@ SoundFileBox::SoundFileBox () (mem_fun (*this, &SoundFileBox::remove_field_clicked)); field_view.get_selection()->signal_changed().connect (mem_fun (*this, &SoundFileBox::field_selected)); - ARDOUR::Library->fields_changed.connect (mem_fun (*this, &SoundFileBox::setup_fields)); + Library->fields_changed.connect (mem_fun (*this, &SoundFileBox::setup_fields)); show_all(); stop_btn.hide(); } void -SoundFileBox::set_session(ARDOUR::Session* s) +SoundFileBox::set_session(Session* s) { _session = s; @@ -104,6 +116,8 @@ SoundFileBox::set_session(ARDOUR::Session* s) bool SoundFileBox::setup_labels (string filename) { + path = filename; + SNDFILE *sf; sf_info.format = 0; // libsndfile says to clear this before sf_open(). @@ -117,7 +131,7 @@ SoundFileBox::setup_labels (string filename) if (sf_info.frames == 0 && sf_info.channels == 0 && sf_info.samplerate == 0 && sf_info.format == 0 && sf_info.sections == 0) { - /* .. ok, its not a sound file */ + /* .. ok, it's not a sound file */ return false; } @@ -135,20 +149,88 @@ SoundFileBox::setup_labels (string filename) samplerate.set_alignment (0.0f, 0.0f); samplerate.set_text (string_compose("Samplerate: %1", sf_info.samplerate)); + setup_fields (); + return true; } void SoundFileBox::setup_fields () -{} +{ + ENSURE_GUI_THREAD(mem_fun (*this, &SoundFileBox::setup_fields)); + + vector field_list; + Library->get_fields(field_list); + + vector::iterator i; + Gtk::TreeModel::iterator iter; + Gtk::TreeModel::Row row; + for (i = field_list.begin(); i != field_list.end(); ++i) { + string value = Library->get_field(path, *i); + iter = fields->append(); + row = *iter; + + row[label_columns.field] = *i; + row[label_columns.data] = value; + } +} void SoundFileBox::play_btn_clicked () -{} +{ + if (!_session) { + return; + } + + _session->cancel_audition(); + + if (access(path.c_str(), R_OK)) { + warning << string_compose(_("Could not read file: %1 (%2)."), path, strerror(errno)) << endmsg; + return; + } + + static std::map region_cache; + + if (region_cache.find (path) == region_cache.end()) { + AudioRegion::SourceList srclist; + SndFileSource* sfs; + + for (int n = 0; n < sf_info.channels; ++n) { + try { + sfs = new SndFileSource(path+":"+string_compose("%1", n), false); + srclist.push_back(sfs); + + } catch (failed_constructor& err) { + error << _("Could not access soundfile: ") << path << endmsg; + return; + } + } + + if (srclist.empty()) { + return; + } + + string result; + _session->region_name (result, PBD::basename(srclist[0]->name()), false); + AudioRegion* a_region = new AudioRegion(srclist, 0, srclist[0]->length(), result, 0, Region::DefaultFlags, false); + region_cache[path] = a_region; + } + + play_btn.hide(); + stop_btn.show(); + + _session->audition_region(*region_cache[path]); +} void SoundFileBox::stop_btn_clicked () -{} +{ + if (_session) { + _session->cancel_audition(); + play_btn.show(); + stop_btn.hide(); + } +} void SoundFileBox::add_field_clicked () @@ -159,8 +241,14 @@ SoundFileBox::remove_field_clicked () {} void -SoundFileBox::audition_status_changed (bool state) -{} +SoundFileBox::audition_status_changed (bool active) +{ + ENSURE_GUI_THREAD(bind (mem_fun (*this, &SoundFileBox::audition_status_changed), active)); + + if (!active) { + stop_btn_clicked (); + } +} void SoundFileBox::field_selected () @@ -178,7 +266,7 @@ SoundFileBrowser::SoundFileBrowser (std::string title) } void -SoundFileBrowser::set_session (ARDOUR::Session* s) +SoundFileBrowser::set_session (Session* s) { preview.set_session(s); } diff --git a/gtk2_ardour/sfdb_ui.h b/gtk2_ardour/sfdb_ui.h index 279cca3ae4..49f19e847d 100644 --- a/gtk2_ardour/sfdb_ui.h +++ b/gtk2_ardour/sfdb_ui.h @@ -55,6 +55,7 @@ class SoundFileBox : public Gtk::VBox protected: ARDOUR::Session* _session; + std::string path; struct LabelModelColumns : public Gtk::TreeModel::ColumnRecord { @@ -92,7 +93,6 @@ class SoundFileBox : public Gtk::VBox Gtk::Button add_field_btn; Gtk::Button remove_field_btn; - // void fields_refiller (Gtk::CList &clist); void setup_fields (); void play_btn_clicked (); diff --git a/libs/ardour/coreaudio_source.cc b/libs/ardour/coreaudio_source.cc index 67abb60101..6398c5f163 100644 --- a/libs/ardour/coreaudio_source.cc +++ b/libs/ardour/coreaudio_source.cc @@ -86,15 +86,14 @@ CoreAudioSource::init (const string& idstr, bool build_peak) if (channel >= n_channels) { error << string_compose(_("CoreAudioSource: file only contains %1 channels; %2 is invalid as a channel number"), n_channels, channel) << endmsg; - ExtAudioFileDispose(af_ref); + ExtAudioFileDispose(*af_ref); throw failed_constructor(); } int64_t ca_frames; size_t prop_size = sizeof(ca_frames); - err = ExtAudioFileGetProperty(af_ref, kExtAudioFileProperty_FileLengthFrames, - sizeof(ca_frames), &ca_frames); + err = ExtAudioFileGetProperty(*af_ref, kExtAudioFileProperty_FileLengthFrames, prop_size, &ca_frames); if (err) { throw failed_constructor(); } @@ -104,7 +103,7 @@ CoreAudioSource::init (const string& idstr, bool build_peak) if (build_peak) { if (initialize_peakfile (false, file)) { - ExtAudioFileDispose(af_ref); + ExtAudioFileDispose(*af_ref); throw failed_constructor (); } } @@ -116,7 +115,7 @@ CoreAudioSource::~CoreAudioSource () GoingAway (this); /* EMIT SIGNAL */ if (af_ref) { - ExtAudioFileDispose(af_ref); + ExtAudioFileDispose(*af_ref); } if (tmpbuf) { @@ -137,7 +136,7 @@ CoreAudioSource::read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt) co float *ptr; uint32_t real_cnt; - OSStatus err = ExtAudioFileSeek(af_ref, start); + OSStatus err = ExtAudioFileSeek(*af_ref, start); if (err) { error << string_compose(_("CoreAudioSource: could not seek to frame %1 within %2"), start, _name.substr (1)) << endmsg; return 0; @@ -145,7 +144,7 @@ CoreAudioSource::read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt) co if (n_channels == 1) { uint32_t ioNumber = cnt; - err = ExtAudioFileRead(af_ref, &ioNumber, dst); + err = ExtAudioFileRead(*af_ref, &ioNumber, dst); _read_data_count = cnt * sizeof(float); return ioNumber; } @@ -165,7 +164,7 @@ CoreAudioSource::read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt) co } nread = real_cnt; - err = ExtAudioFileRead(af_ext, &nread, tmpbuf); + err = ExtAudioFileRead(*af_ref, &nread, tmpbuf); ptr = tmpbuf + channel; nread /= n_channels; diff --git a/libs/ardour/filesource.cc b/libs/ardour/filesource.cc index fd74f66e76..780f26fed6 100644 --- a/libs/ardour/filesource.cc +++ b/libs/ardour/filesource.cc @@ -78,7 +78,7 @@ char FileSource::bwf_serial_number[13] = "000000000000"; string FileSource::search_path; #undef WE_ARE_BIGENDIAN -#ifdef WORDS_BIGENDIAN +#ifdef __BIG_ENDIAN__ #define WE_ARE_BIGENDIAN true #else #define WE_ARE_BIGENDIAN false