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"
41 class Location : public PBD::StatefulDestructible
55 Location (nframes64_t sample_start,
56 nframes64_t sample_end,
57 const std::string &name,
58 Flags bits = Flags(0))
61 _start (sample_start),
73 Location (const Location& other);
74 Location (const XMLNode&);
75 Location* operator= (const Location& other);
77 bool locked() const { return _locked; }
78 void lock() { _locked = true; changed (this); }
79 void unlock() { _locked = false; changed (this); }
81 nframes64_t start() const { return _start; }
82 nframes64_t end() const { return _end; }
83 nframes64_t length() const { return _end - _start; }
85 int set_start (nframes64_t s);
86 int set_end (nframes64_t e);
87 int set (nframes64_t start, nframes64_t end);
89 int move_to (nframes64_t pos);
91 const std::string& name() const { return _name; }
92 void set_name (const std::string &str) { _name = str; name_changed(this); }
94 void set_auto_punch (bool yn, void *src);
95 void set_auto_loop (bool yn, void *src);
96 void set_hidden (bool yn, void *src);
97 void set_cd (bool yn, void *src);
98 void set_is_end (bool yn, void* src);
99 void set_is_start (bool yn, void* src);
100 void set_is_range_marker (bool yn, void* src);
102 bool is_auto_punch () const { return _flags & IsAutoPunch; }
103 bool is_auto_loop () const { return _flags & IsAutoLoop; }
104 bool is_mark () const { return _flags & IsMark; }
105 bool is_hidden () const { return _flags & IsHidden; }
106 bool is_cd_marker () const { return _flags & IsCDMarker; }
107 bool is_end() const { return _flags & IsEnd; }
108 bool is_start() const { return _flags & IsStart; }
109 bool is_range_marker() const { return _flags & IsRangeMarker; }
110 bool matches (Flags f) const { return _flags & f; }
112 sigc::signal<void,Location*> name_changed;
113 sigc::signal<void,Location*> end_changed;
114 sigc::signal<void,Location*> start_changed;
116 sigc::signal<void,Location*,void*> FlagsChanged;
118 /* this is sent only when both start&end change at the same time */
120 sigc::signal<void,Location*> changed;
122 /* CD Track / CD-Text info */
124 std::map<std::string, std::string> cd_info;
125 XMLNode& cd_info_node (const std::string &, const std::string &);
127 XMLNode& get_state (void);
128 int set_state (const XMLNode&, int version);
137 void set_mark (bool yn);
138 bool set_flag_internal (bool yn, Flags flag);
141 class Locations : public PBD::StatefulDestructible
144 typedef std::list<Location *> LocationList;
149 const LocationList& list() { return locations; }
151 void add (Location *, bool make_current = false);
152 void remove (Location *);
154 void clear_markers ();
155 void clear_ranges ();
157 XMLNode& get_state (void);
158 int set_state (const XMLNode&, int version);
159 Location *get_location_by_id(PBD::ID);
161 Location* auto_loop_location () const;
162 Location* auto_punch_location () const;
163 Location* end_location() const;
164 Location* start_location() const;
166 int next_available_name(std::string& result,std::string base);
167 uint32_t num_range_markers() const;
169 int set_current (Location *, bool want_lock = true);
170 Location *current () const { return current_location; }
172 Location *first_location_before (nframes64_t, bool include_special_ranges = false);
173 Location *first_location_after (nframes64_t, bool include_special_ranges = false);
175 void marks_either_side (nframes64_t const, nframes64_t &, nframes64_t &) const;
177 void find_all_between (nframes64_t start, nframes64_t, LocationList&, Location::Flags);
179 sigc::signal<void,Location*> current_changed;
180 sigc::signal<void> changed;
181 sigc::signal<void,Location*> added;
182 sigc::signal<void,Location*> removed;
183 sigc::signal<void,Change> StateChanged;
185 template<class T> void apply (T& obj, void (T::*method)(LocationList&)) {
186 Glib::Mutex::Lock lm (lock);
187 (obj.*method)(locations);
190 template<class T1, class T2> void apply (T1& obj, void (T1::*method)(LocationList&, T2& arg), T2& arg) {
191 Glib::Mutex::Lock lm (lock);
192 (obj.*method)(locations, arg);
197 LocationList locations;
198 Location *current_location;
199 mutable Glib::Mutex lock;
201 int set_current_unlocked (Location *);
202 void location_changed (Location*);
205 } // namespace ARDOUR
207 #endif /* __ardour_location_h__ */