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.

1476 lines
37KB

  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. #include <string>
  19. #include <iostream>
  20. #include <fstream>
  21. #include <sstream>
  22. #include <sys/types.h>
  23. #include <sys/stat.h>
  24. #include <dirent.h>
  25. #include <dlfcn.h>
  26. #include <FL/Fl.H>
  27. #include <FL/Enumerations.H>
  28. #include <FL/fl_file_chooser.h>
  29. #include <FL/Fl_Box.h>
  30. #include <FL/Fl_Tooltip.h>
  31. #include "SpiralSynthModular.h"
  32. #include "SpiralSound/PluginManager.h"
  33. #include "SpiralSound/SpiralInfo.h"
  34. #include "SpiralSound/Plugins/SpiralPluginGUI.h"
  35. #include "GUI/SSM.xpm"
  36. #include "GUI/load.xpm"
  37. #include "GUI/save.xpm"
  38. #include "GUI/new.xpm"
  39. #include "GUI/options.xpm"
  40. #include "GUI/comment.xpm"
  41. #include "GUI/Widgets/PawfalYesNo.h"
  42. //#define DEBUG_PLUGINS
  43. //#define DEBUG_STREAM
  44. const static string LABEL = "SpiralSynthModular "+VER_STRING;
  45. static string TITLEBAR;
  46. static const int FILE_VERSION = 4;
  47. static int Numbers[512];
  48. static const int MAIN_WIDTH = 700;
  49. static const int MAIN_HEIGHT = 600;
  50. static const int SLIDER_WIDTH = 15;
  51. static const int ICON_DEPTH = 3;
  52. static const int COMMENT_ID = -1;
  53. using namespace std;
  54. map<int,DeviceWin*> SynthModular::m_DeviceWinMap;
  55. bool SynthModular::m_CallbackUpdateMode = false;
  56. bool SynthModular::m_BlockingOutputPluginIsReady = false;
  57. //////////////////////////////////////////////////////////
  58. DeviceWin::~DeviceWin()
  59. {
  60. }
  61. //////////////////////////////////////////////////////////
  62. SynthModular::SynthModular():
  63. m_NextID(0),
  64. m_PauseAudio(false)
  65. {
  66. m_Info.BUFSIZE = SpiralInfo::BUFSIZE;
  67. m_Info.FRAGSIZE = SpiralInfo::FRAGSIZE;
  68. m_Info.FRAGCOUNT = SpiralInfo::FRAGCOUNT;
  69. m_Info.SAMPLERATE = SpiralInfo::SAMPLERATE;
  70. m_Info.OUTPUTFILE = SpiralInfo::OUTPUTFILE;
  71. m_Info.MIDIFILE = SpiralInfo::MIDIFILE;
  72. m_Info.POLY = SpiralInfo::POLY;
  73. m_Info.GUI_COLOUR = SpiralInfo::GUI_COLOUR;
  74. m_Info.SCOPE_BG_COLOUR = SpiralInfo::SCOPE_BG_COLOUR;
  75. m_Info.SCOPE_FG_COLOUR = SpiralInfo::SCOPE_FG_COLOUR;
  76. m_Info.SCOPE_SEL_COLOUR = SpiralInfo::SCOPE_SEL_COLOUR;
  77. m_Info.SCOPE_IND_COLOUR = SpiralInfo::SCOPE_IND_COLOUR;
  78. m_Info.SCOPE_MRK_COLOUR = SpiralInfo::SCOPE_MRK_COLOUR;
  79. m_Info.GUICOL_Device = SpiralInfo::GUICOL_Device;
  80. m_Info.GUIDEVICE_Box = SpiralInfo::GUIDEVICE_Box;
  81. for (int n=0; n<512; n++) Numbers[n]=n;
  82. m_CH.Register("PauseAudio",&m_PauseAudio);
  83. }
  84. //////////////////////////////////////////////////////////
  85. SynthModular::~SynthModular()
  86. {
  87. ClearUp();
  88. PluginManager::Get()->PackUpAndGoHome();
  89. system("rm -f ___temp.ssmcopytmp");
  90. }
  91. //////////////////////////////////////////////////////////
  92. void SynthModular::ClearUp()
  93. {
  94. PauseAudio();
  95. for(map<int,DeviceWin*>::iterator i=m_DeviceWinMap.begin();
  96. i!=m_DeviceWinMap.end(); i++)
  97. {
  98. //Stop processing of audio if any
  99. if (i->second->m_Device)
  100. {
  101. if (i->second->m_Device->Kill());
  102. }
  103. i->second->m_DeviceGUI->Clear();
  104. if (i->second->m_DeviceGUI->GetPluginWindow())
  105. {
  106. i->second->m_DeviceGUI->GetPluginWindow()->hide();
  107. }
  108. //Delete Device
  109. delete i->second->m_Device;
  110. i->second->m_Device=NULL;
  111. }
  112. m_Canvas->Clear();
  113. m_DeviceWinMap.clear();
  114. m_NextID=0;
  115. ResumeAudio();
  116. }
  117. //////////////////////////////////////////////////////////
  118. void SynthModular::Update()
  119. {
  120. m_CH.UpdateDataNow();
  121. if (m_PauseAudio) return;
  122. // for all the plugins
  123. for(map<int,DeviceWin*>::iterator i=m_DeviceWinMap.begin();
  124. i!=m_DeviceWinMap.end(); i++)
  125. {
  126. if (i->second->m_Device && i->second->m_Device->IsDead())
  127. {
  128. //Delete Device
  129. delete i->second->m_Device;
  130. i->second->m_Device=NULL;
  131. //Erase Device from DeviceWinMap
  132. m_DeviceWinMap.erase(i);
  133. }
  134. else if (i->second->m_Device && !m_ResetingAudioThread) // if it's not a comment and we aren't reseting
  135. {
  136. #ifdef DEBUG_PLUGINS
  137. cerr<<"Updating channelhandler of plugin "<<i->second->m_PluginID<<endl;
  138. #endif
  139. // updates the data from the gui thread, if it's not blocking
  140. i->second->m_Device->UpdateChannelHandler();
  141. #ifdef DEBUG_PLUGINS
  142. cerr<<"Finished updating"<<endl;
  143. #endif
  144. // run any commands we've received from the GUI's
  145. i->second->m_Device->ExecuteCommands();
  146. }
  147. }
  148. // run the plugins (only ones connected to anything)
  149. list<int> ExecutionOrder = m_Canvas->GetGraph()->GetSortedList();
  150. for (list<int>::reverse_iterator i=ExecutionOrder.rbegin();
  151. i!=ExecutionOrder.rend(); i++)
  152. {
  153. // use the graphsort order to remove internal latency
  154. map<int,DeviceWin*>::iterator di=m_DeviceWinMap.find(*i);
  155. if (di!=m_DeviceWinMap.end() && di->second->m_Device && (! di->second->m_Device->IsDead()))
  156. {
  157. #ifdef DEBUG_PLUGINS
  158. cerr<<"Executing plugin "<<di->second->m_PluginID<<endl;
  159. #endif
  160. if (m_ResetingAudioThread)
  161. {
  162. di->second->m_Device->Reset();
  163. }
  164. else
  165. {
  166. di->second->m_Device->Execute();
  167. }
  168. #ifdef DEBUG_PLUGINS
  169. cerr<<"Finished executing"<<endl;
  170. #endif
  171. }
  172. }
  173. //we can safely turn this off here
  174. m_ResetingAudioThread = false;
  175. }
  176. //////////////////////////////////////////////////////////
  177. void SynthModular::UpdatePluginGUIs()
  178. {
  179. // see if any need deleting
  180. for (map<int,DeviceWin*>::iterator i=m_DeviceWinMap.begin();
  181. i!=m_DeviceWinMap.end(); i++)
  182. {
  183. if (i->second->m_DeviceGUI && i->second->m_DeviceGUI->GetPluginWindow())
  184. {
  185. SpiralPluginGUI *GUI=(SpiralPluginGUI *)i->second->m_DeviceGUI->GetPluginWindow();
  186. GUI->Update();
  187. }
  188. if (i->second->m_DeviceGUI && i->second->m_DeviceGUI->Killed())
  189. {
  190. bool erase = true;
  191. //Stop processing of audio if any
  192. if (i->second->m_Device)
  193. {
  194. if (i->second->m_Device->Kill());
  195. erase = false;
  196. }
  197. //Clear GUI Device
  198. i->second->m_DeviceGUI->Clear();
  199. // Hide Device GUI FIRST
  200. if (i->second->m_DeviceGUI->GetPluginWindow())
  201. {
  202. i->second->m_DeviceGUI->GetPluginWindow()->hide();
  203. }
  204. //Remove Device GUI from canvas
  205. m_Canvas->RemoveDevice(i->second->m_DeviceGUI);
  206. //Delete Device GUI - must delete here or sometimes plugin will randomly crash
  207. delete i->second->m_DeviceGUI;
  208. i->second->m_DeviceGUI = NULL;
  209. //Erase from winmap if no audio to do it
  210. if (erase)
  211. m_DeviceWinMap.erase(i);
  212. }
  213. }
  214. m_Canvas->Poll();
  215. }
  216. //////////////////////////////////////////////////////////
  217. SpiralWindowType *SynthModular::CreateWindow()
  218. {
  219. m_TopWindow = new SpiralWindowType(MAIN_WIDTH, MAIN_HEIGHT, LABEL.c_str());
  220. //m_TopWindow->resizable(m_TopWindow);
  221. int but=50;
  222. int ToolbarHeight=but+0;
  223. m_Topbar = new Fl_Pack (0, 0, MAIN_WIDTH, ToolbarHeight, "");
  224. m_Topbar->user_data((void*)(this));
  225. m_Topbar->type(FL_HORIZONTAL);
  226. m_Topbar->color(SpiralInfo::GUICOL_Button);
  227. m_TopWindow->add(m_Topbar);
  228. m_ToolbarPanel = new Fl_Pack (0, 0, but*5, ToolbarHeight, "");
  229. m_ToolbarPanel->user_data((void*)(this));
  230. m_ToolbarPanel->type(FL_VERTICAL);
  231. m_ToolbarPanel->color(SpiralInfo::GUICOL_Button);
  232. m_Topbar->add(m_ToolbarPanel);
  233. m_Toolbar = new Fl_Pack (0, 0, but*5, but, "");
  234. m_Toolbar->user_data((void*)(this));
  235. m_Toolbar->type(FL_HORIZONTAL);
  236. m_Toolbar->color(SpiralInfo::GUICOL_Button);
  237. m_ToolbarPanel->add(m_Toolbar);
  238. m_Load = new Fl_Button(0, 0, but, but, "");
  239. Fl_Pixmap *tPix = new Fl_Pixmap(load_xpm);
  240. m_Load->image(tPix->copy());
  241. delete tPix;
  242. m_Load->type(0);
  243. m_Load->box(FL_PLASTIC_UP_BOX);
  244. m_Load->color(SpiralInfo::GUICOL_Button);
  245. m_Load->selection_color(SpiralInfo::GUICOL_Tool);
  246. m_Load->labelsize (1);
  247. m_Load->tooltip("Load a patch file");
  248. m_Load->callback((Fl_Callback*)cb_Load);
  249. m_Toolbar->add(m_Load);
  250. m_Save = new Fl_Button(0, 0, but, but, "");
  251. tPix = new Fl_Pixmap(save_xpm);
  252. m_Save->image(tPix->copy());
  253. delete tPix;
  254. m_Save->type(0);
  255. m_Save->box(FL_PLASTIC_UP_BOX);
  256. m_Save->color(SpiralInfo::GUICOL_Button);
  257. m_Save->selection_color(SpiralInfo::GUICOL_Tool);
  258. m_Save->labelsize (1);
  259. m_Save->tooltip("Save a patch file");
  260. m_Save->callback((Fl_Callback*)cb_Save);
  261. m_Toolbar->add(m_Save);
  262. m_New = new Fl_Button(0, 0, but, but, "");
  263. tPix = new Fl_Pixmap(new_xpm);
  264. m_New->image(tPix->copy());
  265. delete tPix;
  266. m_New->type(0);
  267. m_New->box(FL_PLASTIC_UP_BOX);
  268. m_New->color(SpiralInfo::GUICOL_Button);
  269. m_New->selection_color(SpiralInfo::GUICOL_Tool);
  270. m_New->labelsize (1);
  271. m_New->tooltip("New patch");
  272. m_New->callback((Fl_Callback*)cb_New);
  273. m_Toolbar->add(m_New);
  274. m_Options = new Fl_Button(0, 0, but, but, "");
  275. tPix = new Fl_Pixmap(options_xpm);
  276. m_Options->image(tPix->copy());
  277. delete tPix;
  278. m_Options->type(0);
  279. m_Options->box(FL_PLASTIC_UP_BOX);
  280. m_Options->color(SpiralInfo::GUICOL_Button);
  281. m_Options->selection_color(SpiralInfo::GUICOL_Tool);
  282. m_Options->labelsize (1);
  283. m_Options->tooltip("Options");
  284. m_Options->callback((Fl_Callback*)cb_Rload);
  285. m_Toolbar->add(m_Options);
  286. m_NewComment = new Fl_Button(0, 0, but, but, "");
  287. tPix = new Fl_Pixmap(comment_xpm);
  288. m_NewComment->image(tPix->copy());
  289. delete tPix;
  290. m_NewComment->type(0);
  291. m_NewComment->box(FL_PLASTIC_UP_BOX);
  292. m_NewComment->color(SpiralInfo::GUICOL_Button);
  293. m_NewComment->selection_color(SpiralInfo::GUICOL_Tool);
  294. m_NewComment->labelsize (1);
  295. m_NewComment->tooltip("New comment");
  296. m_NewComment->callback((Fl_Callback*)cb_NewComment);
  297. m_Toolbar->add(m_NewComment);
  298. m_GroupFiller = new Fl_Group (0, 0, 0, ToolbarHeight, "");
  299. m_GroupFiller->color(SpiralInfo::GUICOL_Button);
  300. m_Topbar->add (m_GroupFiller);
  301. m_GroupTab = new Fl_Tabs (0, 0, MAIN_WIDTH-m_GroupFiller->w()-but*5, ToolbarHeight, "");
  302. m_GroupTab->user_data ((void*)(this));
  303. m_GroupTab->box(FL_PLASTIC_DOWN_BOX);
  304. m_GroupTab->color(SpiralInfo::GUICOL_Button);
  305. m_GroupTab->callback((Fl_Callback*)cb_GroupTab);
  306. m_Topbar->add (m_GroupTab);
  307. m_Topbar->resizable(m_GroupTab);
  308. /////////////////
  309. m_CanvasScroll = new Fl_Scroll(0, ToolbarHeight, MAIN_WIDTH, MAIN_HEIGHT-ToolbarHeight, "");
  310. m_TopWindow->add(m_CanvasScroll);
  311. m_TopWindow->resizable(m_CanvasScroll);
  312. m_Canvas = new Fl_Canvas(-5000, -5000, 10000, 10000, "");
  313. m_Canvas->type(1);
  314. m_Canvas->box(FL_FLAT_BOX);
  315. m_Canvas->labeltype(FL_ENGRAVED_LABEL);
  316. m_Canvas->align(FL_ALIGN_TOP_LEFT|FL_ALIGN_INSIDE);
  317. m_Canvas->color(SpiralInfo::GUICOL_Canvas);
  318. m_Canvas->user_data((void*)(this));
  319. m_Canvas->SetConnectionCallback((Fl_Callback*)cb_Connection);
  320. m_Canvas->SetUnconnectCallback((Fl_Callback*)cb_Unconnect);
  321. m_Canvas->SetAddDeviceCallback((Fl_Callback*)cb_NewDeviceFromMenu);
  322. m_Canvas->SetCutDeviceGroupCallback((Fl_Callback*)cb_CutDeviceGroup);
  323. m_Canvas->SetCopyDeviceGroupCallback((Fl_Callback*)cb_CopyDeviceGroup);
  324. m_Canvas->SetPasteDeviceGroupCallback((Fl_Callback*)cb_PasteDeviceGroup);
  325. m_Canvas->SetMergePatchCallback((Fl_Callback*)cb_MergePatch);
  326. m_CanvasScroll->add(m_Canvas);
  327. m_SettingsWindow = new SettingsWindow;
  328. m_SettingsWindow->RegisterApp(this);
  329. return m_TopWindow;
  330. }
  331. //////////////////////////////////////////////////////////
  332. vector<string> SynthModular::BuildPluginList (const string &Path) {
  333. // Scan plugin path for plugins.
  334. DIR *dp;
  335. struct dirent *ep;
  336. struct stat sb;
  337. void *handle;
  338. string fullpath;
  339. const char *path = Path.c_str();
  340. vector<string> ret;
  341. dp = opendir(path);
  342. if (!dp) {
  343. cerr << "WARNING: Could not open path " << path << endl;
  344. }
  345. else {
  346. while ((ep = readdir(dp))) {
  347. // Need full path
  348. fullpath = path;
  349. fullpath.append(ep->d_name);
  350. // Stat file to get type
  351. if (!stat(fullpath.c_str(), &sb)) {
  352. // We only want regular files
  353. if (S_ISREG(sb.st_mode)) {
  354. // We're not fussed about resolving symbols yet, since we are just
  355. // checking if it's a DLL.
  356. handle = dlopen(fullpath.c_str(), RTLD_LAZY);
  357. if (!handle) {
  358. cerr << "WARNING: File " << path << ep->d_name
  359. << " could not be examined" << endl;
  360. cerr << "dlerror() output:" << endl;
  361. cerr << dlerror() << endl;
  362. }
  363. else {
  364. // It's a DLL. Add name to list
  365. ret.push_back(ep->d_name);
  366. }
  367. }
  368. }
  369. }
  370. }
  371. return ret;
  372. }
  373. void SynthModular::LoadPlugins(string pluginPath)
  374. {
  375. int Width = 35;
  376. int Height = 35;
  377. int SWidth = 256;
  378. int SHeight = 256;
  379. Fl_Pixmap pic(SSM_xpm);
  380. Fl_Double_Window* Splash = new Fl_Double_Window((Fl::w()/2)-(SWidth/2),
  381. (Fl::h()/2)-(SHeight/2),
  382. SWidth,SHeight,"SSM");
  383. Splash->border(0);
  384. Fl_Box* pbut = new Fl_Box(0,8,SWidth,SHeight,"");
  385. pbut->box(FL_NO_BOX);
  386. pic.label(pbut);
  387. Fl_Box *splashtext = new Fl_Box(5,SHeight-20,200,20,"Loading...");
  388. splashtext->labelsize(10);
  389. splashtext->box(FL_NO_BOX);
  390. splashtext->align(FL_ALIGN_INSIDE|FL_ALIGN_LEFT);
  391. Splash->add(pbut);
  392. Splash->add(splashtext);
  393. Splash->show();
  394. int ID=-1;
  395. vector<string> PluginVector;
  396. if (SpiralInfo::USEPLUGINLIST) {
  397. PluginVector=SpiralInfo::PLUGINVEC;
  398. }
  399. else {
  400. if (pluginPath.empty()) {
  401. PluginVector=BuildPluginList (SpiralInfo::PLUGIN_PATH);
  402. }
  403. else {
  404. string::iterator i = pluginPath.end() - 1;
  405. if (*i != '/') pluginPath += '/';
  406. PluginVector=BuildPluginList(pluginPath);
  407. }
  408. }
  409. for (vector<string>::iterator i=PluginVector.begin();
  410. i!=PluginVector.end(); i++)
  411. {
  412. string Fullpath;
  413. if (pluginPath=="")
  414. {
  415. Fullpath=SpiralInfo::PLUGIN_PATH+*i;
  416. }
  417. else
  418. {
  419. Fullpath=pluginPath+*"/"+*i;
  420. }
  421. ID=PluginManager::Get()->LoadPlugin(Fullpath.c_str());
  422. if (ID!=PluginError)
  423. {
  424. #ifdef DEBUG_PLUGINS
  425. cerr << ID << " = Plugin [" << *i << "]" << endl;
  426. #endif
  427. Fl_ToolButton *NewButton = new Fl_ToolButton(0,0,Width,Height,"");
  428. NewButton->user_data((void*)(this));
  429. NewButton->labelsize(1);
  430. Fl_Pixmap *tPix = new Fl_Pixmap(PluginManager::Get()->GetPlugin(ID)->GetIcon());
  431. NewButton->image(tPix->copy(tPix->w(),tPix->h()));
  432. delete tPix;
  433. string GroupName = PluginManager::Get()->GetPlugin(ID)->GetGroupName();
  434. Fl_Pack* the_group=NULL;
  435. // find or create this group, and add an icon
  436. map<string,Fl_Pack*>::iterator gi=m_PluginGroupMap.find(GroupName);
  437. if (gi==m_PluginGroupMap.end())
  438. {
  439. the_group = new Fl_Pack (m_GroupTab->x(), 16, m_GroupTab->w(), m_GroupTab->h()-15, GroupName.c_str());
  440. the_group->type(FL_HORIZONTAL);
  441. the_group->labelsize(8);
  442. the_group->color(SpiralInfo::GUICOL_Button);
  443. the_group->user_data((void*)(this));
  444. //m_GroupTab->add(the_group);
  445. m_GroupTab->value(the_group);
  446. m_PluginGroupMap[GroupName]=the_group;
  447. }
  448. else
  449. {
  450. the_group=gi->second;
  451. }
  452. NewButton->type(0);
  453. NewButton->box(FL_NO_BOX);
  454. NewButton->down_box(FL_NO_BOX);
  455. //NewButton->color(SpiralInfo::GUICOL_Button);
  456. //NewButton->selection_color(SpiralInfo::GUICOL_Button);
  457. the_group->add(NewButton);
  458. string tooltip=*i;
  459. // find the first / if there is one, and get rid of everything before and including it
  460. unsigned int p = tooltip.find ('/');
  461. if (p < tooltip.length()) tooltip.erase (0, p);
  462. // find last . and get rid of everything after and including it
  463. p = tooltip.rfind ('.');
  464. unsigned int l = tooltip.length ();
  465. if (p < l) tooltip.erase (p, l);
  466. m_Canvas->AddPluginName (tooltip, PluginManager::Get()->GetPlugin(ID)->ID);
  467. splashtext->label (tooltip.c_str());
  468. Splash->redraw();
  469. NewButton->tooltip (tooltip.c_str());
  470. NewButton->callback((Fl_Callback*)cb_NewDevice,&Numbers[ID]);
  471. NewButton->show();
  472. m_DeviceVec.push_back(NewButton);
  473. the_group->redraw();
  474. // m_NextPluginButton++;
  475. Fl::check();
  476. }
  477. }
  478. map<string,Fl_Pack*>::iterator PlugGrp;
  479. for (PlugGrp = m_PluginGroupMap.begin(); PlugGrp!= m_PluginGroupMap.end(); ++PlugGrp)
  480. {
  481. m_GroupTab->add(PlugGrp->second);
  482. PlugGrp->second->add(new Fl_Box(0,0,600,100,""));
  483. }
  484. // try to show the SpiralSound group
  485. PlugGrp = m_PluginGroupMap.find("SpiralSound");
  486. // can't find it - show the first plugin group
  487. if (PlugGrp==m_PluginGroupMap.end()) PlugGrp=m_PluginGroupMap.begin();
  488. m_GroupTab->value(PlugGrp->second);
  489. Splash->hide();
  490. delete Splash;
  491. }
  492. //////////////////////////////////////////////////////////
  493. DeviceGUIInfo SynthModular::BuildDeviceGUIInfo(PluginInfo &PInfo)
  494. {
  495. DeviceGUIInfo Info;
  496. int Height=50;
  497. // tweak the size if we have too many ins/outs
  498. if (PInfo.NumInputs>4 || PInfo.NumOutputs>4)
  499. {
  500. if (PInfo.NumInputs<PInfo.NumOutputs)
  501. {
  502. Height=PInfo.NumOutputs*10+5;
  503. }
  504. else
  505. {
  506. Height=PInfo.NumInputs*10+5;
  507. }
  508. }
  509. // Make the guiinfo struct
  510. Info.XPos = 0;
  511. Info.YPos = 0;
  512. Info.Width = 40;
  513. Info.Height = Height;
  514. Info.NumInputs = PInfo.NumInputs;
  515. Info.NumOutputs = PInfo.NumOutputs;
  516. Info.Name = PInfo.Name;
  517. Info.PortTips = PInfo.PortTips;
  518. Info.PortTypes = PInfo.PortTypes;
  519. return Info;
  520. }
  521. //////////////////////////////////////////////////////////
  522. DeviceWin* SynthModular::NewDeviceWin(int n, int x, int y)
  523. {
  524. DeviceWin *nlw = new DeviceWin;
  525. const HostsideInfo* Plugin=PluginManager::Get()->GetPlugin(n);
  526. if (!Plugin) return NULL;
  527. nlw->m_Device=Plugin->CreateInstance();
  528. if (!nlw->m_Device) return NULL;
  529. nlw->m_Device->SetBlockingCallback(cb_Blocking);
  530. nlw->m_Device->SetUpdateCallback(cb_Update);
  531. nlw->m_Device->SetParent((void*)this);
  532. PluginInfo PInfo = nlw->m_Device->Initialise(&m_Info);
  533. SpiralGUIType *temp = nlw->m_Device->CreateGUI();
  534. Fl_Pixmap *Pix = new Fl_Pixmap(Plugin->GetIcon());
  535. nlw->m_PluginID = n;
  536. if (temp) temp->position(x+10,y);
  537. DeviceGUIInfo Info=BuildDeviceGUIInfo(PInfo);
  538. Info.XPos = x; //TOOLBOX_WIDTH+(rand()%400);
  539. Info.YPos = y; //rand()%400;
  540. nlw->m_DeviceGUI = new Fl_DeviceGUI(Info, temp, Pix, nlw->m_Device->IsTerminal());
  541. Fl_Canvas::SetDeviceCallbacks(nlw->m_DeviceGUI, m_Canvas);
  542. m_Canvas->add(nlw->m_DeviceGUI);
  543. m_Canvas->redraw();
  544. return nlw;
  545. }
  546. //////////////////////////////////////////////////////////
  547. void SynthModular::AddDevice(int n, int x=-1, int y=-1)
  548. {
  549. //cerr<<"Adding "<<m_NextID<<endl;
  550. if (x==-1)
  551. {
  552. x = m_CanvasScroll->x()+50;
  553. y = m_CanvasScroll->y()+50;
  554. }
  555. DeviceWin* temp = NewDeviceWin(n,x,y);
  556. if (temp)
  557. {
  558. int ID=m_NextID++;
  559. //cerr<<"adding device "<<ID<<endl;
  560. temp->m_DeviceGUI->SetID(ID);
  561. temp->m_Device->SetUpdateInfoCallback(ID,cb_UpdatePluginInfo);
  562. m_DeviceWinMap[ID]=temp;
  563. }
  564. }
  565. //////////////////////////////////////////////////////////
  566. DeviceWin* SynthModular::NewComment(int n, int x=-1, int y=-1)
  567. {
  568. DeviceWin *nlw = new DeviceWin;
  569. if (x==-1)
  570. {
  571. x = m_CanvasScroll->x()+50;
  572. y = m_CanvasScroll->y()+50;
  573. }
  574. nlw->m_Device=NULL;
  575. nlw->m_PluginID = COMMENT_ID;
  576. DeviceGUIInfo Info;
  577. Info.XPos = x;
  578. Info.YPos = y;
  579. Info.Width = 50;
  580. Info.Height = 20;
  581. Info.NumInputs = 0;
  582. Info.NumOutputs = 0;
  583. Info.Name = "";
  584. nlw->m_DeviceGUI = new Fl_CommentGUI(Info, NULL, NULL);
  585. Fl_Canvas::SetDeviceCallbacks(nlw->m_DeviceGUI, m_Canvas);
  586. m_Canvas->add(nlw->m_DeviceGUI);
  587. m_Canvas->redraw();
  588. return nlw;
  589. }
  590. //////////////////////////////////////////////////////////
  591. void SynthModular::AddComment(int n)
  592. {
  593. //cerr<<"Adding "<<m_NextID<<endl;
  594. DeviceWin* temp = NewComment(n);
  595. if (temp)
  596. {
  597. int ID=m_NextID++;
  598. //cerr<<"adding comment "<<ID<<endl;
  599. temp->m_DeviceGUI->SetID(ID);
  600. m_DeviceWinMap[ID]=temp;
  601. }
  602. }
  603. //////////////////////////////////////////////////////////
  604. void SynthModular::UpdateHostInfo()
  605. {
  606. /* Pause Audio */
  607. PauseAudio();
  608. // update the settings
  609. m_Info.BUFSIZE = SpiralInfo::BUFSIZE;
  610. m_Info.FRAGSIZE = SpiralInfo::FRAGSIZE;
  611. m_Info.FRAGCOUNT = SpiralInfo::FRAGCOUNT;
  612. m_Info.SAMPLERATE = SpiralInfo::SAMPLERATE;
  613. m_Info.OUTPUTFILE = SpiralInfo::OUTPUTFILE;
  614. m_Info.MIDIFILE = SpiralInfo::MIDIFILE;
  615. m_Info.POLY = SpiralInfo::POLY;
  616. /* Reset all plugin ports/buffers befure Resuming */
  617. ResetAudio();
  618. }
  619. //////////////////////////////////////////////////////////
  620. // called when a callback output plugin wants to run the audio thread
  621. void SynthModular::cb_Update(void* o, bool mode)
  622. {
  623. m_CallbackUpdateMode=mode;
  624. ((SynthModular*)o)->Update();
  625. }
  626. // called by a blocking output plugin to notify the engine its ready to
  627. // take control of the update timing (so take the brakes off)
  628. void SynthModular::cb_Blocking(void* o, bool mode)
  629. {
  630. m_BlockingOutputPluginIsReady=mode;
  631. }
  632. //////////////////////////////////////////////////////////
  633. inline void SynthModular::cb_CutDeviceGroup_i()
  634. {
  635. if (! m_Canvas->HaveSelection())
  636. return;
  637. //show some warning here
  638. cb_CopyDeviceGroup_i();
  639. for (unsigned int i=0; i<m_Canvas->Selection().m_DeviceIds.size(); i++)
  640. {
  641. int ID = m_Canvas->Selection().m_DeviceIds[i];
  642. Fl_DeviceGUI::Kill(m_DeviceWinMap[ID]->m_DeviceGUI);
  643. }
  644. Fl_Canvas::ClearSelection(m_Canvas);
  645. }
  646. //////////////////////////////////////////////////////////
  647. inline void SynthModular::cb_MergePatch_i()
  648. {
  649. char *fn=fl_file_chooser("Merge a patch", "*.ssm", NULL);
  650. if (fn && fn!='\0')
  651. {
  652. ifstream in(fn);
  653. if (in)
  654. {
  655. fstream inf;
  656. inf.open(fn,ios::in);
  657. m_MergeFilePath=fn;
  658. StreamPatchIn(inf, false, true);
  659. m_Canvas->StreamSelectionWiresIn(inf, m_Copied.m_DeviceIds, true, false);
  660. inf.close();
  661. }
  662. }
  663. }
  664. //////////////////////////////////////////////////////////
  665. inline void SynthModular::cb_CopyDeviceGroup_i()
  666. {
  667. if (! m_Canvas->HaveSelection())
  668. return;
  669. m_Copied.devices.open("___temp.ssmcopytmp",ios::out);
  670. m_Copied.devicecount = 0;
  671. m_Copied.m_DeviceIds.clear();
  672. if (m_FilePath != "")
  673. {
  674. m_Copied.devices<<true<<" ";
  675. m_Copied.devices<<m_FilePath<<endl;
  676. }
  677. else
  678. m_Copied.devices<<false<<endl;
  679. for (unsigned int i=0; i<m_Canvas->Selection().m_DeviceIds.size(); i++)
  680. {
  681. int ID = m_Canvas->Selection().m_DeviceIds[i];
  682. std::map<int,DeviceWin*>::iterator i = m_DeviceWinMap.find(ID);
  683. m_Copied.m_DeviceIds[ID] = ID;
  684. m_Copied.devicecount += 1;
  685. m_Copied.devices<<"Device ";
  686. m_Copied.devices<<i->first<<" "; // save the id
  687. m_Copied.devices<<"Plugin ";
  688. m_Copied.devices<<i->second->m_PluginID<<endl;
  689. m_Copied.devices<<i->second->m_DeviceGUI->x()<<" ";
  690. m_Copied.devices<<i->second->m_DeviceGUI->y()<<" ";
  691. m_Copied.devices<<i->second->m_DeviceGUI->GetName().size()<<" ";
  692. m_Copied.devices<<i->second->m_DeviceGUI->GetName()<<" ";
  693. if (i->second->m_DeviceGUI->GetPluginWindow())
  694. {
  695. m_Copied.devices<<i->second->m_DeviceGUI->GetPluginWindow()->visible()<<" ";
  696. m_Copied.devices<<i->second->m_DeviceGUI->GetPluginWindow()->x()<<" ";
  697. m_Copied.devices<<i->second->m_DeviceGUI->GetPluginWindow()->y()<<" ";
  698. }
  699. else
  700. {
  701. m_Copied.devices<<0<<" "<<0<<" "<<0;
  702. }
  703. m_Copied.devices<<endl;
  704. if (i->second->m_PluginID==COMMENT_ID)
  705. {
  706. // save the comment gui
  707. ((Fl_CommentGUI*)(i->second->m_DeviceGUI))->StreamOut(m_Copied.devices);
  708. }
  709. else
  710. {
  711. // save the plugin
  712. i->second->m_Device->StreamOut(m_Copied.devices);
  713. }
  714. m_Copied.devices<<endl;
  715. }
  716. m_Canvas->StreamSelectionWiresOut(m_Copied.devices);
  717. m_Copied.devices.close();
  718. Fl_Canvas::EnablePaste(m_Canvas);
  719. };
  720. //////////////////////////////////////////////////////////
  721. inline void SynthModular::cb_PasteDeviceGroup_i()
  722. {
  723. if (m_Copied.devicecount <= 0)
  724. return;
  725. m_Copied.devices.open("___temp.ssmcopytmp",ios::in);
  726. StreamPatchIn(m_Copied.devices, true, false);
  727. m_Canvas->StreamSelectionWiresIn(m_Copied.devices, m_Copied.m_DeviceIds, false, true);
  728. m_Copied.devices.close();
  729. };
  730. //////////////////////////////////////////////////////////
  731. iostream &SynthModular::StreamPatchIn(iostream &s, bool paste, bool merge)
  732. {
  733. //if we are merging as opposed to loading a new patch
  734. //we have no need to pause audio
  735. if (!merge && !paste)
  736. PauseAudio();
  737. //if we are pasting we don't have any of the file version
  738. //or saving information. since its internal we didn't
  739. //need it, but we do have other things we might need to load
  740. bool has_file_path;
  741. string m_FromFilePath;
  742. string dummy,dummy2;
  743. int ver;
  744. if (paste)
  745. {
  746. m_Copied.devices>>has_file_path;
  747. if (has_file_path)
  748. m_Copied.devices>>m_FromFilePath;
  749. }
  750. else
  751. {
  752. s>>dummy>>dummy>>dummy>>ver;
  753. if (ver>FILE_VERSION)
  754. {
  755. SpiralInfo::Alert("Bad file, or more recent version.");
  756. return s;
  757. }
  758. if (ver>2)
  759. {
  760. int MainWinX,MainWinY,MainWinW,MainWinH;
  761. int EditWinX,EditWinY,EditWinW,EditWinH;
  762. s>>MainWinX>>MainWinY>>MainWinW>>MainWinH;
  763. s>>EditWinX>>EditWinY>>EditWinW>>EditWinH;
  764. //o.m_MainWindow->resize(MainWinX,MainWinY,MainWinW,MainWinH);
  765. //o.m_EditorWindow->resize(EditWinX,EditWinY,EditWinW,EditWinH);
  766. }
  767. if (merge)
  768. m_FromFilePath = m_MergeFilePath;
  769. }
  770. //wether pasting or merging we need to clear the current
  771. //selection so we can replace it with the new devices
  772. if (paste || merge)
  773. Fl_Canvas::ClearSelection(m_Canvas);
  774. int Num, ID, PluginID, x,y,ps,px,py;
  775. if (paste)
  776. {
  777. Num = m_Copied.devicecount;
  778. }
  779. else
  780. {
  781. s>>dummy>>Num;
  782. }
  783. for(int n=0; n<Num; n++)
  784. {
  785. #ifdef DEBUG_STREAM
  786. cerr<<"Loading Device "<<n<<endl;
  787. #endif
  788. s>>dummy; // "Device"
  789. s>>ID;
  790. s>>dummy2; // "Plugin"
  791. s>>PluginID;
  792. s>>x>>y;
  793. string Name;
  794. if (paste || ver>3)
  795. {
  796. // load the device name
  797. int size;
  798. char Buf[1024];
  799. s>>size;
  800. s.ignore(1);
  801. if (size > 0) {
  802. s.get(Buf,size+1);
  803. Name=Buf;
  804. } else {
  805. Name = "";
  806. }
  807. }
  808. #ifdef DEBUG_STREAM
  809. cerr<<dummy<<" "<<ID<<" "<<dummy2<<" "<<PluginID<<" "<<x<<" "<<y<<endl;
  810. #endif
  811. if (paste || ver>1) s>>ps>>px>>py;
  812. //if we are merging a patch or pasting we will change duplicate ID's
  813. if (!paste && !merge)
  814. {
  815. // Check we're not duplicating an ID
  816. if (m_DeviceWinMap.find(ID)!=m_DeviceWinMap.end())
  817. {
  818. SpiralInfo::Alert("Duplicate device ID found in file - aborting load");
  819. return s;
  820. }
  821. }
  822. if (PluginID==COMMENT_ID)
  823. {
  824. DeviceWin* temp = NewComment(PluginID, x, y);
  825. if (temp)
  826. {
  827. if (paste || merge)
  828. {
  829. m_Copied.m_DeviceIds[ID] = m_NextID++;
  830. ID = m_Copied.m_DeviceIds[ID];
  831. }
  832. temp->m_DeviceGUI->SetID(ID);
  833. m_DeviceWinMap[ID]=temp;
  834. ((Fl_CommentGUI*)(m_DeviceWinMap[ID]->m_DeviceGUI))->StreamIn(s); // load the plugin
  835. if (paste || merge)
  836. Fl_Canvas::AppendSelection(ID, m_Canvas);
  837. else
  838. if (m_NextID<=ID) m_NextID=ID+1;
  839. }
  840. }
  841. else
  842. {
  843. DeviceWin* temp = NewDeviceWin(PluginID, x, y);
  844. if (temp)
  845. {
  846. int oldID=ID;
  847. if (paste || merge)
  848. {
  849. m_Copied.m_DeviceIds[ID] = m_NextID++;
  850. ID = m_Copied.m_DeviceIds[ID];
  851. }
  852. temp->m_DeviceGUI->SetID(ID);
  853. if (paste || ver>3)
  854. {
  855. // set the titlebars
  856. temp->m_DeviceGUI->SetName(Name);
  857. }
  858. temp->m_Device->SetUpdateInfoCallback(ID,cb_UpdatePluginInfo);
  859. m_DeviceWinMap[ID]=temp;
  860. m_DeviceWinMap[ID]->m_Device->StreamIn(s); // load the plugin
  861. // load external files
  862. if (paste || merge)
  863. m_DeviceWinMap[ID]->m_Device->LoadExternalFiles(m_FromFilePath+"_files/", oldID);
  864. else
  865. m_DeviceWinMap[ID]->m_Device->LoadExternalFiles(m_FilePath+"_files/");
  866. if ((paste || ver>1) && m_DeviceWinMap[ID]->m_DeviceGUI->GetPluginWindow())
  867. {
  868. // set the GUI up with the loaded values
  869. // looks messy, but if we do it here, the plugin and it's gui can remain
  870. // totally seperated.
  871. ((SpiralPluginGUI*)(m_DeviceWinMap[ID]->m_DeviceGUI->GetPluginWindow()))->
  872. UpdateValues(m_DeviceWinMap[ID]->m_Device);
  873. // updates the data in the channel buffers, so the values don't
  874. // get overwritten in the next tick. (should maybe be somewhere else)
  875. m_DeviceWinMap[ID]->m_Device->GetChannelHandler()->FlushChannels();
  876. // position the plugin window in the main window
  877. //m_DeviceWinMap[ID]->m_DeviceGUI->GetPluginWindow()->position(px,py);
  878. if (ps)
  879. {
  880. m_DeviceWinMap[ID]->m_DeviceGUI->Maximise();
  881. // reposition after maximise
  882. m_DeviceWinMap[ID]->m_DeviceGUI->position(x,y);
  883. }
  884. else m_DeviceWinMap[ID]->m_DeviceGUI->Minimise();
  885. if (paste || merge)
  886. Fl_Canvas::AppendSelection(ID, m_Canvas);
  887. }
  888. if (!paste && !merge)
  889. if (m_NextID<=ID) m_NextID=ID+1;
  890. }
  891. else
  892. {
  893. // can't really recover if the plugin ID doesn't match a plugin, as
  894. // we have no idea how much data in the stream belongs to this plugin
  895. SpiralInfo::Alert("Error in stream, can't really recover data from here on.");
  896. return s;
  897. }
  898. }
  899. }
  900. if (!paste && !merge)
  901. {
  902. s>>*m_Canvas;
  903. ResumeAudio();
  904. }
  905. return s;
  906. }
  907. iostream &operator>>(iostream &s, SynthModular &o)
  908. {
  909. return o.StreamPatchIn(s, false, false);
  910. }
  911. //////////////////////////////////////////////////////////
  912. ostream &operator<<(ostream &s, SynthModular &o)
  913. {
  914. o.PauseAudio();
  915. s<<"SpiralSynthModular File Ver "<<FILE_VERSION<<endl;
  916. // make external files dir
  917. bool ExternalDirUsed=false;
  918. string command("mkdir "+o.m_FilePath+"_files");
  919. system(command.c_str());
  920. if (FILE_VERSION>2)
  921. {
  922. s<<o.m_TopWindow->x()<<" "<<o.m_TopWindow->y()<<" ";
  923. s<<o.m_TopWindow->w()<<" "<<o.m_TopWindow->h()<<" ";
  924. s<<0<<" "<<0<<" ";
  925. s<<0<<" "<<0<<endl;
  926. }
  927. // save out the SynthModular
  928. s<<"SectionList"<<endl;
  929. s<<o.m_DeviceWinMap.size()<<endl;
  930. for(map<int,DeviceWin*>::iterator i=o.m_DeviceWinMap.begin();
  931. i!=o.m_DeviceWinMap.end(); i++)
  932. {
  933. if (i->second->m_DeviceGUI && i->second->m_Device)
  934. {
  935. s<<endl;
  936. s<<"Device ";
  937. s<<i->first<<" "; // save the id
  938. s<<"Plugin ";
  939. s<<i->second->m_PluginID<<endl;
  940. s<<i->second->m_DeviceGUI->x()<<" ";
  941. s<<i->second->m_DeviceGUI->y()<<" ";
  942. s<<i->second->m_DeviceGUI->GetName().size()<<" ";
  943. s<<i->second->m_DeviceGUI->GetName()<<" ";
  944. if (i->second->m_DeviceGUI->GetPluginWindow())
  945. {
  946. s<<i->second->m_DeviceGUI->GetPluginWindow()->visible()<<" ";
  947. s<<i->second->m_DeviceGUI->GetPluginWindow()->x()<<" ";
  948. s<<i->second->m_DeviceGUI->GetPluginWindow()->y()<<" ";
  949. }
  950. else
  951. {
  952. s<<0<<" "<<0<<" "<<0;
  953. }
  954. s<<endl;
  955. if (i->second->m_PluginID==COMMENT_ID)
  956. {
  957. // save the comment gui
  958. ((Fl_CommentGUI*)(i->second->m_DeviceGUI))->StreamOut(s);
  959. }
  960. else
  961. {
  962. // save the plugin
  963. i->second->m_Device->StreamOut(s);
  964. }
  965. s<<endl;
  966. // save external files
  967. if (i->second->m_Device && i->second->m_Device->SaveExternalFiles(o.m_FilePath+"_files/"))
  968. {
  969. ExternalDirUsed=true;
  970. }
  971. }
  972. }
  973. s<<endl<<*o.m_Canvas<<endl;
  974. // remove it if it wasn't used
  975. if (!ExternalDirUsed)
  976. {
  977. // i guess rmdir won't work if there is something in the dir
  978. // anyway, but best to be on the safe side. (could do rm -rf) :)
  979. string command("rmdir "+o.m_FilePath+"_files");
  980. system(command.c_str());
  981. }
  982. o.ResumeAudio();
  983. return s;
  984. }
  985. //////////////////////////////////////////////////////////
  986. inline void SynthModular::cb_Close_i(Fl_Window* o, void* v)
  987. {
  988. m_SettingsWindow->hide();
  989. delete m_SettingsWindow;
  990. m_TopWindow->hide();
  991. delete m_TopWindow;
  992. o->hide();
  993. }
  994. void SynthModular::cb_Close(Fl_Window* o, void* v)
  995. {((SynthModular*)(o->user_data()))->cb_Close_i(o,v);}
  996. //////////////////////////////////////////////////////////
  997. inline void SynthModular::cb_Load_i(Fl_Button* o, void* v)
  998. {
  999. if (m_DeviceWinMap.size()>0 && !Pawfal_YesNo("Load - Lose changes to current patch?"))
  1000. {
  1001. return;
  1002. }
  1003. char *fn=fl_file_chooser("Load a patch", "*.ssm", NULL);
  1004. if (fn && fn!='\0')
  1005. {
  1006. ifstream in(fn);
  1007. if (in)
  1008. {
  1009. fstream inf;
  1010. inf.open(fn,ios::in);
  1011. m_FilePath=fn;
  1012. ClearUp();
  1013. inf>>*this;
  1014. inf.close();
  1015. TITLEBAR=LABEL+" "+fn;
  1016. m_TopWindow->label(TITLEBAR.c_str());
  1017. }
  1018. }
  1019. }
  1020. void SynthModular::cb_Load(Fl_Button* o, void* v)
  1021. {((SynthModular*)(o->parent()->user_data()))->cb_Load_i(o,v);}
  1022. //////////////////////////////////////////////////////////
  1023. inline void SynthModular::cb_Save_i(Fl_Button* o, void* v)
  1024. {
  1025. char *fn=fl_file_chooser("Save a patch", "*.ssm", NULL);
  1026. if (fn && fn!='\0')
  1027. {
  1028. ifstream ifl(fn);
  1029. if (ifl)
  1030. {
  1031. if (!Pawfal_YesNo("File [%s] exists, overwrite?",fn))
  1032. {
  1033. return;
  1034. }
  1035. }
  1036. ofstream of(fn);
  1037. if (of)
  1038. {
  1039. m_FilePath=fn;
  1040. of<<*this;
  1041. TITLEBAR=LABEL+" "+fn;
  1042. m_TopWindow->label(TITLEBAR.c_str());
  1043. }
  1044. else
  1045. {
  1046. fl_message(string("Error saving "+string(fn)).c_str());
  1047. }
  1048. }
  1049. }
  1050. void SynthModular::cb_Save(Fl_Button* o, void* v)
  1051. {((SynthModular*)(o->parent()->user_data()))->cb_Save_i(o,v);}
  1052. //////////////////////////////////////////////////////////
  1053. inline void SynthModular::cb_New_i(Fl_Button* o, void* v)
  1054. {
  1055. if (m_DeviceWinMap.size()>0 && !Pawfal_YesNo("New - Lose changes to current patch?"))
  1056. {
  1057. return;
  1058. }
  1059. m_TopWindow->label(TITLEBAR.c_str());
  1060. ClearUp();
  1061. }
  1062. void SynthModular::cb_New(Fl_Button* o, void* v)
  1063. {((SynthModular*)(o->parent()->user_data()))->cb_New_i(o,v);}
  1064. //////////////////////////////////////////////////////////
  1065. inline void SynthModular::cb_NewDevice_i(Fl_Button* o, void* v)
  1066. {
  1067. AddDevice(*((int*)v));
  1068. }
  1069. void SynthModular::cb_NewDevice(Fl_Button* o, void* v)
  1070. {((SynthModular*)(o->parent()->user_data()))->cb_NewDevice_i(o,v);}
  1071. //////////////////////////////////////////////////////////
  1072. inline void SynthModular::cb_NewDeviceFromMenu_i(Fl_Canvas* o, void* v)
  1073. {
  1074. AddDevice(*((int*)v),*((int*)v+1),*((int*)v+2));
  1075. }
  1076. void SynthModular::cb_NewDeviceFromMenu(Fl_Canvas* o, void* v)
  1077. {((SynthModular*)(o->user_data()))->cb_NewDeviceFromMenu_i(o,v);}
  1078. //////////////////////////////////////////////////////////
  1079. inline void SynthModular::cb_NewComment_i(Fl_Button* o, void* v)
  1080. {
  1081. AddComment(-1);
  1082. }
  1083. void SynthModular::cb_NewComment(Fl_Button* o, void* v)
  1084. {((SynthModular*)(o->parent()->user_data()))->cb_NewComment_i(o,v);}
  1085. //////////////////////////////////////////////////////////
  1086. inline void SynthModular::cb_GroupTab_i(Fl_Tabs* o, void* v)
  1087. {
  1088. m_GroupTab->redraw();
  1089. }
  1090. void SynthModular::cb_GroupTab(Fl_Tabs* o, void* v)
  1091. {((SynthModular*)(o->parent()->user_data()))->cb_GroupTab_i(o,v);}
  1092. //////////////////////////////////////////////////////////
  1093. inline void SynthModular::cb_Rload_i(Fl_Button* o, void* v)
  1094. {
  1095. m_SettingsWindow->show();
  1096. /*PluginManager::Get()->UnloadAll();
  1097. m_ToolBox->remove(m_ToolPack);
  1098. delete m_ToolPack;
  1099. m_ToolPack = new Fl_Pack(5,20,TOOLBOX_WIDTH-10, TOOLBOX_HEIGHT-40,"");
  1100. m_ToolPack->type(FL_VERTICAL);
  1101. m_ToolPack->box(FL_NO_BOX);
  1102. m_ToolPack->color(SpiralInfo::GUICOL_Tool);
  1103. m_ToolPack->user_data((void*)(this));
  1104. m_ToolBox->add(m_ToolPack);
  1105. m_ToolBox->redraw();
  1106. LoadPlugins();*/
  1107. }
  1108. void SynthModular::cb_Rload(Fl_Button* o, void* v)
  1109. {((SynthModular*)(o->parent()->user_data()))->cb_Rload_i(o,v);}
  1110. //////////////////////////////////////////////////////////
  1111. inline void SynthModular::cb_Connection_i(Fl_Canvas* o, void* v)
  1112. {
  1113. CanvasWire *Wire;
  1114. Wire=(CanvasWire*)v;
  1115. map<int,DeviceWin*>::iterator si=m_DeviceWinMap.find(Wire->OutputID);
  1116. if (si==m_DeviceWinMap.end())
  1117. {
  1118. char num[32];
  1119. sprintf(num,"%d",Wire->OutputID);
  1120. SpiralInfo::Alert("Warning: Connection problem - can't find source "+string(num));
  1121. return;
  1122. }
  1123. map<int,DeviceWin*>::iterator di=m_DeviceWinMap.find(Wire->InputID);
  1124. if (di==m_DeviceWinMap.end())
  1125. {
  1126. char num[32];
  1127. sprintf(num,"%d",Wire->InputID);
  1128. SpiralInfo::Alert("Warning: Connection problem - can't find destination "+string(num));
  1129. return;
  1130. }
  1131. Sample *sample=NULL;
  1132. if (!si->second->m_Device->GetOutput(Wire->OutputPort,&sample))
  1133. {
  1134. char num[32];
  1135. sprintf(num,"%d,%d",Wire->OutputID,Wire->OutputPort);
  1136. SpiralInfo::Alert("Warning: Connection problem - can't find source output "+string(num));
  1137. return;
  1138. }
  1139. if (!di->second->m_Device->SetInput(Wire->InputPort,(const Sample*)sample))
  1140. {
  1141. char num[32];
  1142. sprintf(num,"%d,%d",Wire->InputID,Wire->InputPort);
  1143. SpiralInfo::Alert("Warning: Connection problem - can't find source input "+string(num));
  1144. return;
  1145. }
  1146. }
  1147. void SynthModular::cb_Connection(Fl_Canvas* o, void* v)
  1148. {((SynthModular*)(o->user_data()))->cb_Connection_i(o,v);}
  1149. //////////////////////////////////////////////////////////
  1150. inline void SynthModular::cb_Unconnect_i(Fl_Canvas* o, void* v)
  1151. {
  1152. CanvasWire *Wire;
  1153. Wire=(CanvasWire*)v;
  1154. //cerr<<Wire->InputID<<" "<<Wire->InputPort<<endl;
  1155. map<int,DeviceWin*>::iterator di=m_DeviceWinMap.find(Wire->InputID);
  1156. if (di==m_DeviceWinMap.end())
  1157. {
  1158. //cerr<<"Can't find destination device "<<Wire->InputID<<endl;
  1159. return;
  1160. }
  1161. SpiralPlugin *Plugin=di->second->m_Device;
  1162. if (Plugin && !Plugin->SetInput(Wire->InputPort,NULL))
  1163. { cerr<<"Can't find destination device's Input"<<endl; return; }
  1164. }
  1165. void SynthModular::cb_Unconnect(Fl_Canvas* o, void* v)
  1166. {((SynthModular*)(o->user_data()))->cb_Unconnect_i(o,v);}
  1167. //////////////////////////////////////////////////////////
  1168. void SynthModular::cb_UpdatePluginInfo(int ID, void *PInfo)
  1169. {
  1170. map<int,DeviceWin*>::iterator i=m_DeviceWinMap.find(ID);
  1171. if (i!=m_DeviceWinMap.end())
  1172. {
  1173. DeviceGUIInfo Info=BuildDeviceGUIInfo(*((PluginInfo*)PInfo));
  1174. (*i).second->m_DeviceGUI->Setup(Info);
  1175. (*i).second->m_DeviceGUI->redraw();
  1176. }
  1177. }
  1178. //////////////////////////////////////////////////////////
  1179. void SynthModular::LoadPatch(const char *fn)
  1180. {
  1181. ifstream in(fn);
  1182. if (in)
  1183. {
  1184. fstream inf;
  1185. inf.open(fn, std::ios::in);
  1186. m_FilePath=fn;
  1187. ClearUp();
  1188. inf>>*this;
  1189. inf.close();
  1190. TITLEBAR=LABEL+" "+fn;
  1191. m_TopWindow->label(TITLEBAR.c_str());
  1192. }
  1193. }
  1194. //////////////////////////////////////////////////////////