1 /*
2  * Copyright (C) 2012-2013 Tim Mayberry <mojofunk@gmail.com>
3  * Copyright (C) 2012 Carl Hetherington <carl@carlh.net>
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 along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #include <glibmm/miscutils.h>
21 
22 #include "pbd/compose.h"
23 #include "ardour/playlist_factory.h"
24 #include "ardour/source_factory.h"
25 #include "ardour/region.h"
26 #include "ardour/region_factory.h"
27 #include "ardour/sndfilesource.h"
28 #include "ardour/audioregion.h"
29 #include "ardour/audioplaylist.h"
30 #include "audio_region_test.h"
31 #include "test_util.h"
32 
33 using namespace std;
34 using namespace PBD;
35 using namespace ARDOUR;
36 
37 void
setUp()38 AudioRegionTest::setUp ()
39 {
40 	TestNeedingSession::setUp ();
41 
42 	std::string const test_wav_path = Glib::build_filename (new_test_output_dir(), "test.wav");
43 	_playlist = PlaylistFactory::create (DataType::AUDIO, *_session, "test");
44 	_audio_playlist = boost::dynamic_pointer_cast<AudioPlaylist> (_playlist);
45 	_source = SourceFactory::createWritable (DataType::AUDIO, *_session, test_wav_path, get_test_sample_rate ());
46 
47 	/* Write a staircase to the source */
48 
49 	boost::shared_ptr<SndFileSource> s = boost::dynamic_pointer_cast<SndFileSource> (_source);
50 	assert (s);
51 
52 	int const signal_length = 4096;
53 
54 	Sample staircase[signal_length];
55 	for (int i = 0; i < signal_length; ++i) {
56 		staircase[i] = i;
57 	}
58 
59 	s->write (staircase, signal_length);
60 
61 	PropertyList plist;
62 	plist.add (Properties::start, 0);
63 	plist.add (Properties::length, 100);
64 	for (int i = 0; i < 16; ++i) {
65 		_r[i] = RegionFactory::create (_source, plist);
66 		_ar[i] = boost::dynamic_pointer_cast<AudioRegion> (_r[i]);
67 		_ar[i]->set_name (string_compose ("ar%1", i));
68 	}
69 }
70 
71 void
tearDown()72 AudioRegionTest::tearDown ()
73 {
74 	_playlist.reset ();
75 	_audio_playlist.reset ();
76 	_source.reset ();
77 	for (int i = 0; i < 16; ++i) {
78 		_r[i].reset ();
79 		_ar[i].reset ();
80 	}
81 
82 	TestNeedingSession::tearDown ();
83 }
84 
85 
86