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 "marker_time_axis_view.h"
27 #include "marker_time_axis.h"
28 #include "marker_view.h"
29 #include "imageframe_view.h"
30 #include "imageframe_time_axis.h"
31 #include "canvas-simplerect.h"
32 #include "public_editor.h"
33 #include "rgb_macros.h"
34 #include "gui_thread.h"
38 using namespace ARDOUR ;
39 using namespace Editing;
41 //---------------------------------------------------------------------------------------//
42 // Constructor / Desctructor
45 * Construct a new MarkerTimeAxisView helper time axis helper
47 * @param mta the TimeAxsiView that this objbect is the helper for
49 MarkerTimeAxisView::MarkerTimeAxisView(MarkerTimeAxis& tv)
52 region_color = _trackview.color();
53 stream_base_color = color_map[cMarkerTrackBase];
55 //GTK2FIX -- how to get the group? is the canvas display really a group?
56 //canvas_group = gnome_canvas_item_new (GNOME_CANVAS_GROUP(_trackview.canvas_display), gnome_canvas_group_get_type (), 0);
57 canvas_group = new ArdourCanvas::Group (*_trackview.canvas_display);
59 canvas_rect = new ArdourCanvas::SimpleRect (*canvas_group);
60 canvas_rect->set_property ("x1", 0.0);
61 canvas_rect->set_property ("y1", 0.0);
62 canvas_rect->set_property ("x2", 1000000.0);
63 canvas_rect->set_property ("y2", (double)20);
64 canvas_rect->set_property ("outline_color_rgba", color_map[cMarkerTrackOutline]);
65 canvas_rect->set_property ("fill_color_rgba", stream_base_color);
67 canvas_rect->signal_event().connect (bind (mem_fun (_trackview.editor, &PublicEditor::canvas_marker_time_axis_view_event), canvas_rect, &_trackview));
69 _samples_per_unit = _trackview.editor.get_current_zoom() ;
71 _trackview.editor.ZoomChanged.connect (mem_fun(*this, &MarkerTimeAxisView::reset_samples_per_unit));
76 * Reposinsibly for destroying all marker items that may have been added to this time axis view
79 MarkerTimeAxisView::~MarkerTimeAxisView()
81 // destroy everything upon this view
82 for(MarkerViewList::iterator iter = marker_view_list.begin(); iter != marker_view_list.end(); ++iter)
84 MarkerView* mv = (*iter) ;
86 MarkerViewList::iterator next = iter ;
88 marker_view_list.erase(iter) ;
98 gtk_object_destroy(GTK_OBJECT(canvas_rect)) ;
104 gtk_object_destroy(GTK_OBJECT(canvas_group)) ;
110 //---------------------------------------------------------------------------------------//
114 * Sets the height of the time axis view and the item upon it
116 * @param height the new height
119 MarkerTimeAxisView::set_height(gdouble h)
121 if (h < 10.0 || h > 1000.0)
126 gtk_object_set (GTK_OBJECT(canvas_rect), "y2", h, NULL);
128 for (MarkerViewList::iterator i = marker_view_list.begin(); i != marker_view_list.end(); ++i)
130 (*i)->set_height(h) ;
137 * Sets the position of this view helper on the canvas
139 * @param x the x position upon the canvas
140 * @param y the y position upon the canvas
143 MarkerTimeAxisView::set_position(gdouble x, gdouble y)
145 canvas_group->set_property ("x", x);
146 canvas_group->set_property ("y", y);
151 * Sets the current samples per unit.
152 * this method tells each item upon the time axis of the change
154 * @param spu the new samples per canvas unit value
157 MarkerTimeAxisView::set_samples_per_unit(gdouble spp)
163 _samples_per_unit = spp ;
165 for(MarkerViewList::iterator i = marker_view_list.begin(); i != marker_view_list.end(); ++i)
167 (*i)->set_samples_per_unit(spp) ;
173 * Sets the color of the items contained upon this view helper
175 * @param color the new base color
178 MarkerTimeAxisView::apply_color(Gdk::Color& color)
180 region_color = color;
182 for (MarkerViewList::iterator i = marker_view_list.begin(); i != marker_view_list.end(); i++)
184 (*i)->set_color (region_color) ;
189 //---------------------------------------------------------------------------------------//
190 // Child MarkerView Accessors/Mutators
193 * Adds a marker view to the list of items upon this time axis view helper
194 * the new MarkerView is returned
196 * @param ifv the ImageFrameView that the new item is marking up
197 * @param mark_text the text to be displayed uopn the new marker item
198 * @param mark_id the unique id of the new item
199 * @param start the position the new item should be placed upon the time line
200 * @param duration the duration the new item should be placed upon the timeline
201 * @param src the identity of the object that initiated the change
204 MarkerTimeAxisView::add_marker_view(ImageFrameView* ifv, std::string mark_type, std::string mark_id, jack_nframes_t start, jack_nframes_t dur, void* src)
206 if(ifv->has_marker_view_item(mark_id))
211 MarkerView* mv = new MarkerView(canvas_group,
214 _trackview.editor.get_current_zoom(),
221 ifv->add_marker_view_item(mv, src) ;
222 marker_view_list.push_front(mv) ;
224 mv->GoingAway.connect(bind (mem_fun(*this,&MarkerTimeAxisView::remove_marker_view), (void*)this)) ;
226 MarkerViewAdded(mv,src) ; /* EMIT_SIGNAL */
232 * Returns the named MarkerView or 0 if the named marker does not exist
234 * @param item_id the unique id of the item to search for
235 * @return the named MarkerView, or 0 if it is not held upon this view
238 MarkerTimeAxisView::get_named_marker_view(std::string item_id)
242 for(MarkerViewList::iterator i = marker_view_list.begin(); i != marker_view_list.end(); ++i)
244 if(((MarkerView*)*i)->get_item_name() == item_id)
246 mv = ((MarkerView*)*i) ;
254 * Removes the currently selected MarverView
255 * Note that this method actually destroys the MarkerView too.
256 * We assume that since we own the object, we are allowed to do this
258 * @param src the identity of the object that initiated the change
259 * @see add_marker_view
262 MarkerTimeAxisView::remove_selected_marker_view(void* src)
264 std::string removed ;
266 if (selected_time_axis_item)
268 MarkerViewList::iterator i ;
269 if((i = find (marker_view_list.begin(), marker_view_list.end(), selected_time_axis_item)) != marker_view_list.end())
271 marker_view_list.erase(i) ;
273 MarkerViewRemoved(selected_time_axis_item->get_item_name(),src) ; /* EMIT_SIGNAL */
275 delete(selected_time_axis_item) ;
276 selected_time_axis_item = 0 ;
281 //No selected marker view
286 * Removes and returns the named MarkerView from the list of MarkerView held by this view helper
288 * @param item_id the MarkerView unique id to remove
289 * @param src the identity of the object that initiated the change
290 * @see add_marker_view
293 MarkerTimeAxisView::remove_named_marker_view(std::string item_id, void* src)
297 MarkerViewList::iterator i = marker_view_list.begin() ;
299 for(MarkerViewList::iterator iter = marker_view_list.begin(); iter != marker_view_list.end(); ++iter)
301 if(((MarkerView*)*i)->get_item_name() == item_id)
303 mv = ((MarkerView*)*i) ;
304 marker_view_list.erase(i) ;
306 MarkerViewRemoved(mv->get_item_name(), src) ; /* EMIT_SIGNAL */
308 // break from the for loop
318 * Removes mv from the list of MarkerView upon this TimeAxis
320 * @param mv the MarkerView to remove
321 * @param src the identity of the object that initiated the change
324 MarkerTimeAxisView::remove_marker_view(MarkerView* mv, void* src)
326 ENSURE_GUI_THREAD(bind (mem_fun(*this, &MarkerTimeAxisView::remove_marker_view), mv, src));
328 MarkerViewList::iterator i;
330 if((i = find (marker_view_list.begin(), marker_view_list.end(), mv)) != marker_view_list.end()) {
331 marker_view_list.erase(i) ;
333 // Assume this remove happened locally, else use remove_named_marker_time_axis
334 // let listeners know that the named MarkerTimeAxis has been removed
335 MarkerViewRemoved(mv->get_item_name(), src) ; /* EMIT_SIGNAL */
341 * Sets the duration of the selected MarkerView to the specified number of seconds
343 * @param sec the duration to set the MArkerView to, in seconds
346 MarkerTimeAxisView::set_marker_duration_sec(double sec)
348 if(get_selected_time_axis_item() != 0)
350 get_selected_time_axis_item()->set_duration((jack_nframes_t) (sec * _trackview.editor.current_session()->frame_rate()), this) ;
355 //---------------------------------------------------------------------------------------//
356 // Selected item methods
359 * Sets the currently selected item upon this time axis
361 * @param mv the item to set selected
364 MarkerTimeAxisView::set_selected_time_axis_item(MarkerView* mv)
366 selected_time_axis_item = mv ;
370 * Clears any selected item upon this time axis
374 MarkerTimeAxisView::clear_selected_time_axis_item()
376 selected_time_axis_item = 0 ;
380 * Returnsthe currently selected item upon this time axis
382 * @return the currently selected item pon this time axis
385 MarkerTimeAxisView::get_selected_time_axis_item()
387 return(selected_time_axis_item) ;
394 * convenience method to re-get the samples per unit and tell items upon this view
398 MarkerTimeAxisView::reset_samples_per_unit ()
400 set_samples_per_unit(_trackview.editor.get_current_zoom()) ;