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
54 Location (nframes64_t sample_start,
55 nframes64_t sample_end,
56 const std::string &name,
57 Flags bits = Flags(0))
60 _start (sample_start),
72 Location (const Location& other);
73 Location (const XMLNode&);
74 Location* operator= (const Location& other);
76 bool locked() const { return _locked; }
77 void lock() { _locked = true; changed (this); }
78 void unlock() { _locked = false; changed (this); }
80 nframes64_t start() const { return _start; }
81 nframes64_t end() const { return _end; }
82 nframes64_t length() const { return _end - _start; }
84 int set_start (nframes64_t s);
85 int set_end (nframes64_t e);
86 int set (nframes64_t start, nframes64_t end);
88 int move_to (nframes64_t pos);
90 const std::string& name() const { return _name; }
91 void set_name (const std::string &str) { _name = str; name_changed(this); }
93 void set_auto_punch (bool yn, void *src);
94 void set_auto_loop (bool yn, void *src);
95 void set_hidden (bool yn, void *src);
96 void set_cd (bool yn, void *src);
97 void set_is_end (bool yn, void* src);
98 void set_is_start (bool yn, void* src);
99 void set_is_range_marker (bool yn, void* src);
101 bool is_auto_punch () const { return _flags & IsAutoPunch; }
102 bool is_auto_loop () const { return _flags & IsAutoLoop; }
103 bool is_mark () const { return _flags & IsMark; }
104 bool is_hidden () const { return _flags & IsHidden; }
105 bool is_cd_marker () const { return _flags & IsCDMarker; }
106 bool is_end() const { return _flags & IsEnd; }
107 bool is_start() const { return _flags & IsStart; }
108 bool is_range_marker() const { return _flags & IsRangeMarker; }
109 bool matches (Flags f) const { return _flags & f; }
111 PBD::Signal1<void,Location*> name_changed;
112 PBD::Signal1<void,Location*> end_changed;
113 PBD::Signal1<void,Location*> start_changed;
115 PBD::Signal2<void,Location*,void*> FlagsChanged;
117 /* this is sent only when both start&end change at the same time */
119 PBD::Signal1<void,Location*> changed;
121 /* CD Track / CD-Text info */
123 std::map<std::string, std::string> cd_info;
124 XMLNode& cd_info_node (const std::string &, const std::string &);
126 XMLNode& get_state (void);
127 int set_state (const XMLNode&, int version);
136 void set_mark (bool yn);
137 bool set_flag_internal (bool yn, Flags flag);
140 class Locations : public PBD::StatefulDestructible
143 typedef std::list<Location *> LocationList;
148 const LocationList& list() { return locations; }
150 void add (Location *, bool make_current = false);
151 void remove (Location *);
153 void clear_markers ();
154 void clear_ranges ();
156 XMLNode& get_state (void);
157 int set_state (const XMLNode&, int version);
158 Location *get_location_by_id(PBD::ID);
160 Location* auto_loop_location () const;
161 Location* auto_punch_location () const;
162 Location* end_location() const;
163 Location* start_location() const;
165 int next_available_name(std::string& result,std::string base);
166 uint32_t num_range_markers() const;
168 int set_current (Location *, bool want_lock = true);
169 Location *current () const { return current_location; }
171 Location *first_location_before (nframes64_t, bool include_special_ranges = false);
172 Location *first_location_after (nframes64_t, bool include_special_ranges = false);
174 void marks_either_side (nframes64_t const, nframes64_t &, nframes64_t &) const;
176 void find_all_between (nframes64_t start, nframes64_t, LocationList&, Location::Flags);
178 PBD::Signal1<void,Location*> current_changed;
179 PBD::Signal0<void> changed;
180 PBD::Signal1<void,Location*> added;
181 PBD::Signal1<void,Location*> removed;
182 PBD::Signal1<void,Change> StateChanged;
184 template<class T> void apply (T& obj, void (T::*method)(LocationList&)) {
185 Glib::Mutex::Lock lm (lock);
186 (obj.*method)(locations);
189 template<class T1, class T2> void apply (T1& obj, void (T1::*method)(LocationList&, T2& arg), T2& arg) {
190 Glib::Mutex::Lock lm (lock);
191 (obj.*method)(locations, arg);
196 LocationList locations;
197 Location *current_location;
198 mutable Glib::Mutex lock;
200 int set_current_unlocked (Location *);
201 void location_changed (Location*);
204 } // namespace ARDOUR
206 #endif /* __ardour_location_h__ */