2 Copyright (C) 2000 Paul Davis
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.
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.
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.
20 #ifndef __ardour_location_h__
21 #define __ardour_location_h__
28 #include <sys/types.h>
29 #include <sigc++/signal.h>
31 #include <glibmm/thread.h>
34 #include <pbd/stateful.h>
35 #include <pbd/statefuldestructible.h>
37 #include <ardour/ardour.h>
43 class Location : public PBD::StatefulDestructible
57 Location (nframes_t sample_start,
60 Flags bits = Flags(0))
63 _start (sample_start),
75 Location (const Location& other);
76 Location (const XMLNode&);
77 Location* operator= (const Location& other);
79 bool locked() const { return _locked; }
80 void lock() { _locked = true; changed (this); }
81 void unlock() { _locked = false; changed (this); }
83 nframes_t start() const { return _start; }
84 nframes_t end() const { return _end; }
85 nframes_t length() const { return _end - _start; }
87 int set_start (nframes_t s);
88 int set_end (nframes_t e);
89 int set (nframes_t start, nframes_t end);
91 int move_to (nframes_t pos);
93 const string& name() const { return _name; }
94 void set_name (const string &str) { _name = str; name_changed(this); }
96 void set_auto_punch (bool yn, void *src);
97 void set_auto_loop (bool yn, void *src);
98 void set_hidden (bool yn, void *src);
99 void set_cd (bool yn, void *src);
100 void set_is_end (bool yn, void* src);
101 void set_is_start (bool yn, void* src);
102 void set_is_range_marker (bool yn, void* src);
104 bool is_auto_punch () const { return _flags & IsAutoPunch; }
105 bool is_auto_loop () const { return _flags & IsAutoLoop; }
106 bool is_mark () const { return _flags & IsMark; }
107 bool is_hidden () const { return _flags & IsHidden; }
108 bool is_cd_marker () const { return _flags & IsCDMarker; }
109 bool is_end() const { return _flags & IsEnd; }
110 bool is_start() const { return _flags & IsStart; }
111 bool is_range_marker() const { return _flags & IsRangeMarker; }
112 bool matches (Flags f) const { return _flags & f; }
114 sigc::signal<void,Location*> name_changed;
115 sigc::signal<void,Location*> end_changed;
116 sigc::signal<void,Location*> start_changed;
118 sigc::signal<void,Location*,void*> FlagsChanged;
120 /* this is sent only when both start&end change at the same time */
122 sigc::signal<void,Location*> changed;
124 /* CD Track / CD-Text info */
126 std::map<string, string> cd_info;
127 XMLNode& cd_info_node (const string &, const string &);
129 XMLNode& get_state (void);
130 int set_state (const XMLNode&);
139 void set_mark (bool yn);
140 bool set_flag_internal (bool yn, Flags flag);
143 class Locations : public PBD::StatefulDestructible
146 typedef std::list<Location *> LocationList;
151 const LocationList& list() { return locations; }
153 void add (Location *, bool make_current = false);
154 void remove (Location *);
156 void clear_markers ();
157 void clear_ranges ();
159 XMLNode& get_state (void);
160 int set_state (const XMLNode&);
161 Location *get_location_by_id(PBD::ID);
163 Location* auto_loop_location () const;
164 Location* auto_punch_location () const;
165 Location* end_location() const;
166 Location* start_location() const;
168 int next_available_name(string& result,string base);
169 uint32_t num_range_markers() const;
171 int set_current (Location *, bool want_lock = true);
172 Location *current () const { return current_location; }
174 Location *first_location_before (nframes_t, bool include_special_ranges = false);
175 Location *first_location_after (nframes_t, bool include_special_ranges = false);
177 nframes_t first_mark_before (nframes_t, bool include_special_ranges = false);
178 nframes_t first_mark_after (nframes_t, bool include_special_ranges = false);
180 void find_all_between (nframes64_t start, nframes64_t, LocationList&, Location::Flags);
182 sigc::signal<void,Location*> current_changed;
183 sigc::signal<void> changed;
184 sigc::signal<void,Location*> added;
185 sigc::signal<void,Location*> removed;
186 sigc::signal<void,Change> StateChanged;
188 template<class T> void apply (T& obj, void (T::*method)(LocationList&)) {
189 Glib::Mutex::Lock lm (lock);
190 (obj.*method)(locations);
193 template<class T1, class T2> void apply (T1& obj, void (T1::*method)(LocationList&, T2& arg), T2& arg) {
194 Glib::Mutex::Lock lm (lock);
195 (obj.*method)(locations, arg);
200 LocationList locations;
201 Location *current_location;
202 mutable Glib::Mutex lock;
204 int set_current_unlocked (Location *);
205 void location_changed (Location*);
208 } // namespace ARDOUR
210 #endif /* __ardour_location_h__ */