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"
37 #include "pbd/enumwriter.h"
39 #include "ardour/debug.h"
40 #include "ardour/session.h"
41 #include "ardour/source.h"
42 #include "ardour/transient_detector.h"
47 using namespace ARDOUR;
50 Source::Source (Session& s, DataType type, const string& name, Flag flags)
51 : SessionObject(s, name)
54 , _timeline_position(0)
59 fix_writable_flags ();
62 Source::Source (Session& s, const XMLNode& node)
63 : SessionObject(s, "unnamed source")
64 , _type(DataType::AUDIO)
65 , _flags (Flag (Writable|CanRename))
66 , _timeline_position(0)
72 if (set_state (node, Stateful::loading_state_version) || _type == DataType::NIL) {
73 throw failed_constructor();
76 fix_writable_flags ();
81 DEBUG_TRACE (DEBUG::Destruction, string_compose ("Source %1 destructor %2\n", _name, this));
85 Source::fix_writable_flags ()
87 if (!_session.writable()) {
88 _flags = Flag (_flags & ~(Writable|Removable|RemovableIfEmpty|RemoveAtDestroy|CanRename));
95 XMLNode *node = new XMLNode ("Source");
98 node->add_property ("name", name());
99 node->add_property ("type", _type.to_string());
100 node->add_property (X_("flags"), enum_2_string (_flags));
101 _id.print (buf, sizeof (buf));
102 node->add_property ("id", buf);
104 if (_timestamp != 0) {
105 snprintf (buf, sizeof (buf), "%ld", _timestamp);
106 node->add_property ("timestamp", buf);
113 Source::set_state (const XMLNode& node, int /*version*/)
115 const XMLProperty* prop;
117 if ((prop = node.property ("name")) != 0) {
118 _name = prop->value();
123 if ((prop = node.property ("id")) != 0) {
124 _id = prop->value ();
129 if ((prop = node.property ("type")) != 0) {
130 _type = DataType(prop->value());
133 if ((prop = node.property ("timestamp")) != 0) {
134 sscanf (prop->value().c_str(), "%ld", &_timestamp);
137 if ((prop = node.property (X_("flags"))) != 0) {
138 _flags = Flag (string_2_enum (prop->value(), _flags));
144 /* old style, from the period when we had DestructiveFileSource */
145 if ((prop = node.property (X_("destructive"))) != 0) {
146 _flags = Flag (_flags | Destructive);
153 Source::has_been_analysed() const
155 Glib::Mutex::Lock lm (_analysis_lock);
160 Source::set_been_analysed (bool yn)
163 Glib::Mutex::Lock lm (_analysis_lock);
168 load_transients (get_transients_path());
169 AnalysisChanged(); // EMIT SIGNAL
174 Source::load_transients (const string& path)
176 ifstream file (path.c_str());
187 while (file.good()) {
191 nframes64_t frame = (nframes64_t) floor (val * _session.frame_rate());
192 transients.push_back (frame);
200 Source::get_transients_path () const
202 vector<string> parts;
205 /* old sessions may not have the analysis directory */
207 _session.ensure_subdirs ();
209 s = _session.analysis_dir ();
214 s += TransientDetector::operational_identifier();
217 return Glib::build_filename (parts);
221 Source::check_for_analysis_data_on_disk ()
223 /* looks to see if the analysis files for this source are on disk.
224 if so, mark us already analysed.
227 string path = get_transients_path ();
230 if (!Glib::file_test (path, Glib::FILE_TEST_EXISTS)) {
234 // XXX add other tests here as appropriate
236 set_been_analysed (ok);
241 Source::mark_for_remove ()
243 // This operation is not allowed for sources for destructive tracks or out-of-session files.
245 /* XXX need a way to detect _within_session() condition here - move it from FileSource?
248 if ((_flags & Destructive)) {
252 _flags = Flag (_flags | Removable | RemoveAtDestroy);
256 Source::set_timeline_position (int64_t pos)
258 _timeline_position = pos;
262 Source::set_allow_remove_if_empty (bool yn)
269 _flags = Flag (_flags | RemovableIfEmpty);
271 _flags = Flag (_flags & ~RemovableIfEmpty);