-
Notifications
You must be signed in to change notification settings - Fork 15
/
ShoutVST.cpp
134 lines (119 loc) · 3.57 KB
/
ShoutVST.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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include "ShoutVST.h"
#include <thread>
#include "version.h"
AudioEffect* createEffectInstance(audioMasterCallback audioMaster) {
return new ShoutVST(audioMaster);
}
VstInt32 ShoutVST::getVendorVersion() { return SHOUTVST_VERSION_INT; }
VstPlugCategory ShoutVST::getPlugCategory() { return kPlugCategEffect; }
ShoutVST::ShoutVST(audioMasterCallback audioMaster)
: AudioEffectX(audioMaster, 1, 0) {
setNumInputs(2);
setNumOutputs(2);
setUniqueID(CCONST('a', 'h', 'n', 'e'));
canProcessReplacing();
canDoubleReplacing(false);
noTail(false);
encSelected = nullptr;
pEditor = std::make_shared<ShoutVSTEditor>(this);
setEditor(pEditor.get());
}
ShoutVST::~ShoutVST() {
disconnect();
setEditor(nullptr);
}
bool ShoutVST::IsConnected() {
guard lock(mtx_);
return (encSelected != nullptr);
}
int ShoutVST::GetBitrate() { return std::stoi(pEditor->GetBitrate()); }
int ShoutVST::GetTargetSampleRate() {
return std::stoi(pEditor->GetTargetSampleRate());
}
void ShoutVST::processReplacing(float** inputs, float** outputs,
VstInt32 sampleFrames) {
if (!inputs || !outputs || sampleFrames <= 0) {
return;
}
float* in1 = inputs[0];
float* in2 = inputs[1];
float* out1 = outputs[0];
float* out2 = outputs[1];
for (VstInt32 i(0); i < sampleFrames; ++i) {
out1[i] = in1[i];
out2[i] = in2[i];
}
guard lock(mtx_);
if (encSelected) {
if (!encSelected->Process(inputs, sampleFrames)) {
disconnect();
}
}
}
void ShoutVST::connect() {
guard lock(mtx_);
if (encSelected) {
return;
}
encTmp = nullptr;
if (pEditor->getEncodingFormat() == "mp3") {
encTmp = std::make_shared<ShoutVSTEncoderMP3>(libShoutWrapper);
}
if (pEditor->getEncodingFormat() == "ogg") {
encTmp = std::make_shared<ShoutVSTEncoderOGG>(libShoutWrapper);
}
if (!encTmp ||
!encTmp->Initialize(GetBitrate(), (const int)updateSampleRate(),
GetTargetSampleRate()) ||
!libShoutWrapper.InitializeICECasting(
pEditor->getHostName(), pEditor->getProtocol(), pEditor->getPort(),
pEditor->getStreamName(), pEditor->getStreamURL(),
pEditor->getStreamGenre(), pEditor->getStreamDescription(),
std::to_string(encTmp->getBitrate()), pEditor->GetTargetSampleRate(),
pEditor->getStreamArtist(), pEditor->getStreamTitle(),
pEditor->getUserName(), pEditor->getPassword(),
pEditor->getMountPoint(), pEditor->getEncodingFormat())) {
disconnect();
}
std::thread t([this]() {
if (libShoutWrapper.waitForConnect()) {
guard lock(mtx_);
encSelected = encTmp;
pEditor->DisableAccordingly();
} else {
disconnect();
}
});
t.detach();
}
void ShoutVST::disconnect() {
guard lock(mtx_);
encSelected = nullptr;
encTmp = nullptr;
libShoutWrapper.StopICECasting();
pEditor->DisableAccordingly();
}
void ShoutVST::UpdateMetadata(const string& metadata) {
libShoutWrapper.UpdateMetadata(metadata.c_str());
}
bool ShoutVST::getEffectName(char* name) {
if (!name) {
return false;
}
vst_strncpy(name, "ShoutVST", kVstMaxEffectNameLen);
return true;
}
bool ShoutVST::getVendorString(char* text) {
if (!text) {
return false;
}
vst_strncpy(text, "github.com/Iunusov/ShoutVST", kVstMaxVendorStrLen);
return true;
}
bool ShoutVST::getProductString(char* text) {
if (!text) {
return false;
}
vst_strncpy(text, "ShoutVST", kVstMaxProductStrLen);
return true;
}