2 Copyright (C) 2003 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.
23 #include <gtkmm2ext/gtk_ui.h>
25 #include "marker_time_axis_view.h"
26 #include "marker_time_axis.h"
27 #include "marker_view.h"
28 #include "imageframe_view.h"
29 #include "imageframe_time_axis.h"
30 #include "canvas-simplerect.h"
31 #include "public_editor.h"
32 #include "rgb_macros.h"
33 #include "gui_thread.h"
34 #include "ardour_ui.h"
38 using namespace ARDOUR ;
39 using namespace Editing;
41 //---------------------------------------------------------------------------------------//
42 // Constructor / Desctructor
45 * Construct a new MarkerTimeAxisView helper time axis helper
47 * @param mta the TimeAxsiView that this objbect is the helper for
49 MarkerTimeAxisView::MarkerTimeAxisView(MarkerTimeAxis& tv)
52 region_color = _trackview.color();
53 stream_base_color = ARDOUR_UI::config()->canvasvar_MarkerTrack.get();
55 canvas_group = new ArdourCanvas::Group (*_trackview.canvas_display);
57 canvas_rect = new ArdourCanvas::SimpleRect (*canvas_group);
58 canvas_rect->property_x1() = 0.0;
59 canvas_rect->property_y1() = 0.0;
60 canvas_rect->property_x2() = max_frames;
61 canvas_rect->property_y2() = (double)20;
62 canvas_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerTrack.get();
63 canvas_rect->property_fill_color_rgba() = stream_base_color;
65 canvas_rect->signal_event().connect (bind (mem_fun (_trackview.editor, &PublicEditor::canvas_marker_time_axis_view_event), canvas_rect, &_trackview));
67 _samples_per_unit = _trackview.editor.get_current_zoom() ;
69 _trackview.editor.ZoomChanged.connect (mem_fun(*this, &MarkerTimeAxisView::reset_samples_per_unit));
74 * Reposinsibly for destroying all marker items that may have been added to this time axis view
77 MarkerTimeAxisView::~MarkerTimeAxisView()
79 // destroy everything upon this view
80 for(MarkerViewList::iterator iter = marker_view_list.begin(); iter != marker_view_list.end(); ++iter)
82 MarkerView* mv = (*iter) ;
84 MarkerViewList::iterator next = iter ;
86 marker_view_list.erase(iter) ;
102 //---------------------------------------------------------------------------------------//
106 * Sets the height of the time axis view and the item upon it
108 * @param height the new height
111 MarkerTimeAxisView::set_height(gdouble h)
113 if (h < 10.0 || h > 1000.0) {
117 canvas_rect->property_y2() = h;
119 for (MarkerViewList::iterator i = marker_view_list.begin(); i != marker_view_list.end(); ++i) {
120 (*i)->set_y_position_and_height(0, h);
127 * Sets the position of this view helper on the canvas
129 * @param x the x position upon the canvas
130 * @param y the y position upon the canvas
133 MarkerTimeAxisView::set_position(gdouble x, gdouble y)
135 canvas_group->property_x() = x;
136 canvas_group->property_y() = y;
141 * Sets the current samples per unit.
142 * this method tells each item upon the time axis of the change
144 * @param spu the new samples per canvas unit value
147 MarkerTimeAxisView::set_samples_per_unit(gdouble spp)
153 _samples_per_unit = spp ;
155 for(MarkerViewList::iterator i = marker_view_list.begin(); i != marker_view_list.end(); ++i)
157 (*i)->set_samples_per_unit(spp) ;
163 * Sets the color of the items contained upon this view helper
165 * @param color the new base color
168 MarkerTimeAxisView::apply_color(Gdk::Color& color)
170 region_color = color;
172 for (MarkerViewList::iterator i = marker_view_list.begin(); i != marker_view_list.end(); i++)
174 (*i)->set_color (region_color) ;
179 //---------------------------------------------------------------------------------------//
180 // Child MarkerView Accessors/Mutators
183 * Adds a marker view to the list of items upon this time axis view helper
184 * the new MarkerView is returned
186 * @param ifv the ImageFrameView that the new item is marking up
187 * @param mark_text the text to be displayed uopn the new marker item
188 * @param mark_id the unique id of the new item
189 * @param start the position the new item should be placed upon the time line
190 * @param duration the duration the new item should be placed upon the timeline
191 * @param src the identity of the object that initiated the change
194 MarkerTimeAxisView::add_marker_view(ImageFrameView* ifv, std::string mark_type, std::string mark_id, nframes_t start, nframes_t dur, void* src)
196 if(ifv->has_marker_view_item(mark_id))
201 MarkerView* mv = new MarkerView(canvas_group,
204 _trackview.editor.get_current_zoom(),
211 ifv->add_marker_view_item(mv, src) ;
212 marker_view_list.push_front(mv) ;
214 mv->GoingAway.connect(bind (mem_fun(*this,&MarkerTimeAxisView::remove_marker_view), (void*)this)) ;
216 MarkerViewAdded(mv,src) ; /* EMIT_SIGNAL */
222 * Returns the named MarkerView or 0 if the named marker does not exist
224 * @param item_id the unique id of the item to search for
225 * @return the named MarkerView, or 0 if it is not held upon this view
228 MarkerTimeAxisView::get_named_marker_view(std::string item_id)
232 for(MarkerViewList::iterator i = marker_view_list.begin(); i != marker_view_list.end(); ++i)
234 if(((MarkerView*)*i)->get_item_name() == item_id)
236 mv = ((MarkerView*)*i) ;
244 * Removes the currently selected MarverView
245 * Note that this method actually destroys the MarkerView too.
246 * We assume that since we own the object, we are allowed to do this
248 * @param src the identity of the object that initiated the change
249 * @see add_marker_view
252 MarkerTimeAxisView::remove_selected_marker_view(void* src)
254 std::string removed ;
256 if (selected_time_axis_item)
258 MarkerViewList::iterator i ;
259 if((i = find (marker_view_list.begin(), marker_view_list.end(), selected_time_axis_item)) != marker_view_list.end())
261 marker_view_list.erase(i) ;
263 MarkerViewRemoved(selected_time_axis_item->get_item_name(),src) ; /* EMIT_SIGNAL */
265 delete(selected_time_axis_item) ;
266 selected_time_axis_item = 0 ;
271 //No selected marker view
276 * Removes and returns the named MarkerView from the list of MarkerView held by this view helper
278 * @param item_id the MarkerView unique id to remove
279 * @param src the identity of the object that initiated the change
280 * @see add_marker_view
283 MarkerTimeAxisView::remove_named_marker_view(std::string item_id, void* src)
287 MarkerViewList::iterator i = marker_view_list.begin() ;
289 for(MarkerViewList::iterator iter = marker_view_list.begin(); iter != marker_view_list.end(); ++iter)
291 if(((MarkerView*)*i)->get_item_name() == item_id)
293 mv = ((MarkerView*)*i) ;
294 marker_view_list.erase(i) ;
296 MarkerViewRemoved(mv->get_item_name(), src) ; /* EMIT_SIGNAL */
298 // break from the for loop
308 * Removes mv from the list of MarkerView upon this TimeAxis
310 * @param mv the MarkerView to remove
311 * @param src the identity of the object that initiated the change
314 MarkerTimeAxisView::remove_marker_view(MarkerView* mv, void* src)
316 ENSURE_GUI_THREAD(bind (mem_fun(*this, &MarkerTimeAxisView::remove_marker_view), mv, src));
318 MarkerViewList::iterator i;
320 if((i = find (marker_view_list.begin(), marker_view_list.end(), mv)) != marker_view_list.end()) {
321 marker_view_list.erase(i) ;
323 // Assume this remove happened locally, else use remove_named_marker_time_axis
324 // let listeners know that the named MarkerTimeAxis has been removed
325 MarkerViewRemoved(mv->get_item_name(), src) ; /* EMIT_SIGNAL */
331 * Sets the duration of the selected MarkerView to the specified number of seconds
333 * @param sec the duration to set the MArkerView to, in seconds
336 MarkerTimeAxisView::set_marker_duration_sec(double sec)
338 if(get_selected_time_axis_item() != 0)
340 get_selected_time_axis_item()->set_duration((nframes_t) (sec * _trackview.editor.current_session()->frame_rate()), this) ;
345 //---------------------------------------------------------------------------------------//
346 // Selected item methods
349 * Sets the currently selected item upon this time axis
351 * @param mv the item to set selected
354 MarkerTimeAxisView::set_selected_time_axis_item(MarkerView* mv)
356 selected_time_axis_item = mv ;
360 * Clears any selected item upon this time axis
364 MarkerTimeAxisView::clear_selected_time_axis_item()
366 selected_time_axis_item = 0 ;
370 * Returnsthe currently selected item upon this time axis
372 * @return the currently selected item pon this time axis
375 MarkerTimeAxisView::get_selected_time_axis_item()
377 return(selected_time_axis_item) ;
384 * convenience method to re-get the samples per unit and tell items upon this view
388 MarkerTimeAxisView::reset_samples_per_unit ()
390 set_samples_per_unit(_trackview.editor.get_current_zoom()) ;