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