2 Copyright (C) 2006 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.
20 #ifndef __ardour_audiofilesource_h__
21 #define __ardour_audiofilesource_h__
27 #include <ardour/audiosource.h>
31 class non_existent_source : public std::exception {
33 virtual const char *what() const throw() { return "audio file does not exist"; }
36 struct SoundFileInfo {
40 std::string format_name;
44 class AudioFileSource : public AudioSource {
51 RemovableIfEmpty = 0x10,
52 RemoveAtDestroy = 0x20,
57 virtual ~AudioFileSource ();
59 bool set_name (const std::string& newname) { return (set_source_name(newname, destructive()) == 0); }
60 int set_source_name (Glib::ustring newname, bool destructive);
62 Glib::ustring path() const { return _path; }
63 Glib::ustring peak_path (Glib::ustring audio_path);
64 Glib::ustring find_broken_peakfile (Glib::ustring missing_peak_path,
65 Glib::ustring audio_path);
67 uint16_t channel() const { return _channel; }
69 static void set_peak_dir (Glib::ustring dir) { peak_dir = dir; }
71 static bool get_soundfile_info (Glib::ustring path, SoundFileInfo& _info, std::string& error);
73 static bool safe_file_extension (Glib::ustring path);
75 void set_allow_remove_if_empty (bool yn);
76 void mark_for_remove();
78 /* this block of methods do nothing for regular file sources, but are significant
79 for files used in destructive recording.
82 virtual nframes_t last_capture_start_frame() const { return 0; }
83 virtual void mark_capture_start (nframes_t) {}
84 virtual void mark_capture_end () {}
85 virtual void clear_capture_marks() {}
86 virtual bool one_of_several_channels () const { return false; }
88 virtual int update_header (nframes_t when, struct tm&, time_t) = 0;
89 virtual int flush_header () = 0;
91 int move_to_trash (const Glib::ustring& trash_dir_name);
93 static bool is_empty (Session&, Glib::ustring path);
94 void mark_streaming_write_completed ();
96 void mark_take (Glib::ustring);
97 Glib::ustring take_id() const { return _take_id; }
99 bool is_embedded() const { return _is_embedded; }
101 static void set_bwf_serial_number (int);
103 static void set_search_path (Glib::ustring string);
104 static void set_header_position_offset (nframes_t offset );
106 int setup_peakfile ();
108 static sigc::signal<void> HeaderPositionOffsetChanged;
110 XMLNode& get_state ();
111 int set_state (const XMLNode&);
113 bool destructive() const { return (_flags & Destructive); }
114 virtual bool set_destructive (bool yn) { return false; }
115 bool can_truncate_peaks() const { return !destructive(); }
117 Flag flags() const { return _flags; }
119 void mark_immutable ();
121 /* this should really be protected, but C++ is getting stricter
122 and creating slots from protected member functions is starting
126 virtual void handle_header_position_change () {}
128 bool can_be_analysed() const { return _length > 0; }
132 /* constructor to be called for existing external-to-session files */
134 AudioFileSource (Session&, Glib::ustring path, Flag flags);
136 /* constructor to be called for new in-session files */
138 AudioFileSource (Session&, Glib::ustring path, Flag flags,
139 SampleFormat samp_format, HeaderFormat hdr_format);
141 /* constructor to be called for existing in-session files */
143 AudioFileSource (Session&, const XMLNode&, bool must_exit = true);
145 int init (Glib::ustring idstr, bool must_exist);
149 Glib::ustring _take_id;
150 int64_t timeline_position;
155 static bool determine_embeddedness(Glib::ustring path);
157 static Glib::ustring peak_dir;
158 static Glib::ustring search_path;
160 static char bwf_country_code[3];
161 static char bwf_organization_code[4];
162 static char bwf_serial_number[13];
164 static uint64_t header_position_offset;
166 virtual void set_timeline_position (int64_t pos);
167 virtual void set_header_timeline_position () = 0;
169 bool find (Glib::ustring& path, bool must_exist, bool& is_new, uint16_t& chan);
170 bool removable() const;
171 bool writable() const { return _flags & Writable; }
173 static Sample* get_interleave_buffer (nframes_t size);
176 Glib::ustring old_peak_path (Glib::ustring audio_path);
177 Glib::ustring broken_peak_path (Glib::ustring audio_path);
180 } // namespace ARDOUR
182 #endif /* __ardour_audiofilesource_h__ */