00f8cb26de1f2b541013a0867e40dd952613621f
[ardour.git] / libs / ardour / ardour / smf_source.h
1 /*
2     Copyright (C) 2006 Paul Davis
3         Written by Dave Robillard, 2006
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 */
20
21 #ifndef __ardour_smf_filesource_h__ 
22 #define __ardour_smf_filesource_h__
23
24 #include <time.h>
25
26 #include <ardour/midi_source.h>
27
28 namespace ARDOUR {
29
30 /** Standard Midi File (Type 0) Source */
31 class SMFSource : public MidiSource {
32   public:
33         enum Flag {
34                 Writable = 0x1,
35                 CanRename = 0x2,
36                 Broadcast = 0x4,
37                 Removable = 0x8,
38                 RemovableIfEmpty = 0x10,
39                 RemoveAtDestroy = 0x20,
40                 BuildPeaks = 0x40
41         };
42         
43         /** Constructor for existing external-to-session files */
44         SMFSource (std::string path, Flag flags);
45
46         /* Constructor for existing in-session files */
47         SMFSource (const XMLNode&);
48
49         virtual ~SMFSource ();
50
51         int set_name (string newname, bool destructive);
52
53         string path() const { return _path; }
54
55         void set_allow_remove_if_empty (bool yn);
56         void mark_for_remove();
57
58         virtual int update_header (jack_nframes_t when, struct tm&, time_t) = 0;
59         virtual int flush_header () = 0;
60
61         int move_to_trash (const string trash_dir_name);
62
63         static bool is_empty (string path);
64         void mark_streaming_write_completed ();
65
66         void   mark_take (string);
67         string take_id() const { return _take_id; }
68
69         static void set_search_path (string);
70         static void set_header_position_offset (jack_nframes_t offset, bool negative);
71
72         XMLNode& get_state ();
73         int set_state (const XMLNode&);
74
75   protected:
76
77         int init (string idstr, bool must_exist);
78
79         bool find (std::string path, bool must_exist, bool& is_new);
80         bool removable() const;
81         bool writable() const { return _flags & Writable; }
82         
83         uint16_t      _channel;
84         string        _path;
85         Flag          _flags;
86         string        _take_id;
87         bool          _allow_remove_if_empty;
88         uint64_t      _timeline_position;
89
90         static string _search_path;
91 };
92
93 }; /* namespace ARDOUR */
94
95 #endif /* __ardour_smf_filesource_h__ */
96