*** NEW CODING POLICY ***
[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 "pbd/filesystem.h"
33 #include "ardour/types.h"
34 #include "ardour/element_importer.h"
35 #include "ardour/element_import_handler.h"
36
37 namespace ARDOUR {
38
39 class Region;
40
41 class AudioRegionImportHandler : public ElementImportHandler
42 {
43   public:
44         // Inerface implementation
45         AudioRegionImportHandler (XMLTree const & source, Session & session);
46         string get_info () const;
47         
48         void create_regions_from_children (XMLNode const & node, ElementList & list);
49         
50         // Source management
51         bool check_source (string const & filename) const;
52         void add_source (string const & filename, boost::shared_ptr<Source> const & source);
53         boost::shared_ptr<Source> const & get_source (string const & filename) const;
54
55         // Id management
56         void register_id (PBD::ID & old_id, PBD::ID & new_id);
57         PBD::ID const & get_new_id (PBD::ID & old_id) const;
58
59   private:
60         // Source management
61         typedef std::map<string, boost::shared_ptr<Source> > SourceMap;
62         typedef std::pair<string, boost::shared_ptr<Source> > SourcePair;
63         SourceMap sources;
64
65         // Id management
66         typedef std::map<PBD::ID, PBD::ID> IdMap;
67         typedef std::pair<PBD::ID, PBD::ID> IdPair;
68         IdMap id_map;
69 };
70
71 class AudioRegionImporter : public ElementImporter
72 {
73   public:
74         AudioRegionImporter (XMLTree const & source, Session & session, AudioRegionImportHandler & handler, XMLNode const & node);
75         ~AudioRegionImporter ();
76
77         // Interface implementation
78         string get_info () const;
79         
80         // other stuff
81         void add_sources_to_session ();
82         XMLNode const & get_xml ();
83
84   protected:
85         bool _prepare_move ();
86         void _cancel_move ();
87         void _move ();
88
89   private:
90
91         XMLNode xml_region;
92         AudioRegionImportHandler & handler;
93         PBD::ID old_id;
94         PBD::ID id;
95         std::list<string> filenames;
96         
97         bool parse_xml_region ();
98         bool parse_source_xml ();
99         PBD::sys::path get_sound_dir (XMLTree const & tree);
100         
101         void prepare_region ();
102         void prepare_sources ();
103         std::vector<boost::shared_ptr<Region> > region;
104         bool region_prepared;
105         bool sources_prepared;
106 };
107
108 } // namespace ARDOUR
109
110 #endif