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