2 Copyright (C) 2000 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 #include <glibmm/thread.h>
33 #include <glibmm/miscutils.h>
34 #include <glibmm/fileutils.h>
35 #include <pbd/xml++.h>
36 #include <pbd/pthread_utils.h>
38 #include <ardour/source.h>
39 #include <ardour/playlist.h>
40 #include <ardour/session.h>
41 #include <ardour/transient_detector.h>
46 using namespace ARDOUR;
48 Source::Source (Session& s, const string& name, DataType type)
49 : SessionObject(s, name)
52 // not true.. is this supposed to be an assertion?
53 //assert(_name.find("/") == string::npos);
61 Source::Source (Session& s, const XMLNode& node)
62 : SessionObject(s, "unnamed source")
63 , _type(DataType::AUDIO)
70 if (set_state (node) || _type == DataType::NIL) {
71 throw failed_constructor();
83 XMLNode *node = new XMLNode ("Source");
86 node->add_property ("name", _name);
87 node->add_property ("type", _type.to_string());
88 _id.print (buf, sizeof (buf));
89 node->add_property ("id", buf);
91 if (_timestamp != 0) {
92 snprintf (buf, sizeof (buf), "%ld", _timestamp);
93 node->add_property ("timestamp", buf);
100 Source::set_state (const XMLNode& node)
102 const XMLProperty* prop;
104 if ((prop = node.property ("name")) != 0) {
105 _name = prop->value();
110 if ((prop = node.property ("id")) != 0) {
111 _id = prop->value ();
116 if ((prop = node.property ("type")) != 0) {
117 _type = DataType(prop->value());
120 if ((prop = node.property ("timestamp")) != 0) {
121 sscanf (prop->value().c_str(), "%ld", &_timestamp);
124 // Don't think this is valid, absolute paths fail
125 //assert(_name.find("/") == string::npos);
131 Source::update_length (nframes_t pos, nframes_t cnt)
133 if (pos + cnt > _length) {
139 Source::add_playlist (boost::shared_ptr<Playlist> pl)
141 std::pair<PlaylistMap::iterator,bool> res;
142 std::pair<boost::shared_ptr<Playlist>, uint32_t> newpair (pl, 1);
143 Glib::Mutex::Lock lm (_playlist_lock);
145 res = _playlists.insert (newpair);
148 /* it already existed, bump count */
152 pl->GoingAway.connect (bind (mem_fun (*this, &Source::remove_playlist), boost::weak_ptr<Playlist> (pl)));
156 Source::remove_playlist (boost::weak_ptr<Playlist> wpl)
158 boost::shared_ptr<Playlist> pl (wpl.lock());
164 PlaylistMap::iterator x;
165 Glib::Mutex::Lock lm (_playlist_lock);
167 if ((x = _playlists.find (pl)) != _playlists.end()) {
171 _playlists.erase (x);
177 Source::used () const
179 return _playlists.size();
183 Source::has_been_analysed() const
185 Glib::Mutex::Lock lm (_analysis_lock);
190 Source::set_been_analysed (bool yn)
193 Glib::Mutex::Lock lm (_analysis_lock);
198 load_transients (get_transients_path());
199 AnalysisChanged(); // EMIT SIGNAL
204 Source::load_transients (const string& path)
206 ifstream file (path.c_str());
217 while (file.good()) {
221 nframes64_t frame = (nframes64_t) floor (val * _session.frame_rate());
222 transients.push_back (frame);
230 Source::get_transients_path () const
232 vector<string> parts;
235 /* old sessions may not have the analysis directory */
237 _session.ensure_subdirs ();
239 s = _session.analysis_dir ();
244 s += TransientDetector::operational_identifier();
247 return Glib::build_filename (parts);
251 Source::check_for_analysis_data_on_disk ()
253 /* looks to see if the analysis files for this source are on disk.
254 if so, mark us already analysed.
257 string path = get_transients_path ();
260 if (!Glib::file_test (path, Glib::FILE_TEST_EXISTS)) {
264 // XXX add other tests here as appropriate
266 set_been_analysed (ok);