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.
24 #include <gtkmm2ext/gtk_ui.h>
26 #include "imageframe_time_axis_view.h"
27 #include "imageframe_time_axis_group.h"
28 #include "imageframe_view.h"
29 #include "imageframe_time_axis.h"
30 #include "canvas-simplerect.h"
31 #include "region_selection.h"
32 #include "public_editor.h"
33 #include "rgb_macros.h"
34 #include "gui_thread.h"
38 using namespace ARDOUR ;
39 using namespace Editing;
41 //---------------------------------------------------------------------------------------//
42 // Constructor / Desctructor
45 * Constructs a new ImageFrameTimeAxisView.
47 * @param ifta the parent ImageFrameTimeAxis of this view helper
49 ImageFrameTimeAxisView::ImageFrameTimeAxisView (ImageFrameTimeAxis& tv)
51 canvas_group (*_trackview.canvas_display),
52 canvas_rect (canvas_group, 0.0, 0.0, 1000000.0, tv.height)
54 region_color = _trackview.color() ;
55 stream_base_color = color_map[cImageTrackBase] ;
57 canvas_rect.property_outline_color_rgba() = color_map[cImageTrackOutline];
58 canvas_rect.property_fill_color_rgba() = stream_base_color;
60 canvas_rect.signal_event().connect (bind (mem_fun (_trackview.editor, &PublicEditor::canvas_imageframe_view_event), (ArdourCanvas::Item*) &canvas_rect, &tv));
62 _samples_per_unit = _trackview.editor.get_current_zoom() ;
64 _trackview.editor.ZoomChanged.connect (mem_fun(*this, &ImageFrameTimeAxisView::reset_samples_per_unit)) ;
66 selected_imageframe_group = 0 ;
67 selected_imageframe_view = 0 ;
72 * Responsible for destroying all items tat may have been added to this time axis
74 ImageFrameTimeAxisView::~ImageFrameTimeAxisView()
76 // Destroy all the ImageFrameGroups that we have
78 for(ImageFrameGroupList::iterator iter = imageframe_groups.begin(); iter != imageframe_groups.end(); ++iter)
80 ImageFrameTimeAxisGroup* iftag = (*iter) ;
82 ImageFrameGroupList::iterator next = iter ;
85 // remove the front element
86 imageframe_groups.erase(iter) ;
97 //---------------------------------------------------------------------------------------//
101 * Sets the height of the time axis view and the item upon it
103 * @param height the new height
106 ImageFrameTimeAxisView::set_height (gdouble h)
108 /* limit the values to something sane-ish */
109 if (h < 10.0 || h > 1000.0) {
113 canvas_rect.property_y2() = h ;
116 for(ImageFrameGroupList::const_iterator citer = imageframe_groups.begin(); citer != imageframe_groups.end(); ++citer)
118 (*citer)->set_item_heights(h) ;
125 * Sets the position of this view helper on the canvas
127 * @param x the x position upon the canvas
128 * @param y the y position npon the canvas
131 ImageFrameTimeAxisView::set_position (gdouble x, gdouble y)
134 canvas_group.property_x() = x;
135 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 ImageFrameTimeAxisView::set_samples_per_unit (gdouble spp)
153 _samples_per_unit = spp;
155 for(ImageFrameGroupList::const_iterator citer = imageframe_groups.begin(); citer != imageframe_groups.end(); ++citer)
157 (*citer)->set_item_samples_per_units(spp) ;
164 * Sets the color of the items contained uopn this view helper
166 * @param color the new base color
169 ImageFrameTimeAxisView::apply_color(Gdk::Color& color)
171 region_color = color ;
172 for(ImageFrameGroupList::const_iterator citer = imageframe_groups.begin(); citer != imageframe_groups.end(); citer++)
174 (*citer)->apply_item_color(region_color) ;
180 * convenience method to re-get the samples per unit and tell items upon this view
184 ImageFrameTimeAxisView::reset_samples_per_unit ()
186 set_samples_per_unit (_trackview.editor.get_current_zoom());
190 //---------------------------------------------------------------------------------------//
191 // Child ImageFrameTimeAxisGroup Accessors/Mutators
194 * Adds an ImageFrameTimeAxisGroup to the list of items upon this time axis view helper
195 * the new ImageFrameTimeAxisGroup is returned
197 * @param group_id the unique id of the new group
198 * @param src the identity of the object that initiated the change
200 ImageFrameTimeAxisGroup*
201 ImageFrameTimeAxisView::add_imageframe_group(std::string group_id, void* src)
203 ImageFrameTimeAxisGroup* iftag = 0 ;
205 //check that there is not already a group with that id
206 if(get_named_imageframe_group(group_id) != 0)
212 iftag = new ImageFrameTimeAxisGroup(*this, group_id) ;
214 imageframe_groups.push_front(iftag) ;
216 iftag->GoingAway.connect(bind(mem_fun(*this,&ImageFrameTimeAxisView::remove_imageframe_group), iftag, (void*)this)) ;
218 ImageFrameGroupAdded(iftag, src) ; /* EMIT_SIGNAL */
225 * Returns the named ImageFrameTimeAxisGroup or 0 if the named group does not exist on this view helper
227 * @param group_id the unique id of the group to search for
228 * @return the named ImageFrameTimeAxisGroup, or 0 if it is not held upon this view
230 ImageFrameTimeAxisGroup*
231 ImageFrameTimeAxisView::get_named_imageframe_group(std::string group_id)
233 ImageFrameTimeAxisGroup* iftag = 0 ;
235 for(ImageFrameGroupList::iterator i = imageframe_groups.begin(); i != imageframe_groups.end(); ++i)
237 if (((ImageFrameTimeAxisGroup*)*i)->get_group_name() == group_id)
239 iftag = ((ImageFrameTimeAxisGroup*)*i) ;
249 * Removes and returns the named ImageFrameTimeAxisGroup from the list of ImageFrameTimeAxisGroup held by this view helper
251 * @param group_id the ImageFrameTimeAxisGroup unique id to remove
252 * @param src the identity of the object that initiated the change
253 * @see add_imageframe_group
255 ImageFrameTimeAxisGroup*
256 ImageFrameTimeAxisView::remove_named_imageframe_group(std::string group_id, void* src)
258 ImageFrameTimeAxisGroup* removed = 0 ;
260 for(ImageFrameGroupList::iterator iter = imageframe_groups.begin(); iter != imageframe_groups.end(); ++iter)
262 if(((ImageFrameTimeAxisGroup*)*iter)->get_group_name() == group_id)
265 imageframe_groups.erase(iter) ;
267 if(removed == selected_imageframe_group)
269 selected_imageframe_group = 0 ;
272 ImageFrameGroupRemoved(removed->get_group_name(), src) ; /* EMIT_SIGNAL */
274 // break from the for loop
285 * Removes the specified ImageFrameTimeAxisGroup from the list of ImageFrameTimeAxisGroups upon this TimeAxis.
287 * @param iftag the ImageFrameView to remove
290 ImageFrameTimeAxisView::remove_imageframe_group(ImageFrameTimeAxisGroup* iftag, void* src)
292 ENSURE_GUI_THREAD(bind (mem_fun(*this, &ImageFrameTimeAxisView::remove_imageframe_group), iftag, src));
294 ImageFrameGroupList::iterator i;
295 if((i = find (imageframe_groups.begin(), imageframe_groups.end(), iftag)) != imageframe_groups.end())
297 imageframe_groups.erase(i) ;
299 ImageFrameGroupRemoved(iftag->get_group_name(), src) ; /* EMIT_SIGNAL */
306 //---------------------------------------------------------------------------------------//
307 // Selected group methods
310 * Sets the currently selected group upon this time axis
312 * @param ifv the item to set selected
315 ImageFrameTimeAxisView::set_selected_imageframe_group(ImageFrameTimeAxisGroup* iftag)
317 if(selected_imageframe_group)
319 selected_imageframe_group->set_selected(false) ;
322 selected_imageframe_group = iftag ;
323 selected_imageframe_group->set_selected(true) ;
327 * Clears the currently selected image frame group unpo this time axis
331 ImageFrameTimeAxisView::clear_selected_imageframe_group()
333 if(selected_imageframe_group)
335 selected_imageframe_group->set_selected(false) ;
337 selected_imageframe_group = 0 ;
341 * Returns the currently selected group upon this time axis
343 * @return the currently selected group upon this time axis
345 ImageFrameTimeAxisGroup*
346 ImageFrameTimeAxisView::get_selected_imageframe_group() const
348 return(selected_imageframe_group) ;
351 //---------------------------------------------------------------------------------------//
352 // Selected item methods
355 * Sets the currently selected imag frame view item
357 * @param iftag the group the selected item is part
358 * @param ifv the selected item
361 ImageFrameTimeAxisView::set_selected_imageframe_view(ImageFrameTimeAxisGroup* iftag, ImageFrameView* ifv)
363 set_selected_imageframe_group(iftag) ;
365 if(selected_imageframe_view)
367 selected_imageframe_view->set_selected(false) ;
370 selected_imageframe_view = ifv ;
371 selected_imageframe_view->set_selected(true) ;
375 * Clears the currently selected image frame view item
379 ImageFrameTimeAxisView::clear_selected_imageframe_item(bool clear_group)
383 clear_selected_imageframe_group() ;
386 if(selected_imageframe_view)
388 selected_imageframe_view->set_selected(false) ;
390 selected_imageframe_view = 0 ;
394 * Returns the currently selected image frame view item upon this time axis
396 * @return the currently selected image frame view item
399 ImageFrameTimeAxisView::get_selected_imageframe_view() const
401 return(selected_imageframe_view) ;
408 ImageFrameTimeAxisView::set_imageframe_duration_sec(double sec)
410 if(selected_imageframe_group && selected_imageframe_view)
412 selected_imageframe_view->set_duration((nframes_t) (sec * _trackview.editor.current_session()->frame_rate()), this) ;
419 * Removes the currently selected ImageFrame view item
421 * @param src the identity of the object that initiated the change
422 * @see add_imageframe_group
425 ImageFrameTimeAxisView::remove_selected_imageframe_item(void* src)
427 if(selected_imageframe_group && selected_imageframe_view)
429 ImageFrameView* temp_item = selected_imageframe_view ;
430 selected_imageframe_group->remove_imageframe_item(temp_item, src) ;
432 // XXX although we have removed the item from the group, we need the group id still set within the
433 // item as the remove method requires this data when telling others about the deletion
434 // to fully specify the item we need the track, group and item id
435 selected_imageframe_view->remove_this_item(src) ;
436 clear_selected_imageframe_item(false) ;