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 "region_selection.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 * 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.current_height())
54 region_color = _trackview.color() ;
55 stream_base_color = ARDOUR_UI::config()->get_canvasvar_ImageTrack() ;
57 canvas_rect.property_outline_color_rgba() = ARDOUR_UI::config()->get_canvasvar_ImageTrack();
58 canvas_rect.property_fill_color_rgba() = stream_base_color;
60 canvas_rect.signal_event().connect (sigc::bind (sigc::mem_fun (_trackview.editor, &PublicEditor::canvas_imageframe_view_event), (ArdourCanvas::Item*) &canvas_rect, &tv));
62 _samples_per_pixel = _trackview.editor.get_current_zoom() ;
64 _trackview.editor.ZoomChanged.connect (sigc::mem_fun(*this, &ImageFrameTimeAxisView::reset_samples_per_pixel)) ;
66 selected_imageframe_group = 0 ;
67 selected_imageframe_view = 0 ;
69 ImageFrameTimeAxisGroup::CatchDeletion.connect (*this, boost::bind (&ImageFrameTimeAxisView::remove_imageframe_group, this, _1), gui_context());
74 * Responsible for destroying all items tat may have been added to this time axis
76 ImageFrameTimeAxisView::~ImageFrameTimeAxisView()
78 // Destroy all the ImageFrameGroups that we have
80 for(ImageFrameGroupList::iterator iter = imageframe_groups.begin(); iter != imageframe_groups.end(); ++iter)
82 ImageFrameTimeAxisGroup* iftag = (*iter) ;
84 ImageFrameGroupList::iterator next = iter ;
87 // remove the front element
88 imageframe_groups.erase(iter) ;
99 //---------------------------------------------------------------------------------------//
103 * Sets the height of the time axis view and the item upon it
105 * @param height the new height
108 ImageFrameTimeAxisView::set_height (gdouble h)
110 /* limit the values to something sane-ish */
111 if (h < 10.0 || h > 1000.0) {
115 canvas_rect.property_y2() = h ;
118 for(ImageFrameGroupList::const_iterator citer = imageframe_groups.begin(); citer != imageframe_groups.end(); ++citer)
120 (*citer)->set_item_heights(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 npon the canvas
133 ImageFrameTimeAxisView::set_position (gdouble x, gdouble y)
136 canvas_group.property_x() = x;
137 canvas_group.property_y() = y;
143 * Sets the current samples per unit.
144 * this method tells each item upon the time axis of the change
146 * @param spu the new samples per canvas unit value
149 ImageFrameTimeAxisView::set_samples_per_pixel (double fpp)
155 _samples_per_pixel = fpp;
157 for (ImageFrameGroupList::const_iterator citer = imageframe_groups.begin(); citer != imageframe_groups.end(); ++citer) {
158 (*citer)->set_item_samples_per_pixels (fpp);
165 * Sets the color of the items contained uopn this view helper
167 * @param color the new base color
170 ImageFrameTimeAxisView::apply_color(Gdk::Color& color)
172 region_color = color ;
173 for(ImageFrameGroupList::const_iterator citer = imageframe_groups.begin(); citer != imageframe_groups.end(); citer++)
175 (*citer)->apply_item_color(region_color) ;
181 * convenience method to re-get the samples per unit and tell items upon this view
185 ImageFrameTimeAxisView::reset_samples_per_pixel ()
187 set_samples_per_pixel (_trackview.editor.get_current_zoom());
191 //---------------------------------------------------------------------------------------//
192 // Child ImageFrameTimeAxisGroup Accessors/Mutators
195 * Adds an ImageFrameTimeAxisGroup to the list of items upon this time axis view helper
196 * the new ImageFrameTimeAxisGroup is returned
198 * @param group_id the unique id of the new group
199 * @param src the identity of the object that initiated the change
201 ImageFrameTimeAxisGroup*
202 ImageFrameTimeAxisView::add_imageframe_group(std::string group_id, void* src)
204 ImageFrameTimeAxisGroup* iftag = 0 ;
206 //check that there is not already a group with that id
207 if(get_named_imageframe_group(group_id) != 0)
213 iftag = new ImageFrameTimeAxisGroup(*this, group_id) ;
214 imageframe_groups.push_front(iftag) ;
215 ImageFrameGroupAdded(iftag, src) ; /* EMIT_SIGNAL */
222 * Returns the named ImageFrameTimeAxisGroup or 0 if the named group does not exist on this view helper
224 * @param group_id the unique id of the group to search for
225 * @return the named ImageFrameTimeAxisGroup, or 0 if it is not held upon this view
227 ImageFrameTimeAxisGroup*
228 ImageFrameTimeAxisView::get_named_imageframe_group(std::string group_id)
230 ImageFrameTimeAxisGroup* iftag = 0 ;
232 for(ImageFrameGroupList::iterator i = imageframe_groups.begin(); i != imageframe_groups.end(); ++i)
234 if (((ImageFrameTimeAxisGroup*)*i)->get_group_name() == group_id)
236 iftag = ((ImageFrameTimeAxisGroup*)*i) ;
246 * Removes and returns the named ImageFrameTimeAxisGroup from the list of ImageFrameTimeAxisGroup held by this view helper
248 * @param group_id the ImageFrameTimeAxisGroup unique id to remove
249 * @param src the identity of the object that initiated the change
250 * @see add_imageframe_group
252 ImageFrameTimeAxisGroup*
253 ImageFrameTimeAxisView::remove_named_imageframe_group(std::string group_id, void* src)
255 ImageFrameTimeAxisGroup* removed = 0 ;
257 for(ImageFrameGroupList::iterator iter = imageframe_groups.begin(); iter != imageframe_groups.end(); ++iter)
259 if(((ImageFrameTimeAxisGroup*)*iter)->get_group_name() == group_id)
262 imageframe_groups.erase(iter) ;
264 if(removed == selected_imageframe_group)
266 selected_imageframe_group = 0 ;
269 ImageFrameGroupRemoved(removed->get_group_name(), src) ; /* EMIT_SIGNAL */
271 // break from the for loop
282 * Removes the specified ImageFrameTimeAxisGroup from the list of ImageFrameTimeAxisGroups upon this TimeAxis.
284 * @param iftag the ImageFrameView to remove
287 ImageFrameTimeAxisView::remove_imageframe_group(ImageFrameTimeAxisGroup* iftag, void* src)
289 ENSURE_GUI_THREAD (*this, &ImageFrameTimeAxisView::remove_imageframe_group, iftag, src)
291 ImageFrameGroupList::iterator i;
292 if((i = find (imageframe_groups.begin(), imageframe_groups.end(), iftag)) != imageframe_groups.end())
294 imageframe_groups.erase(i) ;
296 ImageFrameGroupRemoved(iftag->get_group_name(), src) ; /* EMIT_SIGNAL */
303 //---------------------------------------------------------------------------------------//
304 // Selected group methods
307 * Sets the currently selected group upon this time axis
309 * @param ifv the item to set selected
312 ImageFrameTimeAxisView::set_selected_imageframe_group(ImageFrameTimeAxisGroup* iftag)
314 if(selected_imageframe_group)
316 selected_imageframe_group->set_selected(false) ;
319 selected_imageframe_group = iftag ;
320 selected_imageframe_group->set_selected(true) ;
324 * Clears the currently selected image frame group unpo this time axis
328 ImageFrameTimeAxisView::clear_selected_imageframe_group()
330 if(selected_imageframe_group)
332 selected_imageframe_group->set_selected(false) ;
334 selected_imageframe_group = 0 ;
338 * Returns the currently selected group upon this time axis
340 * @return the currently selected group upon this time axis
342 ImageFrameTimeAxisGroup*
343 ImageFrameTimeAxisView::get_selected_imageframe_group() const
345 return(selected_imageframe_group) ;
348 //---------------------------------------------------------------------------------------//
349 // Selected item methods
352 * Sets the currently selected imag frame view item
354 * @param iftag the group the selected item is part
355 * @param ifv the selected item
358 ImageFrameTimeAxisView::set_selected_imageframe_view(ImageFrameTimeAxisGroup* iftag, ImageFrameView* ifv)
360 set_selected_imageframe_group(iftag) ;
362 if(selected_imageframe_view)
364 selected_imageframe_view->set_selected(false) ;
367 selected_imageframe_view = ifv ;
368 selected_imageframe_view->set_selected(true) ;
372 * Clears the currently selected image frame view item
376 ImageFrameTimeAxisView::clear_selected_imageframe_item(bool clear_group)
380 clear_selected_imageframe_group() ;
383 if(selected_imageframe_view)
385 selected_imageframe_view->set_selected(false) ;
387 selected_imageframe_view = 0 ;
391 * Returns the currently selected image frame view item upon this time axis
393 * @return the currently selected image frame view item
396 ImageFrameTimeAxisView::get_selected_imageframe_view() const
398 return(selected_imageframe_view) ;
405 ImageFrameTimeAxisView::set_imageframe_duration_sec(double sec)
407 if (selected_imageframe_group && selected_imageframe_view) {
408 selected_imageframe_view->set_duration ((sec * _trackview.editor.session()->frame_rate()), this);
415 * Removes the currently selected ImageFrame view item
417 * @param src the identity of the object that initiated the change
418 * @see add_imageframe_group
421 ImageFrameTimeAxisView::remove_selected_imageframe_item(void* src)
423 if(selected_imageframe_group && selected_imageframe_view)
425 ImageFrameView* temp_item = selected_imageframe_view ;
426 selected_imageframe_group->remove_imageframe_item(temp_item, src) ;
428 // XXX although we have removed the item from the group, we need the group id still set within the
429 // item as the remove method requires this data when telling others about the deletion
430 // to fully specify the item we need the track, group and item id
431 selected_imageframe_view->remove_this_item(src) ;
432 clear_selected_imageframe_item(false) ;