d73440ad540a7f3e8a2fd8ce18127620d315e7fa
[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(ArdourCanvas::Group *parent,
51                        TimeAxisView* tv,
52                        ImageFrameView* marked,
53                        double spu,
54                        Gdk::Color& 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         // hook up our canvas events
68
69         frame_handle_start->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_markerview_start_handle_event), frame_handle_start, this));
70         frame_handle_end->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_markerview_end_handle_event), frame_handle_end, this));
71         group->signal_event().connect (bind (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 }