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>
30 #include <glibmm/thread.h>
33 #include "pbd/stateful.h"
34 #include "pbd/statefuldestructible.h"
36 #include "ardour/ardour.h"
40 class Location : public PBD::StatefulDestructible
53 Location (nframes64_t sample_start,
54 nframes64_t sample_end,
55 const std::string &name,
56 Flags bits = Flags(0))
59 _start (sample_start),
71 Location (const Location& other);
72 Location (const XMLNode&);
73 Location* operator= (const Location& other);
75 bool locked() const { return _locked; }
76 void lock() { _locked = true; changed (this); }
77 void unlock() { _locked = false; changed (this); }
79 nframes64_t start() const { return _start; }
80 nframes64_t end() const { return _end; }
81 nframes64_t length() const { return _end - _start; }
83 int set_start (nframes64_t s, bool force = false);
84 int set_end (nframes64_t e, bool force = false);
85 int set (nframes64_t start, nframes64_t end);
87 int move_to (nframes64_t pos);
89 const std::string& name() const { return _name; }
90 void set_name (const std::string &str) { _name = str; name_changed(this); }
92 void set_auto_punch (bool yn, void *src);
93 void set_auto_loop (bool yn, void *src);
94 void set_hidden (bool yn, void *src);
95 void set_cd (bool yn, void *src);
96 void set_is_range_marker (bool yn, void* src);
98 bool is_auto_punch () const { return _flags & IsAutoPunch; }
99 bool is_auto_loop () const { return _flags & IsAutoLoop; }
100 bool is_mark () const { return _flags & IsMark; }
101 bool is_hidden () const { return _flags & IsHidden; }
102 bool is_cd_marker () const { return _flags & IsCDMarker; }
103 bool is_session_range () const { return _flags & IsSessionRange; }
104 bool is_range_marker() const { return _flags & IsRangeMarker; }
105 bool matches (Flags f) const { return _flags & f; }
107 Flags flags () const { return _flags; }
109 PBD::Signal1<void,Location*> name_changed;
110 PBD::Signal1<void,Location*> end_changed;
111 PBD::Signal1<void,Location*> start_changed;
113 PBD::Signal2<void,Location*,void*> FlagsChanged;
115 /* this is sent only when both start&end change at the same time */
117 PBD::Signal1<void,Location*> changed;
119 /* CD Track / CD-Text info */
121 std::map<std::string, std::string> cd_info;
122 XMLNode& cd_info_node (const std::string &, const std::string &);
124 XMLNode& get_state (void);
125 int set_state (const XMLNode&, int version);
134 void set_mark (bool yn);
135 bool set_flag_internal (bool yn, Flags flag);
138 class Locations : public PBD::StatefulDestructible
141 typedef std::list<Location *> LocationList;
146 const LocationList& list() { return locations; }
148 void add (Location *, bool make_current = false);
149 void remove (Location *);
151 void clear_markers ();
152 void clear_ranges ();
154 XMLNode& get_state (void);
155 int set_state (const XMLNode&, int version);
156 Location *get_location_by_id(PBD::ID);
158 Location* auto_loop_location () const;
159 Location* auto_punch_location () const;
160 Location* session_range_location() const;
162 int next_available_name(std::string& result,std::string base);
163 uint32_t num_range_markers() const;
165 int set_current (Location *, bool want_lock = true);
166 Location *current () const { return current_location; }
168 Location* first_location_before (nframes64_t, bool include_special_ranges = false);
169 Location* first_location_after (nframes64_t, bool include_special_ranges = false);
171 void marks_either_side (nframes64_t const, nframes64_t &, nframes64_t &) const;
173 void find_all_between (nframes64_t start, nframes64_t, LocationList&, Location::Flags);
176 ADDITION, ///< a location was added, but nothing else changed
177 REMOVAL, ///< a location was removed, but nothing else changed
178 OTHER ///< something more complicated happened
181 PBD::Signal1<void,Location*> current_changed;
182 /** something changed about the location list; the parameter gives some idea as to what */
183 PBD::Signal1<void,Change> changed;
184 /** a location has been added to the end of the list */
185 PBD::Signal1<void,Location*> added;
186 PBD::Signal1<void,Location*> removed;
187 PBD::Signal1<void,const PBD::PropertyChange&> StateChanged;
189 template<class T> void apply (T& obj, void (T::*method)(LocationList&)) {
190 Glib::Mutex::Lock lm (lock);
191 (obj.*method)(locations);
194 template<class T1, class T2> void apply (T1& obj, void (T1::*method)(LocationList&, T2& arg), T2& arg) {
195 Glib::Mutex::Lock lm (lock);
196 (obj.*method)(locations, arg);
201 LocationList locations;
202 Location *current_location;
203 mutable Glib::Mutex lock;
205 int set_current_unlocked (Location *);
206 void location_changed (Location*);
209 } // namespace ARDOUR
211 #endif /* __ardour_location_h__ */