You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

193 lines
6.4KB

  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. #include <iostream>
  19. #include <fstream>
  20. #include <stdlib.h>
  21. #include "FL/fl_draw.h"
  22. #include "FL/fl_message.h"
  23. #include "SpiralInfo.h"
  24. #include "../SpiralSynthPluginLocation.h"
  25. float RandFloat (float s, float e) {
  26. return s+((rand()%10000/10000.0)*(e-s));
  27. }
  28. string SpiralInfo::LOCALE = "EN";
  29. int SpiralInfo::BUFSIZE = 512;
  30. int SpiralInfo::FRAGSIZE = 256;
  31. int SpiralInfo::FRAGCOUNT = 8;
  32. int SpiralInfo::SAMPLERATE = 44100;
  33. long SpiralInfo::MAXSAMPLE = 32767;
  34. float SpiralInfo::VALUECONV = 1.0f/MAXSAMPLE;
  35. bool SpiralInfo::WANTMIDI = false;
  36. int SpiralInfo::FILTERGRAN = 50;
  37. string SpiralInfo::OUTPUTFILE = "/dev/dsp";
  38. string SpiralInfo::MIDIFILE = "/dev/midi";
  39. int SpiralInfo::POLY = 1;
  40. bool SpiralInfo::USEPLUGINLIST = false;
  41. unsigned SpiralInfo::GUI_COLOUR = 179;
  42. unsigned SpiralInfo::SCOPE_BG_COLOUR = fl_rgb_color (20, 60, 20);
  43. unsigned SpiralInfo::SCOPE_FG_COLOUR = fl_rgb_color (100, 200, 100);
  44. unsigned SpiralInfo::SCOPE_SEL_COLOUR = FL_WHITE;
  45. unsigned SpiralInfo::SCOPE_IND_COLOUR = fl_rgb_color (203, 255, 0);
  46. unsigned SpiralInfo::SCOPE_MRK_COLOUR = fl_rgb_color (155, 155, 50);
  47. /*int SpiralInfo::GUICOL_Tool=179;
  48. int SpiralInfo::GUICOL_Button=181;
  49. int SpiralInfo::GUICOL_Canvas=181;
  50. int SpiralInfo::GUICOL_Device=181;
  51. int SpiralInfo::GUIDEVICE_Box=30;*/
  52. int SpiralInfo::GUICOL_Tool=48;
  53. int SpiralInfo::GUICOL_Button=42;
  54. int SpiralInfo::GUICOL_Canvas=50;
  55. int SpiralInfo::GUICOL_Device=52;
  56. int SpiralInfo::GUIDEVICE_Box=30;
  57. vector<string> SpiralInfo::PLUGINVEC;
  58. string SpiralInfo::PLUGIN_PATH;
  59. SpiralInfo* SpiralInfo::m_SpiralInfo=NULL;
  60. SpiralInfo* SpiralInfo::Get() {
  61. if (!m_SpiralInfo) {
  62. m_SpiralInfo = new SpiralInfo;
  63. }
  64. return m_SpiralInfo;
  65. }
  66. SpiralInfo::SpiralInfo():
  67. m_Version(1)
  68. {
  69. m_ResFileName = getenv("HOME");
  70. m_ResFileName += "/.spiralmodular";
  71. PLUGIN_PATH = PLUGIN_PATH_LOCATION;
  72. }
  73. void SpiralInfo::LoadPrefs() {
  74. ifstream i (m_ResFileName.c_str());
  75. if (!i) {
  76. cerr << "Creating " << m_ResFileName << endl;
  77. SavePrefs ();
  78. return;
  79. }
  80. StreamInPrefs (i);
  81. }
  82. void SpiralInfo::SavePrefs() {
  83. ofstream o (m_ResFileName.c_str());
  84. StreamOutPrefs (o);
  85. }
  86. void SpiralInfo::StreamInPrefs (istream &s) {
  87. // These lines are from SpiralInfo
  88. char temp[256];
  89. s >> temp >> temp >> temp;
  90. s >> temp >> temp >> m_Version;
  91. s >> temp >> temp >> LOCALE;
  92. s >> temp >> temp >> BUFSIZE;
  93. s >> temp >> temp >> FRAGSIZE;
  94. s >> temp >> temp >> FRAGCOUNT;
  95. s >> temp >> temp >> SAMPLERATE;
  96. s >> temp >> temp >> WANTMIDI;
  97. s >> temp >> temp >> FILTERGRAN;
  98. s >> temp >> temp >> OUTPUTFILE;
  99. s >> temp >> temp >> MIDIFILE;
  100. s >> temp >> temp >> USEPLUGINLIST;
  101. s >> temp >> temp >> POLY;
  102. if (m_Version>0) {
  103. s >> temp >> temp >> GUI_COLOUR;
  104. s >> temp >> temp >> SCOPE_BG_COLOUR;
  105. s >> temp >> temp >> SCOPE_FG_COLOUR;
  106. s >> temp >> temp >> SCOPE_SEL_COLOUR;
  107. s >> temp >> temp >> SCOPE_IND_COLOUR;
  108. s >> temp >> temp >> SCOPE_MRK_COLOUR;
  109. }
  110. s >> temp >> temp;
  111. s >> temp >> temp >> GUICOL_Tool;
  112. s >> temp >> temp >> GUICOL_Button;
  113. s >> temp >> temp >> GUICOL_Canvas;
  114. s >> temp >> temp >> GUICOL_Device;
  115. s >> temp >> temp >> GUIDEVICE_Box;
  116. s >> temp >> temp >> PLUGIN_PATH;
  117. s >> temp >> temp;
  118. string st;
  119. PLUGINVEC.clear();
  120. if (USEPLUGINLIST) {
  121. while (st!="end" && !s.eof()) {
  122. s >> st;
  123. if (st!="end") PLUGINVEC.push_back (st);
  124. }
  125. }
  126. #if __APPLE__
  127. // ignore custom paths, plugins are encapsulated in the app anyway
  128. // this prevents the program to fail if the user move the application icon
  129. PLUGIN_PATH = PLUGIN_PATH_LOCATION;
  130. #endif
  131. }
  132. void SpiralInfo::StreamOutPrefs (ostream &s) {
  133. // These lines are from SpiralInfo
  134. s << "SpiralSound resource file" << endl << endl;
  135. s << "Version = " << m_Version << endl;
  136. s << "Locale = " << LOCALE << endl;
  137. s << "BufferSize = " << BUFSIZE << endl;
  138. s << "FragmentSize = " << FRAGSIZE << endl;
  139. s << "FragmentCount = " << FRAGCOUNT << endl;
  140. s << "Samplerate = " << SAMPLERATE << endl;
  141. s << "WantMidi = " << WANTMIDI << endl;
  142. s << "FilterGranularity = " << FILTERGRAN << endl;
  143. s << "Output = " << OUTPUTFILE << endl;
  144. s << "Midi = " << MIDIFILE << endl;
  145. s << "UsePluginList = " << USEPLUGINLIST << endl;
  146. s << "Polyphony = " << POLY << endl;
  147. s << "GUIColour = " << GUI_COLOUR << endl;
  148. s << "ScopeBGColour = " << SCOPE_BG_COLOUR << endl;
  149. s << "ScopeFGColour = " << SCOPE_FG_COLOUR << endl;
  150. s << "ScopeSelColour = " << SCOPE_SEL_COLOUR << endl;
  151. s << "ScopeIndColour = " << SCOPE_IND_COLOUR << endl;
  152. s << "ScopeMrkColour = " << SCOPE_MRK_COLOUR << endl;
  153. s << endl << "SpiralSynthModular Info:" << endl << endl;
  154. s << "ToolBoxColour = " << GUICOL_Tool << endl;
  155. s << "ButtonColour = " << GUICOL_Button << endl;
  156. s << "CanvasColour = " << GUICOL_Canvas << endl;
  157. s << "DeviceColour = " << GUICOL_Device << endl;
  158. s << "DeviceBoxType = " << GUIDEVICE_Box << endl << endl;
  159. s << "PluginPath = " << PLUGIN_PATH << endl << endl;
  160. s << "PluginList = " << endl;
  161. for (vector<string>::iterator i=PLUGINVEC.begin(); i!=PLUGINVEC.end(); i++) {
  162. s << *i << endl;
  163. }
  164. s << "end" << endl;
  165. }
  166. void SpiralInfo::Alert (string Text) {
  167. // fl_message (Text.c_str());
  168. cerr << "Spiral alert: " << Text << endl;
  169. }
  170. void SpiralInfo::Log (string Text) {
  171. }