1 /* SpiralSynth
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
23 #include "SpiralSound/SpiralInfo.h"
24
RandFloat(float s,float e)25 float RandFloat(float s, float e)
26 {
27 return s+((rand()%10000/10000.0)*(e-s));
28 }
29
CopyBuffer(short * from,short * to)30 void CopyBuffer(short *from, short *to)
31 {
32 for (int n=0; n<SpiralInfo::BUFSIZE; n++)
33 {
34 to[n]=from[n];
35 }
36 }
37
38 int SpiralInfo::BUFSIZE = 512;
39 int SpiralInfo::SAMPLERATE = 44100;
40 long SpiralInfo::MAXSAMPLE = 32767;
41 float SpiralInfo::VALUECONV = 1.0f/MAXSAMPLE;
42 bool SpiralInfo::WANTMIDI = true;
43 int SpiralInfo::FILTERGRAN = 50;
44 string SpiralInfo::OUTPUTFILE = "/dev/dsp";
45 string SpiralInfo::MIDIFILE = "/dev/midi";
46 int SpiralInfo::POLY = 2;
47 bool SpiralInfo::REALTIMEOUT = true;
48 string SpiralInfo::KEYMAP("zsxdcvgbhnjmq2w3er5t6y7ui9o0p[");
49 int SpiralInfo::NKEYS = 30;
50
51 int SpiralInfo::GUI_COLOUR = 179;
52 int SpiralInfo::GUIBG_COLOUR = 0;
53
54 SpiralInfo* SpiralInfo::m_SpiralInfo=NULL;
55
Get()56 SpiralInfo* SpiralInfo::Get()
57 {
58 if (!m_SpiralInfo)
59 {
60 m_SpiralInfo = new SpiralInfo;
61 }
62
63 return m_SpiralInfo;
64 }
65
LoadPrefs()66 void SpiralInfo::LoadPrefs()
67 {
68 string rcfn(m_HomeDir+"/.Spiralrc");
69 ifstream i(rcfn.c_str());
70
71 if (!i)
72 {
73 cerr<<".Spiralrc synth config file not found, creating default\n"<<endl;
74 SavePrefs();
75 return;
76 }
77
78 char temp[256];
79
80 i>>temp>>temp>>temp;
81
82 i>>temp>>temp>>BUFSIZE;
83 i>>temp>>temp>>SAMPLERATE;
84 i>>temp>>temp>>WANTMIDI;
85 i>>temp>>temp>>FILTERGRAN;
86 i>>temp>>temp>>OUTPUTFILE;
87 i>>temp>>temp>>MIDIFILE;
88 i>>temp>>temp>>REALTIMEOUT;
89 i>>temp>>temp>>KEYMAP;
90 i>>temp>>temp>>POLY;
91 }
92
SavePrefs()93 void SpiralInfo::SavePrefs()
94 {
95 string rcfn(m_HomeDir+"/.Spiralrc");
96 ofstream o(rcfn.c_str());
97
98 o<<"SpiralSynth resource file"<<endl<<endl;
99 o<<"BufferSize = "<<BUFSIZE<<endl;
100 o<<"Samplerate = "<<SAMPLERATE<<endl;
101 o<<"WantMidi = "<<WANTMIDI<<endl;
102 o<<"FilterGranularity = "<<FILTERGRAN<<endl;
103 o<<"Output = "<<OUTPUTFILE<<endl;
104 o<<"Midi = "<<MIDIFILE<<endl;
105 o<<"WantRealtimeOut = "<<REALTIMEOUT<<endl;
106 o<<"KeyMap = "<<KEYMAP<<endl;
107 o<<"Polyphony = "<<POLY<<endl;
108 }
109