Make some musical operations on music-locked regions operate in beats.
[ardour.git] / libs / ardour / ardour / audio_region_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_audio_region_importer_h__
22 #define __ardour_audio_region_importer_h__
23
24 #include <list>
25 #include <map>
26 #include <utility>
27
28 #include <boost/shared_ptr.hpp>
29
30 #include "pbd/xml++.h"
31 #include "pbd/id.h"
32 #include "ardour/element_importer.h"
33 #include "ardour/element_import_handler.h"
34 #include "ardour/import_status.h"
35
36 namespace ARDOUR {
37
38 class Region;
39 class Session;
40 class Source;
41
42 class LIBARDOUR_API AudioRegionImportHandler : public ElementImportHandler
43 {
44   public:
45         // Inerface implementation
46         AudioRegionImportHandler (XMLTree const & source, Session & session);
47         std::string get_info () const;
48
49         void create_regions_from_children (XMLNode const & node, ElementList & list);
50
51         // Source management
52         bool check_source (std::string const & filename) const;
53         void add_source (std::string const & filename, boost::shared_ptr<Source> const & source);
54         boost::shared_ptr<Source> const & get_source (std::string const & filename) const;
55
56         // Id management
57         void register_id (PBD::ID & old_id, PBD::ID & new_id);
58         PBD::ID const & get_new_id (PBD::ID & old_id) const;
59
60   private:
61         // Source management
62         typedef std::map<std::string, boost::shared_ptr<Source> > SourceMap;
63         typedef std::pair<std::string, boost::shared_ptr<Source> > SourcePair;
64         SourceMap sources;
65
66         // Id management
67         typedef std::map<PBD::ID, PBD::ID> IdMap;
68         typedef std::pair<PBD::ID, PBD::ID> IdPair;
69         IdMap id_map;
70 };
71
72 class LIBARDOUR_API AudioRegionImporter : public ElementImporter
73 {
74   public:
75         AudioRegionImporter (XMLTree const & source, Session & session, AudioRegionImportHandler & handler, XMLNode const & node);
76         ~AudioRegionImporter ();
77
78         // Interface implementation
79         std::string get_info () const;
80         ImportStatus * get_import_status () { return &status; }
81
82         // other stuff
83         void add_sources_to_session ();
84         XMLNode const & get_xml ();
85
86   protected:
87         bool _prepare_move ();
88         void _cancel_move ();
89         void _move ();
90
91   private:
92
93         XMLNode xml_region;
94         AudioRegionImportHandler & handler;
95         PBD::ID old_id;
96         PBD::ID id;
97         std::list<std::string> filenames;
98         ImportStatus status;
99
100         bool parse_xml_region ();
101         bool parse_source_xml ();
102         std::string get_sound_dir (XMLTree const & tree);
103
104         void prepare_region ();
105         void prepare_sources ();
106         std::vector<boost::shared_ptr<Region> > region;
107         bool region_prepared;
108         bool sources_prepared;
109 };
110
111 } // namespace ARDOUR
112
113 #endif