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.
25 #include <gtkmm2ext/gtk_ui.h>
27 #include "imageframe_time_axis_view.h"
28 #include "imageframe_time_axis_group.h"
29 #include "imageframe_view.h"
30 #include "imageframe_time_axis.h"
31 #include "canvas-simplerect.h"
32 #include "region_selection.h"
33 #include "public_editor.h"
34 #include "rgb_macros.h"
35 #include "gui_thread.h"
39 using namespace ARDOUR ;
40 using namespace Editing;
42 //---------------------------------------------------------------------------------------//
43 // Constructor / Desctructor
46 * Constructs a new ImageFrameTimeAxisView.
48 * @param ifta the parent ImageFrameTimeAxis of this view helper
50 ImageFrameTimeAxisView::ImageFrameTimeAxisView (ImageFrameTimeAxis& tv)
53 region_color = _trackview.color() ;
54 stream_base_color = color_map[cImageTrackBase] ;
56 canvas_group = gtk_canvas_item_new (GTK_CANVAS_GROUP(_trackview.canvas_display), gtk_canvas_group_get_type (), 0) ;
58 canvas_rect = gtk_canvas_item_new (GTK_CANVAS_GROUP(canvas_group),
59 gtk_canvas_simplerect_get_type(),
63 "y2", (double) tv.height,
64 "outline_color_rgba", color_map[cImageTrackOutline],
65 "fill_color_rgba", stream_base_color,
68 gtk_signal_connect(GTK_OBJECT(canvas_rect), "event", (GtkSignalFunc) PublicEditor::canvas_imageframe_view_event, &_trackview) ;
70 _samples_per_unit = _trackview.editor.get_current_zoom() ;
72 _trackview.editor.ZoomChanged.connect (mem_fun(*this, &ImageFrameTimeAxisView::reset_samples_per_unit)) ;
74 selected_imageframe_group = 0 ;
75 selected_imageframe_view = 0 ;
80 * Responsible for destroying all items tat may have been added to this time axis
82 ImageFrameTimeAxisView::~ImageFrameTimeAxisView()
84 // Destroy all the ImageFrameGroups that we have
86 for(ImageFrameGroupList::iterator iter = imageframe_groups.begin(); iter != imageframe_groups.end(); ++iter)
88 ImageFrameTimeAxisGroup* iftag = (*iter) ;
90 ImageFrameGroupList::iterator next = iter ;
93 // remove the front element
94 imageframe_groups.erase(iter) ;
102 // Destroy all our canvas components
105 gtk_object_destroy(GTK_OBJECT(canvas_rect)) ;
111 gtk_object_destroy(GTK_OBJECT(canvas_group));
117 //---------------------------------------------------------------------------------------//
121 * Sets the height of the time axis view and the item upon it
123 * @param height the new height
126 ImageFrameTimeAxisView::set_height (gdouble h)
128 /* limit the values to something sane-ish */
129 if (h < 10.0 || h > 1000.0)
136 gtk_object_set(GTK_OBJECT(canvas_rect), "y2", h, NULL) ;
139 for(ImageFrameGroupList::const_iterator citer = imageframe_groups.begin(); citer != imageframe_groups.end(); ++citer)
141 (*citer)->set_item_heights(h) ;
148 * Sets the position of this view helper on the canvas
150 * @param x the x position upon the canvas
151 * @param y the y position npon the canvas
154 ImageFrameTimeAxisView::set_position (gdouble x, gdouble y)
157 gtk_canvas_item_set (canvas_group, "x", x, "y", y, NULL);
162 * Sets the current samples per unit.
163 * this method tells each item upon the time axis of the change
165 * @param spu the new samples per canvas unit value
168 ImageFrameTimeAxisView::set_samples_per_unit (gdouble spp)
174 _samples_per_unit = spp;
176 for(ImageFrameGroupList::const_iterator citer = imageframe_groups.begin(); citer != imageframe_groups.end(); ++citer)
178 (*citer)->set_item_samples_per_units(spp) ;
185 * Sets the color of the items contained uopn this view helper
187 * @param color the new base color
190 ImageFrameTimeAxisView::apply_color(GdkColor& color)
192 region_color = color ;
193 for(ImageFrameGroupList::const_iterator citer = imageframe_groups.begin(); citer != imageframe_groups.end(); citer++)
195 (*citer)->apply_item_color(region_color) ;
201 * convenience method to re-get the samples per unit and tell items upon this view
205 ImageFrameTimeAxisView::reset_samples_per_unit ()
207 set_samples_per_unit (_trackview.editor.get_current_zoom());
211 //---------------------------------------------------------------------------------------//
212 // Child ImageFrameTimeAxisGroup Accessors/Mutators
215 * Adds an ImageFrameTimeAxisGroup to the list of items upon this time axis view helper
216 * the new ImageFrameTimeAxisGroup is returned
218 * @param group_id the unique id of the new group
219 * @param src the identity of the object that initiated the change
221 ImageFrameTimeAxisGroup*
222 ImageFrameTimeAxisView::add_imageframe_group(std::string group_id, void* src)
224 ImageFrameTimeAxisGroup* iftag = 0 ;
226 //check that there is not already a group with that id
227 if(get_named_imageframe_group(group_id) != 0)
233 iftag = new ImageFrameTimeAxisGroup(*this, group_id) ;
235 imageframe_groups.push_front(iftag) ;
237 iftag->GoingAway.connect(bind(mem_fun(*this,&ImageFrameTimeAxisView::remove_imageframe_group), iftag, (void*)this)) ;
239 ImageFrameGroupAdded(iftag, src) ; /* EMIT_SIGNAL */
246 * Returns the named ImageFrameTimeAxisGroup or 0 if the named group does not exist on this view helper
248 * @param group_id the unique id of the group to search for
249 * @return the named ImageFrameTimeAxisGroup, or 0 if it is not held upon this view
251 ImageFrameTimeAxisGroup*
252 ImageFrameTimeAxisView::get_named_imageframe_group(std::string group_id)
254 ImageFrameTimeAxisGroup* iftag = 0 ;
256 for(ImageFrameGroupList::iterator i = imageframe_groups.begin(); i != imageframe_groups.end(); ++i)
258 if (((ImageFrameTimeAxisGroup*)*i)->get_group_name() == group_id)
260 iftag = ((ImageFrameTimeAxisGroup*)*i) ;
270 * Removes and returns the named ImageFrameTimeAxisGroup from the list of ImageFrameTimeAxisGroup held by this view helper
272 * @param group_id the ImageFrameTimeAxisGroup unique id to remove
273 * @param src the identity of the object that initiated the change
274 * @see add_imageframe_group
276 ImageFrameTimeAxisGroup*
277 ImageFrameTimeAxisView::remove_named_imageframe_group(std::string group_id, void* src)
279 ImageFrameTimeAxisGroup* removed = 0 ;
281 for(ImageFrameGroupList::iterator iter = imageframe_groups.begin(); iter != imageframe_groups.end(); ++iter)
283 if(((ImageFrameTimeAxisGroup*)*iter)->get_group_name() == group_id)
286 imageframe_groups.erase(iter) ;
288 if(removed == selected_imageframe_group)
290 selected_imageframe_group = 0 ;
293 ImageFrameGroupRemoved(removed->get_group_name(), src) ; /* EMIT_SIGNAL */
295 // break from the for loop
306 * Removes the specified ImageFrameTimeAxisGroup from the list of ImageFrameTimeAxisGroups upon this TimeAxis.
308 * @param iftag the ImageFrameView to remove
311 ImageFrameTimeAxisView::remove_imageframe_group(ImageFrameTimeAxisGroup* iftag, void* src)
313 ENSURE_GUI_THREAD(bind (mem_fun(*this, &ImageFrameTimeAxisView::remove_imageframe_group), iftag, src));
315 ImageFrameGroupList::iterator i;
316 if((i = find (imageframe_groups.begin(), imageframe_groups.end(), iftag)) != imageframe_groups.end())
318 imageframe_groups.erase(i) ;
320 ImageFrameGroupRemoved(iftag->get_group_name(), src) ; /* EMIT_SIGNAL */
327 //---------------------------------------------------------------------------------------//
328 // Selected group methods
331 * Sets the currently selected group upon this time axis
333 * @param ifv the item to set selected
336 ImageFrameTimeAxisView::set_selected_imageframe_group(ImageFrameTimeAxisGroup* iftag)
338 if(selected_imageframe_group)
340 selected_imageframe_group->set_selected(false) ;
343 selected_imageframe_group = iftag ;
344 selected_imageframe_group->set_selected(true) ;
348 * Clears the currently selected image frame group unpo this time axis
352 ImageFrameTimeAxisView::clear_selected_imageframe_group()
354 if(selected_imageframe_group)
356 selected_imageframe_group->set_selected(false) ;
358 selected_imageframe_group = 0 ;
362 * Returns the currently selected group upon this time axis
364 * @return the currently selected group upon this time axis
366 ImageFrameTimeAxisGroup*
367 ImageFrameTimeAxisView::get_selected_imageframe_group() const
369 return(selected_imageframe_group) ;
372 //---------------------------------------------------------------------------------------//
373 // Selected item methods
376 * Sets the currently selected imag frame view item
378 * @param iftag the group the selected item is part
379 * @param ifv the selected item
382 ImageFrameTimeAxisView::set_selected_imageframe_view(ImageFrameTimeAxisGroup* iftag, ImageFrameView* ifv)
384 set_selected_imageframe_group(iftag) ;
386 if(selected_imageframe_view)
388 selected_imageframe_view->set_selected(false, this) ;
391 selected_imageframe_view = ifv ;
392 selected_imageframe_view->set_selected(true, this) ;
396 * Clears the currently selected image frame view item
400 ImageFrameTimeAxisView::clear_selected_imageframe_item(bool clear_group)
404 clear_selected_imageframe_group() ;
407 if(selected_imageframe_view)
409 selected_imageframe_view->set_selected(false, this) ;
411 selected_imageframe_view = 0 ;
415 * Returns the currently selected image frame view item upon this time axis
417 * @return the currently selected image frame view item
420 ImageFrameTimeAxisView::get_selected_imageframe_view() const
422 return(selected_imageframe_view) ;
429 ImageFrameTimeAxisView::set_imageframe_duration_sec(double sec)
431 if(selected_imageframe_group && selected_imageframe_view)
433 selected_imageframe_view->set_duration((jack_nframes_t) (sec * _trackview.editor.current_session()->frame_rate()), this) ;
440 * Removes the currently selected ImageFrame view item
442 * @param src the identity of the object that initiated the change
443 * @see add_imageframe_group
446 ImageFrameTimeAxisView::remove_selected_imageframe_item(void* src)
448 if(selected_imageframe_group && selected_imageframe_view)
450 ImageFrameView* temp_item = selected_imageframe_view ;
451 selected_imageframe_group->remove_imageframe_item(temp_item, src) ;
453 // XXX although we have removed the item from the group, we need the group id still set within the
454 // item as the remove method requires this data when telling others about the deletion
455 // to fully specify the item we need the track, group and item id
456 selected_imageframe_view->remove_this_item(src) ;
457 clear_selected_imageframe_item(false) ;