First pass of sfdb tag searching. Not functional, but very very close.
[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     int64_t     timecode;
35 };
36
37 class AudioFileSource : public AudioSource {
38   public:
39         enum Flag {
40                 Writable = 0x1,
41                 CanRename = 0x2,
42                 Broadcast = 0x4,
43                 Removable = 0x8,
44                 RemovableIfEmpty = 0x10,
45                 RemoveAtDestroy = 0x20,
46                 NoPeakFile = 0x40,
47                 Destructive = 0x80
48         };
49
50         virtual ~AudioFileSource ();
51
52         int set_name (string newname, bool destructive);
53
54         string path() const { return _path; }
55         string peak_path (string audio_path);
56         string old_peak_path (string audio_path);
57
58         static void set_peak_dir (string dir) { peak_dir = dir; }
59
60         static bool get_soundfile_info (string path, SoundFileInfo& _info, string& error);
61
62         static bool safe_file_extension (string path);
63
64         void set_allow_remove_if_empty (bool yn);
65         void mark_for_remove();
66
67         /* this block of methods do nothing for regular file sources, but are significant
68            for files used in destructive recording.
69         */
70
71         virtual nframes_t last_capture_start_frame() const { return 0; }
72         virtual void           mark_capture_start (nframes_t) {}
73         virtual void           mark_capture_end () {}
74         virtual void           clear_capture_marks() {}
75
76         virtual int update_header (nframes_t when, struct tm&, time_t) = 0;
77         virtual int flush_header () = 0;
78
79         int move_to_trash (const string trash_dir_name);
80
81         static bool is_empty (Session&, string path);
82         void mark_streaming_write_completed ();
83
84         void   mark_take (string);
85         string take_id() const { return _take_id; }
86
87         bool is_embedded() const { return _is_embedded; }
88
89         static void set_bwf_serial_number (int);
90         
91         static void set_search_path (string);
92         static void set_header_position_offset (nframes_t offset );
93
94         int setup_peakfile ();
95
96         static sigc::signal<void> HeaderPositionOffsetChanged;
97
98         XMLNode& get_state ();
99         int set_state (const XMLNode&);
100
101         bool destructive() const { return (_flags & Destructive); }
102         virtual bool set_destructive (bool yn) { return false; }
103
104         /* this should really be protected, but C++ is getting stricter
105            and creating slots from protected member functions is starting
106            to cause issues.
107         */
108
109         virtual void handle_header_position_change () {}
110
111   protected:
112         
113         /* constructor to be called for existing external-to-session files */
114
115         AudioFileSource (Session&, std::string path, Flag flags);
116
117         /* constructor to be called for new in-session files */
118
119         AudioFileSource (Session&, std::string path, Flag flags,
120                          SampleFormat samp_format, HeaderFormat hdr_format);
121
122         /* constructor to be called for existing in-session files */
123
124         AudioFileSource (Session&, const XMLNode&);
125
126         int init (string idstr, bool must_exist);
127
128         uint16_t       channel;
129         string        _path;
130         Flag          _flags;
131         string        _take_id;
132         int64_t       timeline_position;
133         bool           file_is_new;
134
135         bool          _is_embedded;
136         static bool determine_embeddedness(string path);
137
138         static string peak_dir;
139         static string search_path;
140
141         static char bwf_country_code[3];
142         static char bwf_organization_code[4];
143         static char bwf_serial_number[13];
144
145         static uint64_t header_position_offset;
146
147         virtual void set_timeline_position (int64_t pos);
148         virtual void set_header_timeline_position () = 0;
149
150         bool find (std::string path, bool must_exist, bool& is_new);
151         bool removable() const;
152         bool writable() const { return _flags & Writable; }
153 };
154
155 } // namespace ARDOUR
156
157 #endif /* __ardour_audiofilesource_h__ */
158