export range markers patch (revisited), change selection model, copy-drag tempo+meter...
[ardour.git] / libs / ardour / ardour / location.h
1 /*
2     Copyright (C) 2000 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     $Id$
19 */
20
21 #ifndef __ardour_location_h__
22 #define __ardour_location_h__
23
24 #include <string>
25 #include <list>
26 #include <iostream>
27 #include <map>
28
29 #include <sys/types.h>
30 #include <pthread.h>
31 #include <sigc++/signal.h>
32
33 #include <pbd/lockmonitor.h>
34 #include <pbd/undo.h>
35
36 #include "ardour.h"
37 #include "stateful.h"
38 #include "state_manager.h"
39
40 using std::string;
41
42 namespace ARDOUR {
43
44 class Location : public Stateful, public sigc::trackable
45 {
46   public:
47         enum Flags {
48                 IsMark = 0x1,
49                 IsAutoPunch = 0x2,
50                 IsAutoLoop = 0x4,
51                 IsHidden = 0x8,
52                 IsCDMarker = 0x10,
53                 IsEnd = 0x20,
54                 IsRangeMarker = 0x40
55         };
56
57         Location (jack_nframes_t sample_start,
58                   jack_nframes_t sample_end,
59                   const string &name,
60                   Flags bits = Flags(0))                
61                 
62                 : _name (name),
63                 _start (sample_start),
64                 _end (sample_end),
65                 _flags (bits) { }
66         
67         Location () {
68                 _start = 0;
69                 _end = 0;
70                 _flags = 0;     
71         }
72
73         Location (const Location& other);
74         Location* operator= (const Location& other);
75
76         jack_nframes_t start() { return _start; }
77         jack_nframes_t end() { return _end; }
78         jack_nframes_t length() { return _end - _start; }
79
80         int set_start (jack_nframes_t s);
81         int set_end (jack_nframes_t e);
82         int set (jack_nframes_t start, jack_nframes_t end);
83
84         const string& name() { return _name; }
85         void set_name (const string &str) { _name = str; name_changed(this); }
86
87         void set_auto_punch (bool yn, void *src);
88         void set_auto_loop (bool yn, void *src);
89         void set_hidden (bool yn, void *src);
90         void set_cd (bool yn, void *src);
91         void set_is_end (bool yn, void* src);
92
93         bool is_auto_punch ()  { return _flags & IsAutoPunch; }
94         bool is_auto_loop () { return _flags & IsAutoLoop; }
95         bool is_mark () { return _flags & IsMark; }
96         bool is_hidden () { return _flags & IsHidden; }
97         bool is_cd_marker () { return _flags & IsCDMarker; }
98         bool is_end() { return _flags & IsEnd; }
99         bool is_range_marker() { return _flags & IsRangeMarker; }
100
101         sigc::signal<void,Location*> name_changed;
102         sigc::signal<void,Location*> end_changed;
103         sigc::signal<void,Location*> start_changed;
104
105         sigc::signal<void,Location*,void*> FlagsChanged;
106
107         /* this is sent only when both start&end change at the same time */
108
109         sigc::signal<void,Location*> changed;
110    
111         /* CD Track / CD-Text info */
112
113         std::map<string, string> cd_info;
114         XMLNode& cd_info_node (const string &, const string &);
115
116         XMLNode& get_state (void);
117         int set_state (const XMLNode&);
118
119   private:
120         string        _name;
121         jack_nframes_t     _start;
122         jack_nframes_t     _end;
123         uint32_t _flags;
124
125         void set_mark (bool yn);
126         bool set_flag_internal (bool yn, Flags flag);
127 };
128
129 class Locations : public Stateful, public StateManager
130 {
131   public:
132         typedef std::list<Location *> LocationList;
133
134         Locations ();
135         ~Locations ();
136
137         void add (Location *, bool make_current = false);
138         void remove (Location *);
139         void clear ();
140         void clear_markers ();
141         void clear_ranges ();
142
143         XMLNode& get_state (void);
144         int set_state (const XMLNode&);
145
146         Location* auto_loop_location () const;
147         Location* auto_punch_location () const;
148         Location* end_location() const;
149
150         uint32_t num_range_markers() const;
151
152         int set_current (Location *, bool want_lock = true);
153         Location *current () const { return current_location; }
154
155         Location *first_location_before (jack_nframes_t);
156         Location *first_location_after (jack_nframes_t);
157
158         sigc::signal<void,Location*> current_changed;
159         sigc::signal<void>           changed;
160         sigc::signal<void,Location*> added;
161         sigc::signal<void,Location*> removed;
162
163         template<class T> void apply (T& obj, void (T::*method)(LocationList&)) {
164                 LockMonitor lm (lock, __LINE__, __FILE__);
165                 (obj.*method)(locations);
166         }
167
168         template<class T1, class T2> void apply (T1& obj, void (T1::*method)(LocationList&, T2& arg), T2& arg) {
169                 LockMonitor lm (lock, __LINE__, __FILE__);
170                 (obj.*method)(locations, arg);
171         }
172
173         UndoAction get_memento () const;
174
175   private:
176
177         struct State : public ARDOUR::StateManager::State {
178             LocationList locations;
179             LocationList states;
180
181             State (std::string why) : ARDOUR::StateManager::State (why) {}
182         };
183
184         LocationList       locations;
185         Location          *current_location;
186         mutable PBD::Lock  lock;
187
188         int set_current_unlocked (Location *);
189         void location_changed (Location*);
190
191         Change   restore_state (StateManager::State&);
192         StateManager::State* state_factory (std::string why) const;
193 };
194
195 }; /* namespace ARDOUR */
196
197 #endif /* __ardour_location_h__ */