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.

170 lines
4.0KB

  1. /* SpiralSynthModular
  2. * Copyleft (C) 2002 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. #ifdef HAVE_CONFIG_H
  19. #include <config.h>
  20. #endif
  21. #include <iostream.h>
  22. #include <stdlib.h>
  23. #include <FL/Fl.H>
  24. #include <FL/Fl_Tooltip.h>
  25. #include <unistd.h>
  26. #include "SpiralSynthModular.h"
  27. pthread_t loopthread;
  28. SynthModular *synth;
  29. int pthread_create_realtime (pthread_t *new_thread,
  30. void *(*start)(void *), void *arg,
  31. int priority);
  32. char flashy[] = {'|','/','-','\\'};
  33. void audioloop(void* o)
  34. {
  35. int counter=0,flashy_counter=0;
  36. while(1)
  37. {
  38. synth->Update();
  39. if (counter==10000)
  40. {
  41. cerr<<"\b"<<flashy[flashy_counter%4];
  42. counter=0;
  43. flashy_counter++;
  44. }
  45. counter++;
  46. }
  47. }
  48. int main(int argc, char **argv)
  49. {
  50. srand(time(NULL));
  51. SpiralSynthModularInfo::Get()->LoadPrefs();
  52. bool GUI = true;
  53. bool FIFO = false;
  54. // get args
  55. string cmd_filename="";
  56. bool cmd_specd = false;
  57. // parse the args
  58. if (argc>1)
  59. {
  60. cmd_filename = argv[1];
  61. cmd_specd = true;
  62. for (int a=2; a<argc; a++)
  63. {
  64. if (!strcmp(argv[a],"--NoGUI")) GUI = false;
  65. if (!strcmp(argv[a],"--SHED_FIFO")) FIFO = true;
  66. }
  67. }
  68. Fl::visual(FL_DOUBLE|FL_RGB);
  69. synth=new SynthModular;
  70. // setup the synth
  71. Fl_Window* win = synth->CreateWindow();
  72. synth->LoadPlugins();
  73. win->xclass("");
  74. if (GUI) win->show(argc, argv); // prevents stuff happening before the plugins have loaded
  75. // set some fltk defaults
  76. Fl_Tooltip::size(10);
  77. Fl::visible_focus(false);
  78. // spawn the audio thread
  79. int ret;
  80. if (FIFO) ret=pthread_create_realtime(&loopthread,(void*(*)(void*))audioloop,NULL,50);
  81. else ret=pthread_create(&loopthread,NULL,(void*(*)(void*))audioloop,NULL);
  82. // do we need to load a patch on startup?
  83. if (cmd_specd) synth->LoadPatch(cmd_filename.c_str());
  84. if (!GUI)
  85. {
  86. // if there is no gui needed, there is nothing more to do here
  87. Fl::check();
  88. for (;;) sleep(1);
  89. }
  90. for (;;)
  91. {
  92. if (!Fl::check()) break;
  93. //if (!synth->CallbackMode()) synth->Update();
  94. synth->UpdatePluginGUIs(); // deletes any if necc
  95. //else Fl::wait();
  96. usleep(10000);
  97. }
  98. //pthread_cancel(loopthread);
  99. delete synth;
  100. return 1;
  101. }
  102. // nicked from Paul Barton-Davis' Ardour code :)
  103. int pthread_create_realtime (pthread_t *new_thread,
  104. void *(*start)(void *), void *arg,
  105. int priority)
  106. {
  107. pthread_attr_t *rt_attributes;
  108. struct sched_param *rt_param;
  109. int retval;
  110. rt_attributes = (pthread_attr_t *) malloc (sizeof (pthread_attr_t));
  111. rt_param = (struct sched_param *) malloc (sizeof (struct sched_param));
  112. pthread_attr_init (rt_attributes);
  113. if (seteuid (0)) {
  114. cerr << "Cannot obtain root UID for RT scheduling operations"
  115. << endl;
  116. return -1;
  117. } else {
  118. if (pthread_attr_setschedpolicy (rt_attributes, SCHED_FIFO)) {
  119. cerr << "Cannot set FIFO scheduling attributes for RT thread" << endl;
  120. }
  121. if (pthread_attr_setscope (rt_attributes, PTHREAD_SCOPE_SYSTEM)) {
  122. cerr << "Cannot set scheduling scope for RT thread" << endl;
  123. }
  124. rt_param->sched_priority = priority;
  125. if (pthread_attr_setschedparam (rt_attributes, rt_param)) {
  126. cerr << "Cannot set scheduling priority for RT thread" << endl;
  127. }
  128. }
  129. retval = pthread_create (new_thread, rt_attributes, start, arg);
  130. seteuid (getuid());
  131. return retval;
  132. }