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 "imageframe_time_axis.h"
27 #include "imageframe_time_axis_group.h"
28 #include "marker_time_axis.h"
29 #include "marker_time_axis_view.h"
30 #include "public_editor.h"
32 #include "imageframe_view.h"
33 #include "imageframe.h"
34 #include "gui_thread.h"
36 using namespace ARDOUR;
39 sigc::signal<void,ImageFrameView*> ImageFrameView::GoingAway;
42 * Constructs a new ImageFrameView upon the canvas
44 * @param item_id unique id of this item
45 * @param parent the parent canvas item
46 * @param tv the time axis view that this item is to be placed upon
47 * @param group the ImageFrameGroup that this item is a member of
48 * @param spu the current samples per canvas unit
49 * @param start the start frame ogf this item
50 * @param duration the duration of this item
51 * @param rgb_data the rgb data of the image
52 * @param width the width of the original rgb_data image data
53 * @param height the width of the origianl rgb_data image data
54 * @param num_channels the number of color channels within rgb_data
56 ImageFrameView::ImageFrameView(const string & item_id,
57 ArdourCanvas::Group *parent,
58 ImageFrameTimeAxis* tv,
59 ImageFrameTimeAxisGroup* item_group,
61 Gdk::Color& basic_color,
64 unsigned char* rgb_data,
67 uint32_t num_channels)
68 : TimeAxisViewItem(item_id, *parent, *tv, spu, basic_color, start, duration,
69 TimeAxisViewItem::Visibility (TimeAxisViewItem::ShowNameText|
70 TimeAxisViewItem::ShowNameHighlight|
71 TimeAxisViewItem::ShowFrame|
72 TimeAxisViewItem::ShowHandles))
75 the_parent_group = item_group;
76 set_name_text(item_id);
78 image_data_width = width;
79 image_data_height = height;
80 image_data_num_channels = num_channels;
82 //This should be art_free'd once the ArtPixBuf is destroyed - this should happen when we destroy the imageframe canvas item
83 unsigned char* the_rgb_data = (unsigned char*) art_alloc(width*height*num_channels);
84 memcpy(the_rgb_data, rgb_data, (width*height*num_channels));
87 pbuf = art_pixbuf_new_rgba(the_rgb_data, width, height, (num_channels * width));
90 //calculate our image width based on the track height
91 double im_ratio = (double)width/(double)height;
92 double im_width = ((double)(trackview.current_height() - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE) * im_ratio);
94 imageframe = new ImageFrame (*group, pbuf, 1.0, 1.0, ANCHOR_NW, im_width, (trackview.current_height() - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE));
96 frame_handle_start->signal_event().connect (sigc::bind (sigc::mem_fun (trackview.editor, &PublicEditor::canvas_imageframe_start_handle_event), frame_handle_start, this));
97 frame_handle_end->signal_event().connect (sigc::bind (sigc::mem_fun (trackview.editor, &PublicEditor::canvas_imageframe_end_handle_event), frame_handle_end, this));
98 group->signal_event().connect (sigc::bind (sigc::mem_fun (trackview.editor, &PublicEditor::canvas_imageframe_item_view_event), imageframe, this));
100 frame_handle_start->raise_to_top();
101 frame_handle_end->raise_to_top();
103 set_position(start, this);
104 set_duration(duration, this);
106 MarkerView::CatchDeletion.connect (*this, boost::bind (&ImageFrameView::remove_marker_view_item, this, _1), gui_context());
111 * Reposible for removing and destroying all marker items associated with this item
113 ImageFrameView::~ImageFrameView()
115 CatchDeletion (this);
117 // destroy any marker items we have associated with this item
119 for(MarkerViewList::iterator iter = marker_view_list.begin(); iter != marker_view_list.end(); ++iter)
121 MarkerView* mv = (*iter);
123 MarkerViewList::iterator next = iter;
126 // remove the item from our marker list
127 // the current iterator becomes invalid after this point, so we cannot call next upon it
128 // luckily enough, we already have next
129 marker_view_list.erase(iter);
131 // remove the item from the marker time axis
132 MarkerTimeAxisView* mtav = dynamic_cast<MarkerTimeAxis*>(&mv->get_time_axis_view())->get_view();
135 mtav->remove_marker_view(mv, this);
138 mv->set_marked_item(0);
142 // set our iterator to next, as we have invalided the current iterator with the call to erase
146 // if we are the currently selected item withi the parent track, we need to se-select
149 if(the_parent_group->get_view().get_selected_imageframe_view() == this)
151 the_parent_group->get_view().clear_selected_imageframe_item(false);
160 //---------------------------------------------------------------------------------------//
161 // Position and duration Accessors/Mutators
164 * Set the position of this item to the specified value
166 * @param pos the new position
167 * @param src the identity of the object that initiated the change
168 * @return true if the position change was a success, false otherwise
171 ImageFrameView::set_position(framepos_t pos, void* src, double* delta)
173 framepos_t old_pos = frame_position;
175 // do the standard stuff
176 bool ret = TimeAxisViewItem::set_position(pos, src, delta);
178 // everything went ok with the standard stuff?
180 /* move each of our associated markers with this ImageFrameView */
181 for (MarkerViewList::iterator i = marker_view_list.begin(); i != marker_view_list.end(); ++i)
183 // calculate the offset of the marker
184 MarkerView* mv = (MarkerView*)*i;
185 framepos_t marker_old_pos = mv->get_position();
187 mv->set_position(pos + (marker_old_pos - old_pos), src);
195 * Sets the duration of this item
197 * @param dur the new duration of this item
198 * @param src the identity of the object that initiated the change
199 * @return true if the duration change was succesful, false otherwise
202 ImageFrameView::set_duration(framepos_t dur, void* src)
204 /* do the standard stuff */
205 bool ret = TimeAxisViewItem::set_duration(dur, src);
207 // eveything went ok with the standard stuff?
210 /* handle setting the sizes of our canvas itesm based on the new duration */
211 imageframe->property_drawwidth() = trackview.editor.sample_to_pixel(get_duration());
217 //---------------------------------------------------------------------------------------//
218 // Parent Component Methods
221 * Sets the parent ImageFrameTimeAxisGroup of thie item
222 * each Item must be part of exactly one group (or 'scene') upon the timeline
224 * @param group the new parent group
227 ImageFrameView::set_time_axis_group(ImageFrameTimeAxisGroup* group)
229 the_parent_group = group;
233 * Returns the parent group of this item
235 * @return the parent group of this item
237 ImageFrameTimeAxisGroup*
238 ImageFrameView::get_time_axis_group()
240 return(the_parent_group);
244 //---------------------------------------------------------------------------------------//
248 * Set the height of this item
250 * @param h the new height
253 ImageFrameView::set_height (gdouble h)
255 // set the image size
256 // @todo might have to re-get the image data, for a large height...hmmm.
257 double im_ratio = (double)image_data_width/(double)image_data_height;
259 imageframe->property_width() = (h - TimeAxisViewItem::NAME_Y_OFFSET) * im_ratio;
260 imageframe->property_height() = h - TimeAxisViewItem::NAME_Y_OFFSET;
262 frame->raise_to_top();
263 imageframe->raise_to_top();
264 name_highlight->raise_to_top();
265 name_text->raise_to_top();
266 frame_handle_start->raise_to_top();
267 frame_handle_end->raise_to_top();
269 name_text->property_y() = h - TimeAxisViewItem::NAME_Y_OFFSET;
270 frame->property_y2() = h;
272 name_highlight->property_y1() = (gdouble) h - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE;
273 name_highlight->property_y2() = (gdouble) h - 1.0;
277 //---------------------------------------------------------------------------------------//
278 // MarkerView methods
281 * Adds a markerView to the list of marker views associated with this item
283 * @param item the marker item to add
284 * @param src the identity of the object that initiated the change
287 ImageFrameView::add_marker_view_item(MarkerView* item, void* src)
289 marker_view_list.push_back(item);
290 MarkerViewAdded(item, src); /* EMIT_SIGNAL */
294 * Removes the named marker view from the list of marker view associated with this item
295 * The Marker view is not destroyed on removal, so the caller must handle the item themself
297 * @param markId the id/name of the item to remove
298 * @param src the identity of the object that initiated the change
299 * @return the removed marker item
302 ImageFrameView::remove_named_marker_view_item(const string & markerId, void* src)
305 MarkerViewList::iterator i = marker_view_list.begin();
307 while(i != marker_view_list.end())
309 if (((MarkerView*)*i)->get_item_name() == markerId)
313 marker_view_list.erase(i);
315 MarkerViewRemoved(mv,src); /* EMIT_SIGNAL */
317 // iterator is now invalid, but since we should only ever have
318 // one item with the specified name, things are ok, and we can
319 // break from the while loop
329 * Removes item from the list of marker views assocaited with this item
330 * This method will do nothing if item if not assiciated with this item
332 * @param item the item to remove
333 * @param src the identity of the object that initiated the change
336 ImageFrameView::remove_marker_view_item (MarkerView* mv)
338 ENSURE_GUI_THREAD (*this, &ImageFrameView::remove_marker_view_item, mv, src)
340 MarkerViewList::iterator i;
342 if ((i = find (marker_view_list.begin(), marker_view_list.end(), mv)) != marker_view_list.end()) {
343 marker_view_list.erase(i);
344 MarkerViewRemoved (mv, src); /* EMIT_SIGNAL */
349 * Determines if the named marker is one of those associated with this item
351 * @param markId the id/name of the item to search for
354 ImageFrameView::has_marker_view_item(const string & mname)
358 for (MarkerViewList::const_iterator ci = marker_view_list.begin(); ci != marker_view_list.end(); ++ci)
360 if (((MarkerView*)*ci)->get_item_name() == mname)
364 // found the item, so we can break the for loop