-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainComponent.cpp
78 lines (62 loc) · 2.36 KB
/
MainComponent.cpp
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
#include "MainComponent.h"
//==============================================================================
MainComponent::MainComponent()
{
setSize (800, 900);
// Setup the Look and Feel
setLookAndFeel(&appLookAndFeel);
this->appLookAndFeel.setupLookAndFeel(appLookAndFeel);
if (juce::RuntimePermissions::isRequired (juce::RuntimePermissions::recordAudio)
&& ! juce::RuntimePermissions::isGranted (juce::RuntimePermissions::recordAudio))
{
juce::RuntimePermissions::request (juce::RuntimePermissions::recordAudio,
[&] (bool granted) { setAudioChannels (granted ? 2 : 0, 2); });
}
else
{
setAudioChannels (0, 2);
}
addAndMakeVisible(deckGUI1);
addAndMakeVisible(deckGUI2);
addAndMakeVisible(volumeMixer);
addAndMakeVisible(playlistComponent);
formatManager.registerBasicFormats();
}
MainComponent::~MainComponent()
{
shutdownAudio();
setLookAndFeel(nullptr);
}
//==============================================================================
void MainComponent::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
{
mixerSource.addInputSource(&player1, false);
mixerSource.addInputSource(&player2, false);
player1.prepareToPlay(samplesPerBlockExpected, sampleRate);
player2.prepareToPlay(samplesPerBlockExpected, sampleRate);
}
void MainComponent::getNextAudioBlock (const juce::AudioSourceChannelInfo& bufferToFill)
{
mixerSource.getNextAudioBlock(bufferToFill);
}
void MainComponent::releaseResources()
{
mixerSource.removeAllInputs();
player1.releaseResources();
player2.releaseResources();
mixerSource.releaseResources();
}
//==============================================================================
void MainComponent::paint (juce::Graphics& g)
{
g.fillAll (getLookAndFeel().findColour (juce::ResizableWindow::backgroundColourId));
}
void MainComponent::resized()
{
double deckHeight = getHeight() - getHeight()/3;
deckGUI1.setBounds(5, 5, (getWidth()/2)-10, deckHeight-10);
deckGUI2.setBounds(getWidth()/2 +5, 5, (getWidth()/2)-10, deckHeight-10);
double mixerHeight = 50;
volumeMixer.setBounds(5,deckHeight, getWidth()-10,mixerHeight);
playlistComponent.setBounds(5, deckHeight + mixerHeight+5, getWidth()-10, (getHeight()/3)-mixerHeight-10);
}