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 <pbd/error.h>
26 #include <gtkmm2ext/utils.h>
27 #include <gtkmm2ext/gtk_ui.h>
29 #include <ardour/session.h>
30 #include <ardour/utils.h>
32 #include "public_editor.h"
33 #include "imageframe_time_axis.h"
34 #include "canvas-simplerect.h"
36 #include "imageframe_time_axis_view.h"
37 #include "imageframe_time_axis_group.h"
38 #include "marker_time_axis_view.h"
39 #include "imageframe_view.h"
40 #include "marker_time_axis.h"
41 #include "marker_view.h"
42 #include "gui_thread.h"
46 using namespace ARDOUR ;
47 using namespace sigc ;
51 * Constructs a new ImageFrameTimeAxis.
53 * @param track_id the track name/id
54 * @param ed the PublicEditor
55 * @param sess the current session
56 * @param canvas the parent canvas item
58 ImageFrameTimeAxis::ImageFrameTimeAxis(std::string track_id, PublicEditor& ed, ARDOUR::Session& sess, Widget *canvas)
60 VisualTimeAxis(track_id, ed, sess, canvas)
62 _color = unique_random_color() ;
64 selection_group = gtk_canvas_item_new (GTK_CANVAS_GROUP(canvas_display), gtk_canvas_group_get_type (), NULL) ;
65 gtk_canvas_item_hide(selection_group) ;
67 // intialize our data items
68 _marked_for_display = true;
72 /* create our new image frame view */
73 view = new ImageFrameTimeAxisView(*this) ;
75 /* create the Image Frame Edit Menu */
76 create_imageframe_menu() ;
78 // set the initial time axis text label
81 // set the initial height of this time axis
87 * Responsible for destroying any child image items that may have been added to thie time axis
89 ImageFrameTimeAxis::~ImageFrameTimeAxis ()
91 GoingAway() ; /* EMIT_SIGNAL */
93 // Destroy all the marker views we may have associaited with this TimeAxis
94 for(MarkerTimeAxisList::iterator iter = marker_time_axis_list.begin(); iter != marker_time_axis_list.end(); ++iter)
96 MarkerTimeAxis* mta = *iter ;
97 MarkerTimeAxisList::iterator next = iter ;
100 marker_time_axis_list.erase(iter) ;
108 if(image_action_menu)
110 delete image_action_menu ;
111 image_action_menu = 0 ;
114 for(list<SelectionRect*>::iterator i = free_selection_rects.begin(); i != free_selection_rects.end(); ++i)
116 gtk_object_destroy (GTK_OBJECT((*i)->rect));
117 gtk_object_destroy (GTK_OBJECT((*i)->start_trim));
118 gtk_object_destroy (GTK_OBJECT((*i)->end_trim));
121 for(list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i)
123 gtk_object_destroy (GTK_OBJECT((*i)->rect));
124 gtk_object_destroy (GTK_OBJECT((*i)->start_trim));
125 gtk_object_destroy (GTK_OBJECT((*i)->end_trim));
130 gtk_object_destroy (GTK_OBJECT (selection_group));
131 selection_group = 0 ;
134 // Destroy our Axis View helper
142 //---------------------------------------------------------------------------------------//
146 * Sets the height of this TrackView to one of ths TrackHeghts
148 * @param h the TrackHeight value to set
151 ImageFrameTimeAxis::set_height (TrackHeight h)
153 VisualTimeAxis::set_height(h) ;
155 // tell out view helper of the change too
158 view->set_height((double) height) ;
161 // tell those interested that we have had our height changed
162 gui_changed("track_height",(void*)0); /* EMIT_SIGNAL */
166 * Sets the number of samples per unit that are used.
167 * This is used to determine the siezes of items upon this time axis
169 * @param spu the number of samples per unit
172 ImageFrameTimeAxis::set_samples_per_unit(double spu)
174 TimeAxisView::set_samples_per_unit (editor.get_current_zoom());
177 view->set_samples_per_unit(spu) ;
183 * Returns the available height for images to be drawn onto
185 * @return the available height for an image item to be drawn onto
188 ImageFrameTimeAxis::get_image_display_height()
190 return(height - (gint)TimeAxisViewItem::NAME_HIGHLIGHT_SIZE) ;
195 * Show the popup edit menu
197 * @param button the mouse button pressed
198 * @param time when to show the popup
199 * @param clicked_imageframe the ImageFrameItem that the event ocured upon, or 0 if none
200 * @param with_item true if an item has been selected upon the time axis, used to set context menu
203 ImageFrameTimeAxis::popup_imageframe_edit_menu(int button, int32_t time, ImageFrameView* clicked_imageframe, bool with_item)
205 if (!imageframe_menu)
207 create_imageframe_menu() ;
212 imageframe_item_menu->set_sensitive(true) ;
216 imageframe_item_menu->set_sensitive(false) ;
219 imageframe_menu->popup(button,time) ;
223 * convenience method to select a new track color and apply it to the view and view items
227 ImageFrameTimeAxis::select_track_color()
229 if (choose_time_axis_color())
233 view->apply_color (_color) ;
239 * Handles the building of the popup menu
242 ImageFrameTimeAxis::build_display_menu()
244 using namespace Menu_Helpers;
246 /* get the size menu ready */
252 TimeAxisView::build_display_menu () ;
254 /* now fill it with our stuff */
256 MenuList& items = display_menu->items();
258 items.push_back (MenuElem (_("Rename"), mem_fun(*this, &ImageFrameTimeAxis::start_time_axis_rename)));
260 image_action_menu = new Menu() ;
261 image_action_menu->set_name ("ArdourContextMenu");
262 MenuList image_items = image_action_menu->items() ;
264 items.push_back (SeparatorElem());
265 items.push_back (MenuElem (_("Height"), *size_menu));
266 items.push_back (MenuElem (_("Color"), mem_fun(*this, &ImageFrameTimeAxis::select_track_color)));
268 items.push_back (SeparatorElem());
269 items.push_back (MenuElem (_("Remove"), bind(mem_fun(*this, &VisualTimeAxis::remove_this_time_axis), (void*)this))) ;
273 * handles the building of the ImageFrameView sub menu
276 ImageFrameTimeAxis::create_imageframe_menu()
278 using namespace Menu_Helpers;
280 imageframe_menu = manage(new Menu) ;
281 imageframe_menu->set_name ("ArdourContextMenu");
282 MenuList& items = imageframe_menu->items();
284 imageframe_item_menu = manage(new Menu) ;
285 imageframe_item_menu->set_name ("ArdourContextMenu");
286 MenuList& imageframe_sub_items = imageframe_item_menu->items() ;
289 Menu* duration_menu = manage(new Menu) ;
290 duration_menu->set_name ("ArdourContextMenu");
291 MenuList& duration_items = duration_menu->items() ;
295 duration_items.push_back(MenuElem (_("0.5 seconds"), bind (mem_fun (view, &ImageFrameTimeAxisView::set_imageframe_duration_sec), 0.5))) ;
296 duration_items.push_back(MenuElem (_("1 seconds"), bind (mem_fun (view, &ImageFrameTimeAxisView::set_imageframe_duration_sec), 1.0))) ;
297 duration_items.push_back(MenuElem (_("1.5 seconds"), bind (mem_fun (view, &ImageFrameTimeAxisView::set_imageframe_duration_sec), 1.5))) ;
298 duration_items.push_back(MenuElem (_("2 seconds"), bind (mem_fun (view, &ImageFrameTimeAxisView::set_imageframe_duration_sec), 2.0))) ;
299 duration_items.push_back(MenuElem (_("2.5 seconds"), bind (mem_fun (view, &ImageFrameTimeAxisView::set_imageframe_duration_sec), 2.5))) ;
300 duration_items.push_back(MenuElem (_("3 seconds"), bind (mem_fun (view, &ImageFrameTimeAxisView::set_imageframe_duration_sec), 3.0))) ;
301 //duration_items.push_back(SeparatorElem()) ;
302 //duration_items.push_back(MenuElem (_("custom"), mem_fun(*this, &ImageFrameTimeAxis::set_imageframe_duration_custom))) ;
305 imageframe_sub_items.push_back(MenuElem(_("Duration (sec)"), *duration_menu)) ;
307 imageframe_sub_items.push_back(SeparatorElem()) ;
310 imageframe_sub_items.push_back(MenuElem (_("Remove Frame"), bind(mem_fun (view, &ImageFrameTimeAxisView::remove_selected_imageframe_item), (void*)this))) ;
313 items.push_back(MenuElem(_("Image Frame"), *imageframe_item_menu)) ;
314 items.push_back(MenuElem (_("Rename Track"), mem_fun(*this,&ImageFrameTimeAxis::start_time_axis_rename))) ;
316 imageframe_menu->show_all() ;
322 //---------------------------------------------------------------------------------------//
323 // Marker Time Axis Methods
326 * Add a MarkerTimeAxis to the ilst of MarkerTimeAxis' associated with this ImageFrameTimeAxis
328 * @param marker_track the MarkerTimeAxis to add
329 * @param src the identity of the object that initiated the change
330 * @return true if the addition was a success,
334 ImageFrameTimeAxis::add_marker_time_axis(MarkerTimeAxis* marker_track, void* src)
338 if(get_named_marker_time_axis(marker_track->name()) != 0)
344 marker_time_axis_list.push_back(marker_track) ;
345 marker_track->GoingAway.connect(bind(mem_fun(*this, &ImageFrameTimeAxis::remove_time_axis_view), marker_track, (void*)this));
347 MarkerTimeAxisAdded(marker_track, src) ; /* EMIT_SIGNAL */
355 * Returns the named MarkerTimeAxis associated with this ImageFrameTimeAxis
357 * @param track_id the track_id of the MarkerTimeAxis to search for
358 * @return the named markerTimeAxis, or 0 if the named MarkerTimeAxis is not associated with this ImageFrameTimeAxis
361 ImageFrameTimeAxis::get_named_marker_time_axis(std::string track_id)
363 MarkerTimeAxis* mta = 0 ;
365 for (MarkerTimeAxisList::iterator i = marker_time_axis_list.begin(); i != marker_time_axis_list.end(); ++i)
367 if (((MarkerTimeAxis*)*i)->name() == track_id)
369 mta = ((MarkerTimeAxis*)*i) ;
377 * Removes the named markerTimeAxis from those associated with this ImageFrameTimeAxis
379 * @param track_id the track id of the MarkerTimeAxis to remove
380 * @param src the identity of the object that initiated the change
381 * @return the removed MarkerTimeAxis
384 ImageFrameTimeAxis::remove_named_marker_time_axis(std::string track_id, void* src)
386 MarkerTimeAxis* mta = 0 ;
388 for(MarkerTimeAxisList::iterator i = marker_time_axis_list.begin(); i != marker_time_axis_list.end(); ++i)
390 if (((MarkerTimeAxis*)*i)->name() == track_id)
392 mta = ((MarkerTimeAxis*)*i) ;
394 // the iterator is invalid after this call, so we can no longer use it as is.
395 marker_time_axis_list.erase(i) ;
397 MarkerTimeAxisRemoved(mta->name(), src) ; /* EMIT_SIGNAL */
406 * Removes the specified MarkerTimeAxis from the list of MarkerTimaAxis associated with this ImageFrameTimeAxis
407 * Note that the MarkerTimeAxis is not deleted, only removed from the list os associated tracks
409 * @param mta the TimeAxis to remove
410 * @param src the identity of the object that initiated the change
413 ImageFrameTimeAxis::remove_time_axis_view(MarkerTimeAxis* mta, void* src)
415 ENSURE_GUI_THREAD(bind (mem_fun(*this, &ImageFrameTimeAxis::remove_time_axis_view), mta, src));
417 MarkerTimeAxisList::iterator i;
418 if((i = find (marker_time_axis_list.begin(), marker_time_axis_list.end(), mta)) != marker_time_axis_list.end())
420 // note that we dont delete the object itself, we just remove it from our list
421 marker_time_axis_list.erase(i) ;
423 MarkerTimeAxisRemoved(mta->name(), src) ; /* EMIT_SIGNAL */
428 //---------------------------------------------------------------------------------------//
429 // Parent/Child helper object accessors
432 * Returns the view helper of this TimeAxis
434 * @return the view helper of this TimeAxis
436 ImageFrameTimeAxisView*
437 ImageFrameTimeAxis::get_view()