Anklang-0.3.0.dev886+g785567a1 anklang-0.3.0.dev886+g785567a1
ASE — Anklang Sound Engine (C++)

« « « Anklang Documentation
Loading...
Searching...
No Matches
test-setup.cc
Go to the documentation of this file.
1 // This Source Code Form is licensed MPL-2.0: http://mozilla.org/MPL/2.0
2#include "trkn/tracktion.hh" // PCH include must come first
3#include <ase/project.hh>
4#include <ase/clip.hh>
5#include <ase/track.hh>
6#include <ase/testing.hh>
7#include <ase/path.hh>
8#include <ase/platform.hh>
9
10namespace Ase {
11
12static tracktion::WaveAudioClip::Ptr
13load_audio_file_as_clip (tracktion::Edit &edit, const juce::File &file)
14{
15 edit.ensureNumberOfAudioTracks (1);
16 if (auto track = tracktion::getAudioTracks (edit)[0]) {
17 tracktion::AudioFile audioFile (edit.engine, file);
18 if (audioFile.isValid())
19 if (auto newClip =
20 track->insertWaveClip (file.getFileNameWithoutExtension(), file,
21 { { {}, tracktion::TimeDuration::fromSeconds (audioFile.getLength()) }, {} }, false))
22 return newClip;
23 }
24 return {};
25}
26
27template<typename ClipType> static typename ClipType::Ptr
28loop_around_clip (ClipType &clip)
29{
30 using namespace std::literals;
31 auto &transport = clip.edit.getTransport();
32 transport.setLoopRange (clip.getEditTimeRange());
33 transport.looping = true;
34 transport.setPosition (0s);
35 return clip;
36}
37
38void
39test_audio_sample_load()
40{
41 ProjectImplP project = ProjectImpl::create ("AudioSampleTest");
42 TASSERT (project);
43 project->_activate();
44
45 // Verify project was created successfully
46 TASSERT (project->name() == "AudioSampleTest");
47 TASSERT (project->bpm() == 120.0);
48
49 // Load audio sample as clip (moved from project.cc test_setup)
50 const std::string sample01 = anklang_runpath (RPath::SAMPLEDIR, "freepats-vorbis/Tone/000_Acoustic_Grand_Piano_acpiano_0.ogg");
52 auto clip = load_audio_file_as_clip (*project->edit_, sampleFile);
53 TASSERT (clip != nullptr);
54 loop_around_clip (*clip);
55 project->edit_->getTransport().ensureContextAllocated();
56
57 project->_deactivate();
58 project->discard();
59}
60TEST_ADD (test_audio_sample_load);
61
62} // Ase
String getFileNameWithoutExtension() const
The Anklang C++ API namespace.
Definition api.hh:8
std::string anklang_runpath(RPath rpath, const String &segment)
Retrieve various resource paths at runtime.
Definition platform.cc:58
#define TASSERT(cond)
Unconditional test assertion, enters breakpoint if not fullfilled.
Definition testing.hh:24
#define TEST_ADD(fun)
Register a function to run as part of the unit test suite.
Definition testing.hh:31