attempt to remove confusion and errors caused by unclear semantics of _is_embedded...
[ardour.git] / libs / ardour / ardour / audiofilesource.h
1 /*
2     Copyright (C) 2006 Paul Davis
3
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.
8
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.
13
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.
17
18 */
19
20 #ifndef __ardour_audiofilesource_h__
21 #define __ardour_audiofilesource_h__
22
23 #include <exception>
24 #include <time.h>
25 #include "ardour/audiosource.h"
26 #include "ardour/file_source.h"
27
28 namespace ARDOUR {
29
30 struct SoundFileInfo {
31     float       samplerate;
32     uint16_t    channels;
33     int64_t     length;
34     std::string format_name;
35     int64_t     timecode;
36 };
37
38 class AudioFileSource : public AudioSource, public FileSource {
39 public:
40         virtual ~AudioFileSource ();
41
42         bool set_name (const std::string& newname) {
43                 return (set_source_name(newname, destructive()) == 0);
44         }
45
46         Glib::ustring peak_path (Glib::ustring audio_path);
47         Glib::ustring find_broken_peakfile (Glib::ustring missing_peak_path,
48                         Glib::ustring audio_path);
49
50         static void set_peak_dir (Glib::ustring dir) { peak_dir = dir; }
51
52         static bool get_soundfile_info (Glib::ustring path, SoundFileInfo& _info, std::string& error);
53
54         bool safe_file_extension (const Glib::ustring& path) const {
55                 return safe_audio_file_extension(path);
56         }
57
58         /* this block of methods do nothing for regular file sources, but are significant
59            for files used in destructive recording.
60         */
61         virtual sframes_t last_capture_start_frame() const { return 0; }
62         virtual void      mark_capture_start (sframes_t) {}
63         virtual void      mark_capture_end () {}
64         virtual void      clear_capture_marks() {}
65         virtual bool      one_of_several_channels () const { return false; }
66
67         virtual int update_header (sframes_t when, struct tm&, time_t) = 0;
68         virtual int flush_header () = 0;
69
70         void mark_streaming_write_completed ();
71
72         int setup_peakfile ();
73
74         XMLNode& get_state ();
75         int set_state (const XMLNode&, int version);
76
77         bool can_truncate_peaks() const { return !destructive(); }
78         bool can_be_analysed() const    { return _length > 0; }
79
80         static bool safe_audio_file_extension (const Glib::ustring& path);
81
82         static bool is_empty (Session&, Glib::ustring path);
83
84         static void set_bwf_serial_number (int);
85         static void set_header_position_offset (nframes_t offset );
86
87         static sigc::signal<void> HeaderPositionOffsetChanged;
88
89 protected:
90         /** Constructor to be called for existing external-to-session files */
91         AudioFileSource (Session&, const Glib::ustring& path, Source::Flag flags);
92
93         /** Constructor to be called for new in-session files */
94         AudioFileSource (Session&, const Glib::ustring& path, Source::Flag flags,
95                         SampleFormat samp_format, HeaderFormat hdr_format);
96
97         /** Constructor to be called for existing in-session files */
98         AudioFileSource (Session&, const XMLNode&, bool must_exist = true);
99
100         int init (const Glib::ustring& idstr, bool must_exist);
101
102         virtual void set_header_timeline_position () = 0;
103         virtual void handle_header_position_change () {}
104
105         int move_dependents_to_trash();
106
107         static Sample* get_interleave_buffer (nframes_t size);
108
109         static Glib::ustring peak_dir;
110
111         static char bwf_country_code[3];
112         static char bwf_organization_code[4];
113         static char bwf_serial_number[13];
114
115         static uint64_t header_position_offset;
116
117   private:
118         Glib::ustring old_peak_path (Glib::ustring audio_path);
119         Glib::ustring broken_peak_path (Glib::ustring audio_path);
120 };
121
122 } // namespace ARDOUR
123
124 #endif /* __ardour_audiofilesource_h__ */
125