Fix pollution of global namespace by Evoral.
[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 <sigc++/signal.h>
28
29 #include <ardour/types.h>
30
31 using std::string;
32
33 class XMLTree;
34 namespace ARDOUR {
35
36 class Session;
37
38 /// Virtual interface class for element importers
39 class ElementImporter
40 {
41   public:
42
43         ElementImporter (XMLTree const & source, ARDOUR::Session & session);
44         virtual ~ElementImporter () {};
45         
46         /** Returns the element name
47          * @return the name of the element
48          */
49         virtual string get_name () const { return name; };
50         
51         /** Gets a textual representation of the element
52          * @return a textual representation on this specific element
53          */
54         virtual string get_info () const = 0;
55         
56         /** Prepares to move element
57          * Should take care of all tasks that need to be done 
58          * before moving the element. This includes prompting
59          * the user for more information if necessary.
60          *
61          * If the element can be moved, queued should be set to true.
62          *
63          * @return whther or not the element could be prepared for moving
64          */
65         virtual bool prepare_move () = 0;
66         
67         /** Cancels moving of element
68          * If the element has been set to be moved, this cancels the move.
69          * queued should be set to false.
70          */
71         virtual void cancel_move () = 0;
72         
73         /** Moves the element to the taget session
74          * In addition to actually adding the element to the session
75          * changing ids, renaming files etc. should be taken care of.
76          */
77         virtual void move () = 0;
78         
79         /// Check if element is broken. Cannot be moved if broken.
80         bool broken () { return _broken; }
81         
82         /// Signal that requests for anew name
83         static sigc::signal <std::pair<bool, string>, string, string> Rename;
84         
85         /// Signal for ok/cancel prompting
86         static sigc::signal <bool, string> Prompt;
87         
88   protected:
89         /// Source XML-tree
90         XMLTree const & source;
91         
92         /// Target session
93         ARDOUR::Session & session;
94         
95         /// Ture if the element has been prepared and queued for importing
96         bool    queued;
97         
98         /// Name of element
99         string  name;
100         
101         /// The sample rate of the session from which we are importing
102         nframes_t sample_rate;
103         
104         /// Converts smpte time to a string
105         string smpte_to_string(SMPTE::Time & time) const;
106         
107         /// Converts samples so that times match the sessions sample rate
108         nframes_t rate_convert_samples (nframes_t samples) const;
109         
110         /// Converts samples so that times match the sessions sample rate (for straight use in XML)
111         string rate_convert_samples (string const & samples) const;
112         
113         /// Set element broken
114         void set_broken () { _broken = true; }
115         
116   private:
117         bool _broken;
118 };
119
120 } // namespace ARDOUR
121
122 #endif