Add a couple of missing attach_buffers() calls after _ports has been changed. I...
[ardour2.git] / gtk2_ardour / imageframe_time_axis.cc
blob3e0f38d4be099d16e4cc3a7b3cc11f92e3f84b91
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 <string>
21 #include <algorithm>
23 #include "pbd/error.h"
25 #include <gtkmm/menu.h>
27 #include <gtkmm2ext/utils.h>
28 #include <gtkmm2ext/gtk_ui.h>
30 #include "ardour/session.h"
31 #include "ardour/utils.h"
33 #include "public_editor.h"
34 #include "imageframe_time_axis.h"
35 #include "simplerect.h"
36 #include "enums.h"
37 #include "imageframe_time_axis_view.h"
38 #include "imageframe_time_axis_group.h"
39 #include "marker_time_axis_view.h"
40 #include "imageframe_view.h"
41 #include "marker_time_axis.h"
42 #include "marker_view.h"
43 #include "gui_thread.h"
44 #include "canvas_impl.h"
46 #include "i18n.h"
48 using namespace ARDOUR;
49 using namespace PBD;
50 using namespace Gtk;
52 /**
53 * Constructs a new ImageFrameTimeAxis.
55 * @param track_id the track name/id
56 * @param ed the PublicEditor
57 * @param sess the current session
58 * @param canvas the parent canvas item
60 ImageFrameTimeAxis::ImageFrameTimeAxis(const string & track_id, PublicEditor& ed, ARDOUR::Session* sess, ArdourCanvas::Canvas& canvas)
61 : AxisView(sess),
62 VisualTimeAxis(track_id, ed, sess, canvas)
64 _color = unique_random_color() ;
66 selection_group = new ArdourCanvas::Group (*canvas_display);
67 selection_group->hide();
69 // intialize our data items
70 y_position = -1 ;
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
79 label_view() ;
81 // set the initial height of this time axis
82 set_height(hNormal) ;
84 TimeAxisView::CatchDeletion.connect (*this, ui_bind (&ImageFrameTimeAxis::remove_time_axis_view, this, _1), gui_context());
87 /**
88 * Destructor
89 * Responsible for destroying any child image items that may have been added to thie time axis
91 ImageFrameTimeAxis::~ImageFrameTimeAxis ()
93 CatchDeletion (this);
95 // Destroy all the marker views we may have associaited with this TimeAxis
96 for(MarkerTimeAxisList::iterator iter = marker_time_axis_list.begin(); iter != marker_time_axis_list.end(); ++iter)
98 MarkerTimeAxis* mta = *iter ;
99 MarkerTimeAxisList::iterator next = iter ;
100 next++ ;
102 marker_time_axis_list.erase(iter) ;
104 delete mta ;
105 mta = 0 ;
107 iter = next ;
110 delete image_action_menu ;
111 image_action_menu = 0 ;
113 delete selection_group;
114 selection_group = 0 ;
116 // Destroy our Axis View helper
117 delete view ;
118 view = 0 ;
121 //---------------------------------------------------------------------------------------//
122 // ui methods & data
125 * Sets the height of this TrackView to one of ths TrackHeghts
127 * @param h
129 void
130 ImageFrameTimeAxis::set_height (uint32_t h)
132 VisualTimeAxis::set_height(h) ;
134 // tell out view helper of the change too
135 if(view != 0)
137 view->set_height((double) height) ;
140 // tell those interested that we have had our height changed
141 gui_changed("track_height",(void*)0); /* EMIT_SIGNAL */
145 * Sets the number of samples per unit that are used.
146 * This is used to determine the siezes of items upon this time axis
148 * @param spu the number of samples per unit
150 void
151 ImageFrameTimeAxis::set_samples_per_unit(double spu)
153 TimeAxisView::set_samples_per_unit (editor.get_current_zoom());
155 if(view) {
156 view->set_samples_per_unit(spu) ;
162 * Returns the available height for images to be drawn onto
164 * @return the available height for an image item to be drawn onto
167 ImageFrameTimeAxis::get_image_display_height()
169 return(height - (gint)TimeAxisViewItem::NAME_HIGHLIGHT_SIZE) ;
174 * Show the popup edit menu
176 * @param button the mouse button pressed
177 * @param time when to show the popup
178 * @param clicked_imageframe the ImageFrameItem that the event ocured upon, or 0 if none
179 * @param with_item true if an item has been selected upon the time axis, used to set context menu
181 void
182 ImageFrameTimeAxis::popup_imageframe_edit_menu(int button, int32_t time, ImageFrameView* clicked_imageframe, bool with_item)
184 if (!imageframe_menu)
186 create_imageframe_menu() ;
189 if(with_item)
191 imageframe_item_menu->set_sensitive(true) ;
193 else
195 imageframe_item_menu->set_sensitive(false) ;
198 imageframe_menu->popup(button,time) ;
202 * convenience method to select a new track color and apply it to the view and view items
205 void
206 ImageFrameTimeAxis::select_track_color()
208 if (choose_time_axis_color())
210 if (view)
212 view->apply_color (_color) ;
218 * Handles the building of the popup menu
220 void
221 ImageFrameTimeAxis::build_display_menu()
223 using namespace Menu_Helpers;
224 using Gtk::Menu;
226 /* get the size menu ready */
228 build_size_menu();
230 /* prepare it */
232 TimeAxisView::build_display_menu () ;
234 /* now fill it with our stuff */
236 MenuList& items = display_menu->items();
238 items.push_back (MenuElem (_("Rename"), sigc::mem_fun(*this, &ImageFrameTimeAxis::start_time_axis_rename)));
240 image_action_menu = new Menu() ;
241 image_action_menu->set_name ("ArdourContextMenu");
242 MenuList image_items = image_action_menu->items() ;
244 items.push_back (SeparatorElem());
245 items.push_back (MenuElem (_("Height"), *size_menu));
246 items.push_back (MenuElem (_("Color"), sigc::mem_fun(*this, &ImageFrameTimeAxis::select_track_color)));
248 items.push_back (SeparatorElem());
249 items.push_back (MenuElem (_("Remove"), sigc::bind(sigc::mem_fun(*this, &VisualTimeAxis::remove_this_time_axis), (void*)this))) ;
253 * handles the building of the ImageFrameView sub menu
255 void
256 ImageFrameTimeAxis::create_imageframe_menu()
258 using namespace Menu_Helpers;
259 using Gtk::Menu;
261 imageframe_menu = manage(new Menu) ;
262 imageframe_menu->set_name ("ArdourContextMenu");
263 MenuList& items = imageframe_menu->items();
265 imageframe_item_menu = manage(new Menu) ;
266 imageframe_item_menu->set_name ("ArdourContextMenu");
267 MenuList& imageframe_sub_items = imageframe_item_menu->items() ;
269 /* duration menu */
270 Menu* duration_menu = manage(new Menu) ;
271 duration_menu->set_name ("ArdourContextMenu");
272 MenuList& duration_items = duration_menu->items() ;
274 if(view)
276 duration_items.push_back(MenuElem (_("0.5 seconds"), sigc::bind (sigc::mem_fun (view, &ImageFrameTimeAxisView::set_imageframe_duration_sec), 0.5))) ;
277 duration_items.push_back(MenuElem (_("1 seconds"), sigc::bind (sigc::mem_fun (view, &ImageFrameTimeAxisView::set_imageframe_duration_sec), 1.0))) ;
278 duration_items.push_back(MenuElem (_("1.5 seconds"), sigc::bind (sigc::mem_fun (view, &ImageFrameTimeAxisView::set_imageframe_duration_sec), 1.5))) ;
279 duration_items.push_back(MenuElem (_("2 seconds"), sigc::bind (sigc::mem_fun (view, &ImageFrameTimeAxisView::set_imageframe_duration_sec), 2.0))) ;
280 duration_items.push_back(MenuElem (_("2.5 seconds"), sigc::bind (sigc::mem_fun (view, &ImageFrameTimeAxisView::set_imageframe_duration_sec), 2.5))) ;
281 duration_items.push_back(MenuElem (_("3 seconds"), sigc::bind (sigc::mem_fun (view, &ImageFrameTimeAxisView::set_imageframe_duration_sec), 3.0))) ;
282 //duration_items.push_back(SeparatorElem()) ;
283 //duration_items.push_back(MenuElem (_("custom"), sigc::mem_fun(*this, &ImageFrameTimeAxis::set_imageframe_duration_custom))) ;
286 imageframe_sub_items.push_back(MenuElem(_("Duration (sec)"), *duration_menu)) ;
288 imageframe_sub_items.push_back(SeparatorElem()) ;
289 if(view)
291 imageframe_sub_items.push_back(MenuElem (_("Remove Frame"), sigc::bind(sigc::mem_fun (view, &ImageFrameTimeAxisView::remove_selected_imageframe_item), (void*)this))) ;
294 items.push_back(MenuElem(_("Image Frame"), *imageframe_item_menu)) ;
295 items.push_back(MenuElem (_("Rename Track"), sigc::mem_fun(*this,&ImageFrameTimeAxis::start_time_axis_rename))) ;
297 imageframe_menu->show_all() ;
303 //---------------------------------------------------------------------------------------//
304 // Marker Time Axis Methods
307 * Add a MarkerTimeAxis to the ilst of MarkerTimeAxis' associated with this ImageFrameTimeAxis
309 * @param marker_track the MarkerTimeAxis to add
310 * @param src the identity of the object that initiated the change
311 * @return true if the addition was a success,
312 * false otherwise
314 bool
315 ImageFrameTimeAxis::add_marker_time_axis(MarkerTimeAxis* marker_track, void* src)
317 bool ret = false ;
319 if(get_named_marker_time_axis(marker_track->name()) != 0)
321 ret = false ;
323 else
325 marker_time_axis_list.push_back(marker_track) ;
326 MarkerTimeAxisAdded(marker_track, src) ; /* EMIT_SIGNAL */
327 ret = true ;
330 return(ret) ;
334 * Returns the named MarkerTimeAxis associated with this ImageFrameTimeAxis
336 * @param track_id the track_id of the MarkerTimeAxis to search for
337 * @return the named markerTimeAxis, or 0 if the named MarkerTimeAxis is not associated with this ImageFrameTimeAxis
339 MarkerTimeAxis*
340 ImageFrameTimeAxis::get_named_marker_time_axis(const string & track_id)
342 MarkerTimeAxis* mta = 0 ;
344 for (MarkerTimeAxisList::iterator i = marker_time_axis_list.begin(); i != marker_time_axis_list.end(); ++i)
346 if (((MarkerTimeAxis*)*i)->name() == track_id)
348 mta = ((MarkerTimeAxis*)*i) ;
349 break ;
352 return(mta) ;
356 * Removes the named markerTimeAxis from those associated with this ImageFrameTimeAxis
358 * @param track_id the track id of the MarkerTimeAxis to remove
359 * @param src the identity of the object that initiated the change
360 * @return the removed MarkerTimeAxis
362 MarkerTimeAxis*
363 ImageFrameTimeAxis::remove_named_marker_time_axis(const string & track_id, void* src)
365 MarkerTimeAxis* mta = 0 ;
367 for(MarkerTimeAxisList::iterator i = marker_time_axis_list.begin(); i != marker_time_axis_list.end(); ++i)
369 if (((MarkerTimeAxis*)*i)->name() == track_id)
371 mta = ((MarkerTimeAxis*)*i) ;
373 // the iterator is invalid after this call, so we can no longer use it as is.
374 marker_time_axis_list.erase(i) ;
376 MarkerTimeAxisRemoved(mta->name(), src) ; /* EMIT_SIGNAL */
377 break ;
381 return(mta) ;
385 * Removes the specified MarkerTimeAxis from the list of MarkerTimaAxis associated with this ImageFrameTimeAxis
386 * Note that the MarkerTimeAxis is not deleted, only removed from the list os associated tracks
388 * @param mta the TimeAxis to remove
389 * @param src the identity of the object that initiated the change
391 void
392 ImageFrameTimeAxis::remove_time_axis_view (TimeAxisView* tav)
394 MarkerTimeAxisView* mtav = dynamic_cast<MarkerTimeAxisView*> (tav);
396 if (!mtav) {
397 return;
400 MarkerTimeAxisList::iterator i;
402 if ((i = find (marker_time_axis_list.begin(), marker_time_axis_list.end(), mta)) != marker_time_axis_list.end()) {
403 // note that we dont delete the object itself, we just remove it from our list
404 marker_time_axis_list.erase(i) ;
405 MarkerTimeAxisRemoved (mta->name(), src) ; /* EMIT_SIGNAL */
410 //---------------------------------------------------------------------------------------//
411 // Parent/Child helper object accessors
414 * Returns the view helper of this TimeAxis
416 * @return the view helper of this TimeAxis
418 ImageFrameTimeAxisView*
419 ImageFrameTimeAxis::get_view()
421 return(view) ;