more file add/remove ops related to sndfile changes
[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 <time.h>
24
25 #include <ardour/audiosource.h>
26
27 namespace ARDOUR {
28
29 struct SoundFileInfo {
30     float       samplerate;
31     uint16_t    channels;
32     int64_t     length;
33     std::string format_name;
34 };
35
36 class AudioFileSource : public AudioSource {
37   public:
38         enum Flag {
39                 Writable = 0x1,
40                 CanRename = 0x2,
41                 Broadcast = 0x4,
42                 Removable = 0x8,
43                 RemovableIfEmpty = 0x10,
44                 RemoveAtDestroy = 0x20,
45                 BuildPeaks = 0x40
46         };
47
48         virtual ~AudioFileSource ();
49
50         int set_name (string newname, bool destructive);
51
52         string path() const { return _path; }
53         string peak_path (string audio_path);
54         string old_peak_path (string audio_path);
55
56         static void set_peak_dir (string dir) { peak_dir = dir; }
57
58         /* factory for an existing but not-used-in-session audio file. this exists
59            because there maybe multiple back-end derivations of AudioFileSource,
60            some of which can handle formats that cannot be handled by others.
61            For example, CoreAudioFileSource can handle MP3 files, which SndFileSource
62            cannot.
63          */
64
65         static AudioFileSource* create (string path_plus_channel);
66         static AudioFileSource* create (const XMLNode&);
67
68         static bool get_soundfile_info (string path, SoundFileInfo& _info, string& error);
69
70         void set_allow_remove_if_empty (bool yn);
71         void mark_for_remove();
72
73         /* this block of methods do nothing for regular file sources, but are significant
74            for files used in destructive recording.
75         */
76
77         virtual jack_nframes_t last_capture_start_frame() const { return 0; }
78         virtual void           mark_capture_start (jack_nframes_t) {}
79         virtual void           mark_capture_end () {}
80         virtual void           clear_capture_marks() {}
81
82         virtual int update_header (jack_nframes_t when, struct tm&, time_t) = 0;
83         virtual int flush_header () = 0;
84
85         int move_to_trash (const string trash_dir_name);
86
87         static bool is_empty (string path);
88         void mark_streaming_write_completed ();
89
90         void   mark_take (string);
91         string take_id() const { return _take_id; }
92
93         static void set_bwf_country_code (string x);
94         static void set_bwf_organization_code (string x);
95         static void set_bwf_serial_number (int);
96         
97         static void set_search_path (string);
98         static void set_header_position_offset (jack_nframes_t offset, bool negative);
99
100         static sigc::signal<void,struct tm*, time_t> HeaderPositionOffsetChanged;
101
102         XMLNode& get_state ();
103         int set_state (const XMLNode&);
104
105         /* this should really be protected, but C++ is getting stricter
106            and creating slots from protected member functions is starting
107            to cause issues.
108         */
109
110         void handle_header_position_change (struct tm*, time_t tnow);
111
112   protected:
113         
114         /* constructor to be called for existing external-to-session files */
115
116         AudioFileSource (std::string path, Flag flags);
117
118         /* constructor to be called for new in-session files */
119
120         AudioFileSource (std::string path, Flag flags,
121                          SampleFormat samp_format, HeaderFormat hdr_format);
122
123         /* constructor to be called for existing in-session files */
124
125         AudioFileSource (const XMLNode&);
126
127         int init (string idstr, bool must_exist);
128
129         uint16_t       channel;
130         string        _path;
131         Flag          _flags;
132         string        _take_id;
133         bool           allow_remove_if_empty;
134         uint64_t       timeline_position;
135
136         static string peak_dir;
137         static string search_path;
138
139         static char bwf_country_code[3];
140         static char bwf_organization_code[4];
141         static char bwf_serial_number[13];
142
143         static uint64_t header_position_offset;
144         static bool     header_position_negative;
145
146         virtual void set_timeline_position (jack_nframes_t pos);
147         virtual void set_header_timeline_position () = 0;
148
149         bool find (std::string path, bool must_exist, bool& is_new);
150         bool removable() const;
151         bool writable() const { return _flags & Writable; }
152 };
153
154 }; /* namespace ARDOUR */
155
156 #endif /* __ardour_audiofilesource_h__ */
157