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"
37 #include "ardour/session_handle.h"
41 class Location : public SessionHandleRef, public PBD::StatefulDestructible
55 Location (Session &, framepos_t, framepos_t, const std::string &, Flags bits = Flags(0));
56 Location (const Location& other);
57 Location (Session &, const XMLNode&);
58 Location* operator= (const Location& other);
60 bool locked() const { return _locked; }
64 framepos_t start() const { return _start; }
65 framepos_t end() const { return _end; }
66 framepos_t length() const { return _end - _start; }
68 int set_start (framepos_t s, bool force = false, bool allow_bbt_recompute = true);
69 int set_end (framepos_t e, bool force = false, bool allow_bbt_recompute = true);
70 int set (framepos_t start, framepos_t end, bool allow_bbt_recompute = true);
72 int move_to (framepos_t pos);
74 const std::string& name() const { return _name; }
75 void set_name (const std::string &str) { _name = str; name_changed(this); }
77 void set_auto_punch (bool yn, void *src);
78 void set_auto_loop (bool yn, void *src);
79 void set_hidden (bool yn, void *src);
80 void set_cd (bool yn, void *src);
81 void set_is_range_marker (bool yn, void* src);
83 bool is_auto_punch () const { return _flags & IsAutoPunch; }
84 bool is_auto_loop () const { return _flags & IsAutoLoop; }
85 bool is_mark () const { return _flags & IsMark; }
86 bool is_hidden () const { return _flags & IsHidden; }
87 bool is_cd_marker () const { return _flags & IsCDMarker; }
88 bool is_session_range () const { return _flags & IsSessionRange; }
89 bool is_range_marker() const { return _flags & IsRangeMarker; }
90 bool matches (Flags f) const { return _flags & f; }
92 Flags flags () const { return _flags; }
94 PBD::Signal1<void,Location*> name_changed;
95 PBD::Signal1<void,Location*> end_changed;
96 PBD::Signal1<void,Location*> start_changed;
98 PBD::Signal1<void,Location*> LockChanged;
99 PBD::Signal2<void,Location*,void*> FlagsChanged;
100 PBD::Signal1<void,Location*> PositionLockStyleChanged;
102 /* this is sent only when both start and end change at the same time */
103 PBD::Signal1<void,Location*> changed;
105 /* CD Track / CD-Text info */
107 std::map<std::string, std::string> cd_info;
108 XMLNode& cd_info_node (const std::string &, const std::string &);
110 XMLNode& get_state (void);
111 int set_state (const XMLNode&, int version);
113 PositionLockStyle position_lock_style() const { return _position_lock_style; }
114 void set_position_lock_style (PositionLockStyle ps);
115 void recompute_frames_from_bbt ();
120 Timecode::BBT_Time _bbt_start;
122 Timecode::BBT_Time _bbt_end;
125 PositionLockStyle _position_lock_style;
127 void set_mark (bool yn);
128 bool set_flag_internal (bool yn, Flags flag);
129 void recompute_bbt_from_frames ();
132 class Locations : public SessionHandleRef, public PBD::StatefulDestructible
135 typedef std::list<Location *> LocationList;
137 Locations (Session &);
140 const LocationList& list() { return locations; }
142 void add (Location *, bool make_current = false);
143 void remove (Location *);
145 void clear_markers ();
146 void clear_ranges ();
148 XMLNode& get_state (void);
149 int set_state (const XMLNode&, int version);
150 Location *get_location_by_id(PBD::ID);
152 Location* auto_loop_location () const;
153 Location* auto_punch_location () const;
154 Location* session_range_location() const;
156 int next_available_name(std::string& result,std::string base);
157 uint32_t num_range_markers() const;
159 int set_current (Location *, bool want_lock = true);
160 Location *current () const { return current_location; }
162 Location* first_location_before (framepos_t, bool include_special_ranges = false);
163 Location* first_location_after (framepos_t, bool include_special_ranges = false);
165 void marks_either_side (framepos_t const, framepos_t &, framepos_t &) const;
167 void find_all_between (framepos_t start, framepos_t, LocationList&, Location::Flags);
170 ADDITION, ///< a location was added, but nothing else changed
171 REMOVAL, ///< a location was removed, but nothing else changed
172 OTHER ///< something more complicated happened
175 PBD::Signal1<void,Location*> current_changed;
176 /** something changed about the location list; the parameter gives some idea as to what */
177 PBD::Signal1<void,Change> changed;
178 /** a location has been added to the end of the list */
179 PBD::Signal1<void,Location*> added;
180 PBD::Signal1<void,Location*> removed;
181 PBD::Signal1<void,const PBD::PropertyChange&> StateChanged;
183 template<class T> void apply (T& obj, void (T::*method)(LocationList&)) {
184 Glib::Mutex::Lock lm (lock);
185 (obj.*method)(locations);
188 template<class T1, class T2> void apply (T1& obj, void (T1::*method)(LocationList&, T2& arg), T2& arg) {
189 Glib::Mutex::Lock lm (lock);
190 (obj.*method)(locations, arg);
195 LocationList locations;
196 Location *current_location;
197 mutable Glib::Mutex lock;
199 int set_current_unlocked (Location *);
200 void location_changed (Location*);
203 } // namespace ARDOUR
205 #endif /* __ardour_location_h__ */