a0e8f2bbf0c95a847c768b852760345f8c653992
[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 */
19
20 #include <gtkmm.h>
21
22 #include "imageframe_time_axis.h"
23 #include "imageframe_view.h"
24 #include "canvas-simplerect.h"
25 #include "public_editor.h"
26 #include "marker_view.h"
27
28 using namespace ARDOUR ;
29
30 PBD::Signal1<void,MarkerView*> MarkerView::CatchDeletion
31
32 //---------------------------------------------------------------------------------------//
33 // Constructor / Desctructor
34
35 /**
36  * Constructs a new MarkerView
37  *
38  * @param parent the parent canvas item
39  * @param tv the parent TimeAxisView of this item
40  * @param tavi the TimeAxisViewItem that this item is to be assciated (marking) with
41  * @param spu the current samples per unit
42  * @param base_color
43  * @param mark_type the marker type/name text, eg fade out, pan up etc.
44  * @param mark_id unique name/id of this item
45  * @param start the start time of this item
46  * @param duration the duration of this item
47  */
48 MarkerView::MarkerView(ArdourCanvas::Group *parent,
49                        TimeAxisView* tv,
50                        ImageFrameView* marked,
51                        double spu,
52                        Gdk::Color& basic_color,
53                        std::string mark_type,
54                        std::string mark_id,
55                        nframes_t start,
56                        nframes_t duration)
57   : TimeAxisViewItem(mark_id, *parent,*tv,spu,basic_color,start,duration)
58 {
59         mark_type_text = mark_type ;
60         marked_item = marked ;
61
62         // set the canvas item text to the marker type, not the id
63         set_name_text(mark_type_text) ;
64
65         // hook up our canvas events
66
67         if (frame_handle_start) {
68                 frame_handle_start->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_markerview_start_handle_event), frame_handle_start, this));
69                 frame_handle_end->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_markerview_end_handle_event), frame_handle_end, this));
70         }
71         group->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_markerview_item_view_event), group, this));
72
73         set_position(start, this) ;
74         set_duration(duration, this) ;
75 }
76
77 /**
78  * Destructor
79  * Destroys this Marker Item and removes the association between itself and the item it is marking.
80  */
81 MarkerView::~MarkerView()
82 {
83         // remove the association our marked may still have to us
84         if(marked_item)
85         {
86                 marked_item->remove_marker_view_item(this, this) ;
87         }
88 }
89
90
91 //---------------------------------------------------------------------------------------//
92 // Marker Type Methods
93
94 /**
95  * Sets the marker Type text of this this MarkerItem, eg fade_out, pan up etc.
96  *
97  * @param type_text the marker type text of this item
98  */
99 void
100 MarkerView::set_mark_type_text(std::string type_text)
101 {
102         mark_type_text = type_text ;
103          MarkTypeChanged(mark_type_text, this) ; /* EMIT_SIGNAL */
104 }
105
106 /**
107  * Returns the marker Type of this this MarkerItem, eg fade_out, pan up etc.
108  *
109  * @return the marker type text of this item
110  */
111 std::string
112 MarkerView::get_mark_type_text() const
113 {
114         return(mark_type_text) ;
115 }
116
117
118 //---------------------------------------------------------------------------------------//
119 // Marked Item Methods
120
121 ImageFrameView*
122 MarkerView::set_marked_item(ImageFrameView* item)
123 {
124         ImageFrameView* temp = marked_item ;
125         marked_item = item ;
126
127          MarkedItemChanged(marked_item, this) ; /* EMIT_SIGNAL */
128         return(temp) ;
129 }
130
131 ImageFrameView*
132 MarkerView::get_marked_item()
133 {
134         return(marked_item) ;
135 }