83bc47d7d372b517a177ba696c1be32eeacc18ec
[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 = Flag(0));
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         int update_header (jack_nframes_t when, struct tm&, time_t);
59         int flush_header ();
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         jack_nframes_t read_unlocked (RawMidi* dst, jack_nframes_t start, jack_nframes_t cn) const;
80         jack_nframes_t write_unlocked (RawMidi* dst, jack_nframes_t cnt);
81
82         bool find (std::string path, bool must_exist, bool& is_new);
83         bool removable() const;
84         bool writable() const { return _flags & Writable; }
85         
86         uint16_t      _channel;
87         string        _path;
88         Flag          _flags;
89         string        _take_id;
90         bool          _allow_remove_if_empty;
91         uint64_t      _timeline_position;
92
93         static string _search_path;
94 };
95
96 }; /* namespace ARDOUR */
97
98 #endif /* __ardour_smf_filesource_h__ */
99