summaryrefslogtreecommitdiff
path: root/libs/ardour/ardour/audio_region_importer.h
blob: d466dd793f3abc7efcd1a141742b78fa7c8fcf45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
 * Copyright (C) 2008-2009 Sakari Bergen <sakari.bergen@beatwaves.net>
 * Copyright (C) 2009-2012 David Robillard <d@drobilla.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#ifndef __ardour_audio_region_importer_h__
#define __ardour_audio_region_importer_h__

#include <list>
#include <map>
#include <utility>

#include <boost/shared_ptr.hpp>

#include "pbd/xml++.h"
#include "pbd/id.h"
#include "ardour/element_importer.h"
#include "ardour/element_import_handler.h"
#include "ardour/import_status.h"

namespace ARDOUR {

class Region;
class Session;
class Source;

class LIBARDOUR_API AudioRegionImportHandler : public ElementImportHandler
{
  public:
	// Inerface implementation
	AudioRegionImportHandler (XMLTree const & source, Session & session);
	std::string get_info () const;

	void create_regions_from_children (XMLNode const & node, ElementList & list);

	// Source management
	bool check_source (std::string const & filename) const;
	void add_source (std::string const & filename, boost::shared_ptr<Source> const & source);
	boost::shared_ptr<Source> const & get_source (std::string const & filename) const;

	// Id management
	void register_id (PBD::ID & old_id, PBD::ID & new_id);
	PBD::ID const & get_new_id (PBD::ID & old_id) const;

  private:
	// Source management
	typedef std::map<std::string, boost::shared_ptr<Source> > SourceMap;
	typedef std::pair<std::string, boost::shared_ptr<Source> > SourcePair;
	SourceMap sources;

	// Id management
	typedef std::map<PBD::ID, PBD::ID> IdMap;
	typedef std::pair<PBD::ID, PBD::ID> IdPair;
	IdMap id_map;
};

class LIBARDOUR_API AudioRegionImporter : public ElementImporter
{
  public:
	AudioRegionImporter (XMLTree const & source, Session & session, AudioRegionImportHandler & handler, XMLNode const & node);
	~AudioRegionImporter ();

	// Interface implementation
	std::string get_info () const;
	ImportStatus * get_import_status () { return &status; }

	// other stuff
	void add_sources_to_session ();
	XMLNode const & get_xml ();

  protected:
	bool _prepare_move ();
	void _cancel_move ();
	void _move ();

  private:

	XMLNode xml_region;
	AudioRegionImportHandler & handler;
	PBD::ID old_id;
	PBD::ID id;
	std::list<std::string> filenames;
	ImportStatus status;

	bool parse_xml_region ();
	bool parse_source_xml ();
	std::string get_sound_dir (XMLTree const & tree);

	void prepare_region ();
	void prepare_sources ();
	std::vector<boost::shared_ptr<Region> > region;
	bool region_prepared;
	bool sources_prepared;
};

} // namespace ARDOUR

#endif