Remove erroneous assert which I added earlier.
[ardour2.git] / gtk2_ardour / imageframe_time_axis_view.cc
blobbbec156efddb2d12d2d6ba5373857b19d87828b5
1 /*
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.
20 #include <algorithm>
22 #include <gtkmm.h>
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"
35 #include "ardour_ui.h"
37 #include "i18n.h"
39 using namespace ARDOUR ;
40 using namespace Editing;
42 //---------------------------------------------------------------------------------------//
43 // Constructor / Desctructor
45 /**
46 * Constructs a new ImageFrameTimeAxisView.
48 * @param ifta the parent ImageFrameTimeAxis of this view helper
50 ImageFrameTimeAxisView::ImageFrameTimeAxisView (ImageFrameTimeAxis& tv)
51 : _trackview (tv),
52 canvas_group (*_trackview.canvas_display),
53 canvas_rect (canvas_group, 0.0, 0.0, 1000000.0, tv.current_height())
55 region_color = _trackview.color() ;
56 stream_base_color = ARDOUR_UI::config()->canvasvar_ImageTrack.get() ;
58 canvas_rect.property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_ImageTrack.get();
59 canvas_rect.property_fill_color_rgba() = stream_base_color;
61 canvas_rect.signal_event().connect (sigc::bind (sigc::mem_fun (_trackview.editor, &PublicEditor::canvas_imageframe_view_event), (ArdourCanvas::Item*) &canvas_rect, &tv));
63 _samples_per_unit = _trackview.editor.get_current_zoom() ;
65 _trackview.editor.ZoomChanged.connect (sigc::mem_fun(*this, &ImageFrameTimeAxisView::reset_samples_per_unit)) ;
67 selected_imageframe_group = 0 ;
68 selected_imageframe_view = 0 ;
70 ImageFrameTimeAxisGroup::CatchDeletion.connect (*this, ui_bind (&ImageFrameTimeAxisView::remove_imageframe_group, this, _1), gui_context());
73 /**
74 * Destructor
75 * Responsible for destroying all items tat may have been added to this time axis
77 ImageFrameTimeAxisView::~ImageFrameTimeAxisView()
79 // Destroy all the ImageFrameGroups that we have
81 for(ImageFrameGroupList::iterator iter = imageframe_groups.begin(); iter != imageframe_groups.end(); ++iter)
83 ImageFrameTimeAxisGroup* iftag = (*iter) ;
85 ImageFrameGroupList::iterator next = iter ;
86 next++ ;
88 // remove the front element
89 imageframe_groups.erase(iter) ;
91 delete iftag ;
92 iftag = 0 ;
94 iter = next ;
100 //---------------------------------------------------------------------------------------//
101 // ui methods & data
104 * Sets the height of the time axis view and the item upon it
106 * @param height the new height
109 ImageFrameTimeAxisView::set_height (gdouble h)
111 /* limit the values to something sane-ish */
112 if (h < 10.0 || h > 1000.0) {
113 return(-1) ;
116 canvas_rect.property_y2() = h ;
119 for(ImageFrameGroupList::const_iterator citer = imageframe_groups.begin(); citer != imageframe_groups.end(); ++citer)
121 (*citer)->set_item_heights(h) ;
124 return(0) ;
128 * Sets the position of this view helper on the canvas
130 * @param x the x position upon the canvas
131 * @param y the y position npon the canvas
134 ImageFrameTimeAxisView::set_position (gdouble x, gdouble y)
137 canvas_group.property_x() = x;
138 canvas_group.property_y() = y;
140 return 0;
144 * Sets the current samples per unit.
145 * this method tells each item upon the time axis of the change
147 * @param spu the new samples per canvas unit value
150 ImageFrameTimeAxisView::set_samples_per_unit (gdouble spp)
152 if (spp < 1.0) {
153 return(-1) ;
156 _samples_per_unit = spp;
158 for(ImageFrameGroupList::const_iterator citer = imageframe_groups.begin(); citer != imageframe_groups.end(); ++citer)
160 (*citer)->set_item_samples_per_units(spp) ;
163 return(0) ;
167 * Sets the color of the items contained uopn this view helper
169 * @param color the new base color
171 void
172 ImageFrameTimeAxisView::apply_color(Gdk::Color& color)
174 region_color = color ;
175 for(ImageFrameGroupList::const_iterator citer = imageframe_groups.begin(); citer != imageframe_groups.end(); citer++)
177 (*citer)->apply_item_color(region_color) ;
183 * convenience method to re-get the samples per unit and tell items upon this view
186 void
187 ImageFrameTimeAxisView::reset_samples_per_unit ()
189 set_samples_per_unit (_trackview.editor.get_current_zoom());
193 //---------------------------------------------------------------------------------------//
194 // Child ImageFrameTimeAxisGroup Accessors/Mutators
197 * Adds an ImageFrameTimeAxisGroup to the list of items upon this time axis view helper
198 * the new ImageFrameTimeAxisGroup is returned
200 * @param group_id the unique id of the new group
201 * @param src the identity of the object that initiated the change
203 ImageFrameTimeAxisGroup*
204 ImageFrameTimeAxisView::add_imageframe_group(std::string group_id, void* src)
206 ImageFrameTimeAxisGroup* iftag = 0 ;
208 //check that there is not already a group with that id
209 if(get_named_imageframe_group(group_id) != 0)
211 // iftag = 0 ;
213 else
215 iftag = new ImageFrameTimeAxisGroup(*this, group_id) ;
216 imageframe_groups.push_front(iftag) ;
217 ImageFrameGroupAdded(iftag, src) ; /* EMIT_SIGNAL */
220 return(iftag) ;
224 * Returns the named ImageFrameTimeAxisGroup or 0 if the named group does not exist on this view helper
226 * @param group_id the unique id of the group to search for
227 * @return the named ImageFrameTimeAxisGroup, or 0 if it is not held upon this view
229 ImageFrameTimeAxisGroup*
230 ImageFrameTimeAxisView::get_named_imageframe_group(std::string group_id)
232 ImageFrameTimeAxisGroup* iftag = 0 ;
234 for(ImageFrameGroupList::iterator i = imageframe_groups.begin(); i != imageframe_groups.end(); ++i)
236 if (((ImageFrameTimeAxisGroup*)*i)->get_group_name() == group_id)
238 iftag = ((ImageFrameTimeAxisGroup*)*i) ;
239 break ;
243 return(iftag) ;
248 * Removes and returns the named ImageFrameTimeAxisGroup from the list of ImageFrameTimeAxisGroup held by this view helper
250 * @param group_id the ImageFrameTimeAxisGroup unique id to remove
251 * @param src the identity of the object that initiated the change
252 * @see add_imageframe_group
254 ImageFrameTimeAxisGroup*
255 ImageFrameTimeAxisView::remove_named_imageframe_group(std::string group_id, void* src)
257 ImageFrameTimeAxisGroup* removed = 0 ;
259 for(ImageFrameGroupList::iterator iter = imageframe_groups.begin(); iter != imageframe_groups.end(); ++iter)
261 if(((ImageFrameTimeAxisGroup*)*iter)->get_group_name() == group_id)
263 removed = (*iter) ;
264 imageframe_groups.erase(iter) ;
266 if(removed == selected_imageframe_group)
268 selected_imageframe_group = 0 ;
271 ImageFrameGroupRemoved(removed->get_group_name(), src) ; /* EMIT_SIGNAL */
273 // break from the for loop
274 break ;
276 iter++ ;
279 return(removed) ;
284 * Removes the specified ImageFrameTimeAxisGroup from the list of ImageFrameTimeAxisGroups upon this TimeAxis.
286 * @param iftag the ImageFrameView to remove
288 void
289 ImageFrameTimeAxisView::remove_imageframe_group(ImageFrameTimeAxisGroup* iftag, void* src)
291 ENSURE_GUI_THREAD (*this, &ImageFrameTimeAxisView::remove_imageframe_group, iftag, src)
293 ImageFrameGroupList::iterator i;
294 if((i = find (imageframe_groups.begin(), imageframe_groups.end(), iftag)) != imageframe_groups.end())
296 imageframe_groups.erase(i) ;
298 ImageFrameGroupRemoved(iftag->get_group_name(), src) ; /* EMIT_SIGNAL */
305 //---------------------------------------------------------------------------------------//
306 // Selected group methods
309 * Sets the currently selected group upon this time axis
311 * @param ifv the item to set selected
313 void
314 ImageFrameTimeAxisView::set_selected_imageframe_group(ImageFrameTimeAxisGroup* iftag)
316 if(selected_imageframe_group)
318 selected_imageframe_group->set_selected(false) ;
321 selected_imageframe_group = iftag ;
322 selected_imageframe_group->set_selected(true) ;
326 * Clears the currently selected image frame group unpo this time axis
329 void
330 ImageFrameTimeAxisView::clear_selected_imageframe_group()
332 if(selected_imageframe_group)
334 selected_imageframe_group->set_selected(false) ;
336 selected_imageframe_group = 0 ;
340 * Returns the currently selected group upon this time axis
342 * @return the currently selected group upon this time axis
344 ImageFrameTimeAxisGroup*
345 ImageFrameTimeAxisView::get_selected_imageframe_group() const
347 return(selected_imageframe_group) ;
350 //---------------------------------------------------------------------------------------//
351 // Selected item methods
354 * Sets the currently selected imag frame view item
356 * @param iftag the group the selected item is part
357 * @param ifv the selected item
359 void
360 ImageFrameTimeAxisView::set_selected_imageframe_view(ImageFrameTimeAxisGroup* iftag, ImageFrameView* ifv)
362 set_selected_imageframe_group(iftag) ;
364 if(selected_imageframe_view)
366 selected_imageframe_view->set_selected(false) ;
369 selected_imageframe_view = ifv ;
370 selected_imageframe_view->set_selected(true) ;
374 * Clears the currently selected image frame view item
377 void
378 ImageFrameTimeAxisView::clear_selected_imageframe_item(bool clear_group)
380 if(clear_group)
382 clear_selected_imageframe_group() ;
385 if(selected_imageframe_view)
387 selected_imageframe_view->set_selected(false) ;
389 selected_imageframe_view = 0 ;
393 * Returns the currently selected image frame view item upon this time axis
395 * @return the currently selected image frame view item
397 ImageFrameView*
398 ImageFrameTimeAxisView::get_selected_imageframe_view() const
400 return(selected_imageframe_view) ;
406 void
407 ImageFrameTimeAxisView::set_imageframe_duration_sec(double sec)
409 if (selected_imageframe_group && selected_imageframe_view) {
410 selected_imageframe_view->set_duration ((sec * _trackview.editor.session()->frame_rate()), this);
417 * Removes the currently selected ImageFrame view item
419 * @param src the identity of the object that initiated the change
420 * @see add_imageframe_group
422 void
423 ImageFrameTimeAxisView::remove_selected_imageframe_item(void* src)
425 if(selected_imageframe_group && selected_imageframe_view)
427 ImageFrameView* temp_item = selected_imageframe_view ;
428 selected_imageframe_group->remove_imageframe_item(temp_item, src) ;
430 // XXX although we have removed the item from the group, we need the group id still set within the
431 // item as the remove method requires this data when telling others about the deletion
432 // to fully specify the item we need the track, group and item id
433 selected_imageframe_view->remove_this_item(src) ;
434 clear_selected_imageframe_item(false) ;