File size: 2,003 Bytes
8c39918
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#include "SamplePlayer.h"

SamplePlayer::SamplePlayer() = default;

SamplePlayer::~SamplePlayer()
{
    shutdown();
}

bool SamplePlayer::initialize()
{
    auto result = deviceManager.initialise(
        0,              // input channels
        2,              // output channels
        nullptr,        // XML state
        true,           // select default device
        "",             // preferred device
        nullptr         // preferred setup
    );
    
    if (result.isNotEmpty())
    {
        jassertfalse;
        return false;
    }
    
    engine = std::make_unique<AudioEngine>();
    
    deviceManager.addAudioCallback(engine.get());
    
    return true;
}

void SamplePlayer::shutdown()
{
    if (engine != nullptr)
    {
        deviceManager.removeAudioCallback(engine.get());
        engine.reset();
    }
    
    deviceManager.closeAudioDevice();
}

void SamplePlayer::play(int padIndex)
{
    if (engine)
        engine->playPad(padIndex);
}

void SamplePlayer::stop(int padIndex)
{
    if (engine)
        engine->stopPad(padIndex);
}

void SamplePlayer::stopAll()
{
    if (engine)
        engine->stopAll();
}

bool SamplePlayer::loadSample(int padIndex, const juce::String& filePath)
{
    if (engine)
        return engine->loadSample(padIndex, filePath);
    return false;
}

void SamplePlayer::clearSample(int padIndex)
{
    if (engine)
        engine->clearPad(padIndex);
}

void SamplePlayer::setBpm(double bpm)
{
    if (engine)
        engine->setBpm(bpm);
}

void SamplePlayer::setLoopMode(int padIndex, bool loop)
{
    if (engine)
        engine->setLoopMode(padIndex, loop);
}

void SamplePlayer::setVolume(int padIndex, float volume)
{
    if (engine)
        engine->setVolume(padIndex, volume);
}

void SamplePlayer::enableReverb(bool enabled)
{
    if (engine)
        engine->setReverb(enabled ? 0.5f : 0.0f);
}

void SamplePlayer::enableDelay(bool enabled)
{
    if (engine)
        engine->setDelay(enabled ? 0.3f : 0.0f, enabled ? 0.4f : 0.0f);
}