Switched to use libgnomecanvas (not the C++ one).
[ardour.git] / gtk2_ardour / marker_view.cc
1 /*
2     Copyright (C) 2003 Paul Davis 
3
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.
8
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.
13
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.
17
18     $Id$
19 */
20
21 #include <gtkmm.h>
22
23 #include "imageframe_time_axis.h"
24 #include "imageframe_view.h"
25 #include "canvas-simplerect.h"
26 #include "public_editor.h"
27 #include "marker_view.h"
28
29 using namespace ARDOUR ;
30 using namespace sigc;
31
32 sigc::signal<void,MarkerView*> MarkerView::GoingAway;
33
34 //---------------------------------------------------------------------------------------//
35 // Constructor / Desctructor
36
37 /**
38  * Constructs a new MarkerView
39  * 
40  * @param parent the parent canvas item
41  * @param tv the parent TimeAxisView of this item
42  * @param tavi the TimeAxisViewItem that this item is to be assciated (marking) with
43  * @param spu the current samples per unit 
44  * @param base_color
45  * @param mark_type the marker type/name text, eg fade out, pan up etc.
46  * @param mark_id unique name/id of this item
47  * @param start the start time of this item
48  * @param duration the duration of this item
49  */
50 MarkerView::MarkerView(GnomeCanvasGroup *parent,
51         TimeAxisView* tv,
52         ImageFrameView* marked,
53         double spu,
54         GdkColor& basic_color,
55         std::string mark_type,
56         std::string mark_id,
57         jack_nframes_t start,
58         jack_nframes_t duration)
59   : TimeAxisViewItem(mark_id, parent,*tv,spu,basic_color,start,duration)
60 {
61         mark_type_text = mark_type ;
62         marked_item = marked ;
63
64         // set the canvas item text to the marker type, not the id
65         set_name_text(mark_type_text) ;
66
67         // hoo up our canvas events
68         gtk_signal_connect (GTK_OBJECT(frame_handle_start), "event",
69                 (GtkSignalFunc) PublicEditor::canvas_markerview_start_handle_event,
70                 this);
71         
72         gtk_signal_connect (GTK_OBJECT(frame_handle_end), "event",
73                 (GtkSignalFunc) PublicEditor::canvas_markerview_end_handle_event,
74                 this);
75                 
76         gtk_signal_connect (GTK_OBJECT(group), "event",
77                 (GtkSignalFunc) PublicEditor::canvas_markerview_item_view_event,        this);
78         
79     /* handle any specific details required by the initial start end duration values */
80     set_position(start, this) ;
81     set_duration(duration, this) ;
82 }
83
84 /**
85  * Destructor
86  * Destroys this Marker Item and removes the association between itself and the item it is marking.
87  */
88 MarkerView::~MarkerView()
89 {
90         // remove the association our marked may still have to us
91         if(marked_item)
92         {
93                 marked_item->remove_marker_view_item(this, this) ;
94         }
95 }
96
97         
98 //---------------------------------------------------------------------------------------//
99 // Marker Type Methods
100
101 /**
102  * Sets the marker Type text of this this MarkerItem, eg fade_out, pan up etc. 
103  *
104  * @param type_text the marker type text of this item
105  */
106 void
107 MarkerView::set_mark_type_text(std::string type_text)
108 {
109         mark_type_text = type_text ;
110          MarkTypeChanged(mark_type_text, this) ; /* EMIT_SIGNAL */
111 }
112                 
113 /**
114  * Returns the marker Type of this this MarkerItem, eg fade_out, pan up etc. 
115  *
116  * @return the marker type text of this item
117  */
118 std::string
119 MarkerView::get_mark_type_text() const
120 {
121         return(mark_type_text) ;
122 }
123
124
125 //---------------------------------------------------------------------------------------//
126 // Marked Item Methods
127
128 ImageFrameView*
129 MarkerView::set_marked_item(ImageFrameView* item)
130 {
131         ImageFrameView* temp = marked_item ;
132         marked_item = item ;
133         
134          MarkedItemChanged(marked_item, this) ; /* EMIT_SIGNAL */
135         return(temp) ;
136 }
137
138 ImageFrameView*
139 MarkerView::get_marked_item()
140 {
141         return(marked_item) ;
142 }