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 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
|
/* abGate - LV2 Noise Gate Plugin
*
* Copyright 2011 Antanas Bružas
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* DIRTY DIRTY DIRTY DIRTY DIRTY DIRTY DIRTY DIRTY DIRTY DIRTY DIRTY DIRTY DIRTY */
#include "presets.h"
presets::presets() {
}
presets::~presets() {
}
vector<string> presets::get_names_xml(string dir) {
ifstream presetsfile(dir.c_str());
if (presetsfile.is_open()) {
while (getline(presetsfile, line)) {
found_preset = line.rfind("\">");
if (found_preset != string::npos) {
names_vector.push_back(line.substr(30, line.length() - 32));
}
}
presetsfile.close();
}
else { cerr << "Unable to open file"; }
return names_vector;
}
list<preset> presets::get_xml(string dir) {
line_nr = 0;
preset_nr = 0;
ifstream presetsfile(dir.c_str());
if (presetsfile.is_open()) {
while (getline(presetsfile, line)) {
found_preset = line.rfind("\">");
found_param = line.rfind("\" />");
if (found_preset != string::npos) {
line_nr = 0;
preset_name = line.substr(30, line.length() - 32);
preset_nr++;
}
else if (found_param != string::npos) {
line_value = line.find("value");
pos = (int)line_value;
float_string = new char[line.substr(pos + 7, line.length() - pos - 11).length() + 1];
strcpy(float_string, line.substr(pos + 7, line.length() - pos - 11).c_str());
sscanf(float_string, "%f", ¶m_value[line_nr]);
line_nr++;
if (line_nr == 6) {
tmp_preset = new preset();
tmp_preset->construct(preset_name, param_value);
presets_list.push_back(*tmp_preset);
}
}
}
presetsfile.close();
}
else { cerr << "Unable to open file"; }
return presets_list;
}
preset presets::get_one_xml(string name, string dir) {
ifstream presetsfile(dir.c_str());
tmp_preset = new preset();
if (presetsfile.is_open()) {
while (getline(presetsfile, line)) {
found_preset = line.rfind("\"" + name + "\"");
if (found_preset != string::npos) {
for (int i = 0; i < 6; i++) {
getline(presetsfile, line);
line_value = line.find("value");
pos = (int)line_value;
float_string = new char[line.substr(pos + 7, line.length() - pos - 11).length() + 1];
strcpy(float_string, line.substr(pos + 7, line.length() - pos - 11).c_str());
sscanf(float_string, "%f", ¶m_value[i]);
if (i == 5) {
tmp_preset->construct(name, param_value);
return *tmp_preset;
}
}
}
}
presetsfile.close();
}
else { cerr << "Unable to open file"; }
return *tmp_preset;
}
bool presets::set_xml(preset new_preset, bool clr, string dir) {
ofstream presetsfile;
if (clr == true) { presetsfile.open(dir.c_str()); }
else { presetsfile.open(dir.c_str(), ios::app); }
if (presetsfile.is_open()) {
presetsfile << "<preset plugin=\"abgate\" name=\"" << new_preset.name << "\">\n";
presetsfile << "\t<param name=\"switch\" value=\"" << new_preset.param_value[0] << "\" />\n";
presetsfile << "\t<param name=\"threshold\" value=\"" << new_preset.param_value[1] << "\" />\n";
presetsfile << "\t<param name=\"attack\" value=\"" << new_preset.param_value[2] << "\" />\n";
presetsfile << "\t<param name=\"hold\" value=\"" << new_preset.param_value[3] << "\" />\n";
presetsfile << "\t<param name=\"decay\" value=\"" << new_preset.param_value[4] << "\" />\n";
presetsfile << "\t<param name=\"gaterange\" value=\"" << new_preset.param_value[5] << "\" />\n";
presetsfile << "</preset>\n";
presetsfile.close();
}
else { cerr << "Unable to open file"; return false; }
return true;
}
/* ==================== Examples ==================== */
/*
// isprintina visus names
presets *test = new presets();
vector<string>names_vector = test->get_names_xml();
for (int i = 0; i < names_vector.size(); i++) {
cout << names_vector[i] << endl;
}
*/
// isprintina visa xml
/*
presets *test = new presets();
list<preset>preset_list = test->get_xml();
list<preset>::iterator it;
for (it = preset_list.begin(); it != preset_list.end(); it++) {
cout << it->name << endl;
cout << it->param_value[0] << endl;
cout << it->param_value[1] << endl;
cout << it->param_value[2] << endl;
cout << it->param_value[3] << endl;
cout << it->param_value[4] << endl;
cout << it->param_value[5] << endl;
}
*/
// senas su vektoriais
/*presets *test = new presets();
vector<preset>preset_vector = test->get_xml();
for (int i = 0; i < preset_vector.size(); i++) {
cout << preset_vector[i].name << endl;
cout << preset_vector[i].param_value[0] << endl;
cout << preset_vector[i].param_value[1] << endl;
cout << preset_vector[i].param_value[2] << endl;
cout << preset_vector[i].param_value[3] << endl;
cout << preset_vector[i].param_value[4] << endl;
cout << preset_vector[i].param_value[5] << endl;
}*/
// iterpia nauja preseta, priklausomai nuo true false parametro įterps arba į galą arba viską ištrins ir įterps
/*
presets *testas = new presets();
preset *presetas666 = new preset();
float parametrai[6] = { 1, -5, 250, 200, 600, -30 };
presetas666->construct("zjbisa", parametrai);
testas->set_xml(*presetas666, false);
*/
// išprintina vieną presetą pagal name
/*presets *test = new presets();
preset presetas1 = test->get_one_xml("zjbis ne");
cout << presetas1.name << endl;
cout << presetas1.param_value[0] << endl;
cout << presetas1.param_value[1] << endl;
cout << presetas1.param_value[2] << endl;
cout << presetas1.param_value[3] << endl;
cout << presetas1.param_value[4] << endl;
cout << presetas1.param_value[5] << endl;
*/
/*
// paima visa xml, ištrina vieną presetą pagal name ir updeitina visa xml
presets *test = new presets();
list<preset>preset_list = test->get_xml();
list<preset>::iterator it;
for (it = preset_list.begin(); it != preset_list.end(); it++) {
if (it->name == "Defaulta") { preset_list.erase(it); break; }
}
// opening and after closing the file to clear the content of it
ofstream presetsfile("presets.xml");
presetsfile.close();
preset *presetas = new preset();
for (it = preset_list.begin(); it != preset_list.end(); it++) {
float parametrai[6] = { it->param_value[0], it->param_value[1], it->param_value[2], it->param_value[3], it->param_value[4], it->param_value[5] };
presetas->construct(it->name, parametrai);
test->set_xml(*presetas, false);
}
*/
|