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.

165 lines
3.8KB

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