-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzasf.cpp
201 lines (151 loc) · 4.11 KB
/
zasf.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*
ZynWise - ZynAddSubFX presets player in vst format
zasf.cpp - ZynAddSubFx wrapper
Copyright (C) 2013 Alessandro De Santis
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License
as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License (version 2 or later) for more details.
You should have received a copy of the GNU General Public License (version 2)
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <sstream>
using namespace std;
#include "zasf.h"
int denormalkillbuf_usercount = 0;
Zasf::Zasf()
{
CreateDenormalKillBuffer();
config.init();
SAMPLE_RATE = config.cfg.SampleRate;
SOUND_BUFFER_SIZE = config.cfg.SoundBufferSize;
OSCIL_SIZE = config.cfg.OscilSize;
vmaster = new Master();
vmaster->swaplr = 0;
SelectPreset(0);
pbuffer = NULL;
int i = 0;
_programs[i].push_back(P0(vmaster->Pvolume));
ParamSetter[i][knobVolume] = &Zasf::SetMasterVolume;
}
ParamInfo *Zasf::Param(int program, int index)
{
if (program < 0 || program > PROGRAMS_COUNT)
return NULL;
if (index < 0 || index > PARAMS_COUNT)
return NULL;
return &_programs[program][index];
}
Zasf::~Zasf()
{
if (pbuffer)
delete pbuffer;
delete vmaster;
DestroyDenormalKillBuffer();
}
void Zasf::CreateDenormalKillBuffer()
{
denormalkillbuf_usercount++;
if (denormalkillbuf_usercount == 1)
{
denormalkillbuf = new REALTYPE [SOUND_BUFFER_SIZE];
for(int i = 0; i < SOUND_BUFFER_SIZE; i++)
denormalkillbuf[i] = (RND - 0.5) * 1e-16;
}
}
void Zasf::DestroyDenormalKillBuffer()
{
denormalkillbuf_usercount--;
if (denormalkillbuf_usercount == 0)
delete[] denormalkillbuf;
}
void Zasf::SelectPreset(int index)
{
if (index < 0 || index > 3)
return;
preset_index = index;
vmaster->part[0]->AllNotesOff();
string filename = presets[index];
if (filename.length() == 0)
vmaster->part[0]->defaultsinstrument();
else
vmaster->part[0]->loadXMLinstrument(filename.c_str());
vmaster->part[0]->applyparameters();
}
void Zasf::SetPreset(int index, string filename)
{
if (index < 0 || index > 3)
return;
presets[index] = filename;
if (index == preset_index)
SelectPreset(index);
}
void Zasf::StoreProgram(char **mem, int &size)
{
stringstream bag;
bag << (int)vmaster->Pvolume << endl;
bag << preset_index << endl;
bag << presets[0] << endl;
bag << presets[1] << endl;
bag << presets[2] << endl;
bag << presets[3] << endl;
if (pbuffer != NULL)
delete pbuffer;
size = bag.tellp();
*mem = pbuffer = new char[size];
bag.read(pbuffer, size);
}
void Zasf::LoadProgram(char *mem, int size)
{
stringstream bag;
bag.write((const char *)mem, size);
string s;
int v;
getline(bag, s);
v = atoi(s.c_str());
vmaster->setPvolume(v);
getline(bag, s);
v = atoi(s.c_str());
preset_index = v;
getline(bag, presets[0]);
getline(bag, presets[1]);
getline(bag, presets[2]);
getline(bag, presets[3]);
SelectPreset(preset_index);
}
void Zasf::SetParam(int program, int index, double value)
{
_programs[program][index].SetNormalValue(value);
(this->*ParamSetter[program][index])(value, true);
}
void Zasf::SetMasterVolume(double value, bool normal)
{
if (!normal)
vmaster->setPvolume(value);
else
vmaster->setPvolume((int)(value * 127 + 0.5f));
}
///////////////////////////////////////////////////
bool XizFileChooser(HWND hWnd, string& filename)
{
OPENFILENAME ofn;
char buffer[MAX_PATH] = "";
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hWnd;
ofn.lpstrFilter = "Xiz files (*.xiz)\0*.xiz\0";
ofn.lpstrDefExt = "xiz";
ofn.lpstrFile = buffer;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
if (GetOpenFileName(&ofn))
{
filename = string(ofn.lpstrFile);
return true;
}
return false;
}