1 /* 2 * Copyright (C) 2009-2011 Carl Hetherington <carl@carlh.net> 3 * Copyright (C) 2009-2011 David Robillard <d@drobilla.net> 4 * Copyright (C) 2009-2015 Paul Davis <paul@linuxaudiosystems.com> 5 * Copyright (C) 2015-2017 Robin Gareus <robin@gareus.org> 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; either version 2 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License along 18 * with this program; if not, write to the Free Software Foundation, Inc., 19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 */ 21 22 #ifndef __ardour_filesource_h__ 23 #define __ardour_filesource_h__ 24 25 #include <list> 26 #include <string> 27 #include <exception> 28 #include <time.h> 29 #include "ardour/source.h" 30 31 namespace ARDOUR { 32 33 class LIBARDOUR_API MissingSource : public std::exception 34 { 35 public: MissingSource(const std::string & p,DataType t)36 MissingSource (const std::string& p, DataType t) throw () 37 : path (p), type (t) {} throw()38 ~MissingSource() throw() {} 39 what()40 virtual const char *what() const throw() { return "source file does not exist"; } 41 42 std::string path; 43 DataType type; 44 }; 45 46 /** A source associated with a file on disk somewhere */ 47 class LIBARDOUR_API FileSource : virtual public Source { 48 public: 49 virtual ~FileSource (); 50 path()51 const std::string& path() const { return _path; } 52 53 virtual bool safe_file_extension (const std::string& path) const = 0; 54 55 int move_to_trash (const std::string& trash_dir_name); 56 void mark_take (const std::string& id); 57 void mark_immutable (); 58 void mark_immutable_except_write(); 59 void mark_nonremovable (); 60 within_session()61 bool within_session () const { return _within_session; } channel()62 uint16_t channel() const { return _channel; } gain()63 float gain() const { return _gain; } 64 65 virtual void set_gain (float g, bool temporarily = false) { _gain = g; } 66 67 int set_state (const XMLNode&, int version); 68 69 int set_source_name (const std::string& newname); 70 71 static bool find (Session&, DataType type, const std::string& path, 72 bool must_exist, bool& is_new, uint16_t& chan, 73 std::string& found_path); 74 75 static bool find_2X (Session&, DataType type, const std::string& path, 76 bool must_exist, bool& is_new, uint16_t& chan, 77 std::string& found_path); 78 79 void inc_use_count (); 80 bool removable () const; 81 bool is_stub () const; 82 origin()83 const std::string& origin() const { return _origin; } set_origin(std::string const & o)84 void set_origin (std::string const& o) { _origin = o; } 85 86 virtual void set_path (const std::string&); 87 void replace_file (const std::string&); 88 89 static PBD::Signal2<int,std::string,std::vector<std::string> > AmbiguousFileName; 90 91 void existence_check (); 92 virtual void prevent_deletion (); 93 94 /** Rename the file on disk referenced by this source to \p newname */ 95 int rename (const std::string& name); 96 97 virtual void close () = 0; 98 99 protected: 100 FileSource (Session& session, DataType type, 101 const std::string& path, 102 const std::string& origin, 103 Source::Flag flags = Source::Flag(0)); 104 105 FileSource (Session& session, const XMLNode& node, bool must_exist); 106 107 virtual int init (const std::string& idstr, bool must_exist); 108 move_dependents_to_trash()109 virtual int move_dependents_to_trash() { return 0; } 110 void set_within_session_from_path (const std::string&); 111 112 std::string _path; 113 bool _file_is_new; 114 uint16_t _channel; 115 bool _within_session; 116 std::string _origin; 117 float _gain; 118 }; 119 120 } // namespace ARDOUR 121 122 #endif /* __ardour_filesource_h__ */ 123 124