1 /* SpiralSound
2 * Copyleft (C) 2000 David Griffiths <dave@pawfal.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19 #include <iostream>
20 #include <fstream>
21 #include <stdlib.h>
22 #include "FL/fl_draw.H"
23 #include "FL/fl_message.H"
24 #include "SpiralInfo.h"
25 #include "../SpiralSynthPluginLocation.h"
26
RandFloat(float s,float e)27 float RandFloat (float s, float e) {
28 return s+((rand()%10000/10000.0)*(e-s));
29 }
30
31
32
33
34 string SpiralInfo::LOCALE = "EN";
35 int SpiralInfo::BUFSIZE = 512;
36 int SpiralInfo::FRAGSIZE = 256;
37 int SpiralInfo::FRAGCOUNT = 8;
38 int SpiralInfo::SAMPLERATE = 44100;
39 long SpiralInfo::MAXSAMPLE = 32767;
40 float SpiralInfo::VALUECONV = 1.0f/MAXSAMPLE;
41 bool SpiralInfo::WANTMIDI = false;
42 int SpiralInfo::FILTERGRAN = 50;
43 string SpiralInfo::OUTPUTFILE = "/dev/dsp";
44 string SpiralInfo::MIDIFILE = "/dev/midi";
45 int SpiralInfo::POLY = 1;
46 bool SpiralInfo::USEPLUGINLIST = false;
47 unsigned SpiralInfo::GUI_COLOUR = 179;
48 unsigned SpiralInfo::SCOPE_BG_COLOUR = fl_rgb_color (20, 60, 20);
49 unsigned SpiralInfo::SCOPE_FG_COLOUR = fl_rgb_color (100, 200, 100);
50 unsigned SpiralInfo::SCOPE_SEL_COLOUR = FL_WHITE;
51 unsigned SpiralInfo::SCOPE_IND_COLOUR = fl_rgb_color (203, 255, 0);
52 unsigned SpiralInfo::SCOPE_MRK_COLOUR = fl_rgb_color (155, 155, 50);
53
54 /*int SpiralInfo::GUICOL_Tool=179;
55 int SpiralInfo::GUICOL_Button=181;
56 int SpiralInfo::GUICOL_Canvas=181;
57 int SpiralInfo::GUICOL_Device=181;
58 int SpiralInfo::GUIDEVICE_Box=30;*/
59
60 int SpiralInfo::GUICOL_Tool=48;
61 int SpiralInfo::GUICOL_Button=42;
62 int SpiralInfo::GUICOL_Canvas=50;
63 int SpiralInfo::GUICOL_Device=52;
64 int SpiralInfo::GUIDEVICE_Box=30;
65
66 vector<string> SpiralInfo::PLUGINVEC;
67
68 string SpiralInfo::PLUGIN_PATH;
69
70 SpiralInfo* SpiralInfo::m_SpiralInfo=NULL;
71
Get()72 SpiralInfo* SpiralInfo::Get() {
73 if (!m_SpiralInfo) {
74 m_SpiralInfo = new SpiralInfo;
75 }
76 return m_SpiralInfo;
77 }
78
SpiralInfo()79 SpiralInfo::SpiralInfo():
80 m_Version(1)
81 {
82 m_ResFileName = getenv("HOME");
83 m_ResFileName += "/.spiralmodular";
84 PLUGIN_PATH = PLUGIN_PATH_LOCATION;
85 }
86
LoadPrefs()87 void SpiralInfo::LoadPrefs() {
88 ifstream i (m_ResFileName.c_str());
89 if (!i) {
90 cerr << "Creating " << m_ResFileName << endl;
91 SavePrefs ();
92 return;
93 }
94 StreamInPrefs (i);
95 }
96
SavePrefs()97 void SpiralInfo::SavePrefs() {
98 ofstream o (m_ResFileName.c_str());
99 StreamOutPrefs (o);
100 }
101
StreamInPrefs(istream & s)102 void SpiralInfo::StreamInPrefs (istream &s) {
103 // These lines are from SpiralInfo
104 char temp[256];
105 s >> temp >> temp >> temp;
106 s >> temp >> temp >> m_Version;
107 s >> temp >> temp >> LOCALE;
108 s >> temp >> temp >> BUFSIZE;
109 s >> temp >> temp >> FRAGSIZE;
110 s >> temp >> temp >> FRAGCOUNT;
111 s >> temp >> temp >> SAMPLERATE;
112 s >> temp >> temp >> WANTMIDI;
113 s >> temp >> temp >> FILTERGRAN;
114 s >> temp >> temp >> OUTPUTFILE;
115 s >> temp >> temp >> MIDIFILE;
116 s >> temp >> temp >> USEPLUGINLIST;
117 s >> temp >> temp >> POLY;
118 if (m_Version>0) {
119 s >> temp >> temp >> GUI_COLOUR;
120 s >> temp >> temp >> SCOPE_BG_COLOUR;
121 s >> temp >> temp >> SCOPE_FG_COLOUR;
122 s >> temp >> temp >> SCOPE_SEL_COLOUR;
123 s >> temp >> temp >> SCOPE_IND_COLOUR;
124 s >> temp >> temp >> SCOPE_MRK_COLOUR;
125 }
126 s >> temp >> temp;
127 s >> temp >> temp >> GUICOL_Tool;
128 s >> temp >> temp >> GUICOL_Button;
129 s >> temp >> temp >> GUICOL_Canvas;
130 s >> temp >> temp >> GUICOL_Device;
131 s >> temp >> temp >> GUIDEVICE_Box;
132 s >> temp >> temp >> PLUGIN_PATH;
133 s >> temp >> temp;
134 string st;
135 PLUGINVEC.clear();
136 if (USEPLUGINLIST) {
137 while (st!="end" && !s.eof()) {
138 s >> st;
139 if (st!="end") PLUGINVEC.push_back (st);
140 }
141 }
142
143 #if __APPLE__
144 // ignore custom paths, plugins are encapsulated in the app anyway
145 // this prevents the program to fail if the user move the application icon
146 PLUGIN_PATH = PLUGIN_PATH_LOCATION;
147 #endif
148 }
149
StreamOutPrefs(ostream & s)150 void SpiralInfo::StreamOutPrefs (ostream &s) {
151 // These lines are from SpiralInfo
152 s << "SpiralSound resource file" << endl << endl;
153 s << "Version = " << m_Version << endl;
154 s << "Locale = " << LOCALE << endl;
155 s << "BufferSize = " << BUFSIZE << endl;
156 s << "FragmentSize = " << FRAGSIZE << endl;
157 s << "FragmentCount = " << FRAGCOUNT << endl;
158 s << "Samplerate = " << SAMPLERATE << endl;
159 s << "WantMidi = " << WANTMIDI << endl;
160 s << "FilterGranularity = " << FILTERGRAN << endl;
161 s << "Output = " << OUTPUTFILE << endl;
162 s << "Midi = " << MIDIFILE << endl;
163 s << "UsePluginList = " << USEPLUGINLIST << endl;
164 s << "Polyphony = " << POLY << endl;
165 s << "GUIColour = " << GUI_COLOUR << endl;
166 s << "ScopeBGColour = " << SCOPE_BG_COLOUR << endl;
167 s << "ScopeFGColour = " << SCOPE_FG_COLOUR << endl;
168 s << "ScopeSelColour = " << SCOPE_SEL_COLOUR << endl;
169 s << "ScopeIndColour = " << SCOPE_IND_COLOUR << endl;
170 s << "ScopeMrkColour = " << SCOPE_MRK_COLOUR << endl;
171 s << endl << "SpiralSynthModular Info:" << endl << endl;
172 s << "ToolBoxColour = " << GUICOL_Tool << endl;
173 s << "ButtonColour = " << GUICOL_Button << endl;
174 s << "CanvasColour = " << GUICOL_Canvas << endl;
175 s << "DeviceColour = " << GUICOL_Device << endl;
176 s << "DeviceBoxType = " << GUIDEVICE_Box << endl << endl;
177 s << "PluginPath = " << PLUGIN_PATH << endl << endl;
178 s << "PluginList = " << endl;
179 for (vector<string>::iterator i=PLUGINVEC.begin(); i!=PLUGINVEC.end(); i++) {
180 s << *i << endl;
181 }
182 s << "end" << endl;
183 }
184
Alert(string Text)185 void SpiralInfo::Alert (string Text) {
186 // fl_message (Text.c_str());
187 cerr << "Spiral alert: " << Text << endl;
188 }
189
Log(string Text)190 void SpiralInfo::Log (string Text) {
191
192 }
193