use new syntax for connecting to backend signals that enforces explicit connection...
[ardour.git] / libs / ardour / ardour / element_importer.h
1 /*
2     Copyright (C) 2008 Paul Davis
3     Author: Sakari Bergen
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 */
20
21 #ifndef __ardour_element_importer_h__
22 #define __ardour_element_importer_h__
23
24 #include <string>
25 #include <utility>
26
27 #include "pbd/signals.h"
28 #include "ardour/types.h"
29
30 class XMLTree;
31 namespace ARDOUR {
32
33 class Session;
34 class ImportStatus;
35
36 /// Virtual interface class for element importers
37 class ElementImporter
38 {
39   public:
40
41         ElementImporter (XMLTree const & source, ARDOUR::Session & session);
42         virtual ~ElementImporter ();
43
44         /** Returns the element name
45          * @return the name of the element
46          */
47         virtual std::string get_name () const { return name; };
48
49         /** Gets a textual representation of the element
50          * @return a textual representation on this specific element
51          */
52         virtual std::string get_info () const = 0;
53
54         /** Gets import status, if applicable. */
55         virtual ImportStatus * get_import_status () { return 0; }
56
57         /** Prepares to move element
58          *
59          * @return whther or not the element could be prepared for moving
60          */
61         bool prepare_move ();
62
63         /** Cancels moving of element
64          * If the element has been set to be moved, this cancels the move.
65          */
66         void cancel_move ();
67
68         /// Moves the element to the taget session
69         void move ();
70
71         /// Check if element is broken. Cannot be moved if broken.
72         bool broken () { return _broken; }
73
74         /// Signal that requests for anew name
75         static PBD::Signal2<std::pair<bool, std::string>,std::string, std::string> Rename;
76
77         /// Signal for ok/cancel prompting
78         static PBD::Signal1<bool,std::string> Prompt;
79
80   protected:
81
82         /** Moves the element to the taget session
83          * In addition to actually adding the element to the session
84          * changing ids, renaming files etc. should be taken care of.
85          */
86         virtual void _move () = 0;
87
88         /** Should take care of all tasks that need to be done
89          * before moving the element. This includes prompting
90          * the user for more information if necessary.
91          *
92          * @return whether or not the element can be moved
93          */
94         virtual bool _prepare_move () = 0;
95
96         /// Cancel move
97         virtual void _cancel_move () = 0;
98
99         /// Source XML-tree
100         XMLTree const & source;
101
102         /// Target session
103         ARDOUR::Session & session;
104
105         /// Ture if the element has been prepared and queued for importing
106         bool queued () { return _queued; }
107
108         /// Name of element
109         std::string  name;
110
111         /// The sample rate of the session from which we are importing
112         nframes_t sample_rate;
113
114         /// Converts timecode time to a string
115         std::string timecode_to_string (Timecode::Time & time) const;
116
117         /// Converts samples so that times match the sessions sample rate
118         nframes_t rate_convert_samples (nframes_t samples) const;
119
120         /// Converts samples so that times match the sessions sample rate (for straight use in XML)
121         std::string rate_convert_samples (std::string const & samples) const;
122
123         /// Set element broken
124         void set_broken () { _broken = true; }
125
126   private:
127         bool _queued;
128         bool _broken;
129 };
130
131 } // namespace ARDOUR
132
133 #endif