Audio plugin host https://kx.studio/carla
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.

172 lines
5.4KB

  1. /*******************************************************************************/
  2. /* Copyright (C) 2012 Jonathan Moore Liles */
  3. /* */
  4. /* This program is free software; you can redistribute it and/or modify it */
  5. /* under the terms of the GNU General Public License as published by the */
  6. /* Free Software Foundation; either version 2 of the License, or (at your */
  7. /* option) any later version. */
  8. /* */
  9. /* This program is distributed in the hope that it will be useful, but WITHOUT */
  10. /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
  11. /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
  12. /* more details. */
  13. /* */
  14. /* You should have received a copy of the GNU General Public License along */
  15. /* with This program; see the file COPYING. If not,write to the Free Software */
  16. /* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
  17. /*******************************************************************************/
  18. #include "NSM.H"
  19. #include "../Nio/Nio.h"
  20. #if defined(FLTK_UI) || defined(NTK_UI)
  21. #include <FL/Fl.H>
  22. #endif
  23. #include <cstdio>
  24. #include <cstring>
  25. #include <sys/stat.h>
  26. #include <sys/types.h>
  27. #include <unistd.h>
  28. #include <stdlib.h>
  29. extern int Pexitprogram;
  30. #if defined(FLTK_UI) || defined(NTK_UI)
  31. #include "MasterUI.h"
  32. extern MasterUI *ui;
  33. #endif
  34. extern NSM_Client *nsm;
  35. extern char *instance_name;
  36. NSM_Client::NSM_Client(zyn::MiddleWare *m)
  37. :project_filename(0),
  38. display_name(0),
  39. middleware(m)
  40. {
  41. }
  42. int command_open(const char *name,
  43. const char *display_name,
  44. const char *client_id,
  45. char **out_msg);
  46. int command_save(char **out_msg);
  47. int
  48. NSM_Client::command_save(char **out_msg)
  49. {
  50. (void) out_msg;
  51. int r = ERR_OK;
  52. middleware->transmitMsg("/save_xmz", "s", project_filename);
  53. return r;
  54. }
  55. int
  56. NSM_Client::command_open(const char *name,
  57. const char *display_name,
  58. const char *client_id,
  59. char **out_msg)
  60. {
  61. zyn::Nio::stop();
  62. if(instance_name)
  63. free(instance_name);
  64. instance_name = strdup(client_id);
  65. zyn::Nio::start();
  66. char *new_filename;
  67. //if you're on windows enjoy the undefined behavior...
  68. #ifndef WIN32
  69. asprintf(&new_filename, "%s.xmz", name);
  70. #endif
  71. struct stat st;
  72. int r = ERR_OK;
  73. if(0 == stat(new_filename, &st))
  74. middleware->transmitMsg("/load_xmz", "s", new_filename);
  75. else
  76. middleware->transmitMsg("/reset_master", "");
  77. if(project_filename)
  78. free(project_filename);
  79. if(this->display_name)
  80. free(this->display_name);
  81. project_filename = new_filename;
  82. this->display_name = strdup(display_name);
  83. return r;
  84. }
  85. #if defined(FLTK_UI) || defined(NTK_UI)
  86. static void save_callback(Fl_Widget *, void *v)
  87. {
  88. MasterUI *ui = static_cast<MasterUI*>(v);
  89. ui->do_save_master();
  90. }
  91. #endif
  92. void
  93. NSM_Client::command_active(bool active)
  94. {
  95. #if defined(FLTK_UI) || defined(NTK_UI)
  96. if(active) {
  97. Fl_Menu_Item *m;
  98. //TODO see if there is a cleaner way of doing this without voiding
  99. //constness
  100. if((m=const_cast<Fl_Menu_Item *>(ui->mastermenu->find_item(
  101. "&File/&Open Parameters..."))))
  102. m->label("&Import Parameters...");
  103. if((m=const_cast<Fl_Menu_Item *>(ui->simplemastermenu->find_item(
  104. "&File/&Open Parameters..."))))
  105. m->label("&Import Parameters...");
  106. //TODO get this menu entry inserted at the right point
  107. if((m=const_cast<Fl_Menu_Item *>(ui->mastermenu->find_item("&File/&Export Parameters..."))))
  108. m->show();
  109. else
  110. ui->mastermenu->add("&File/&Export Parameters...",0,save_callback,ui);
  111. if((m=const_cast<Fl_Menu_Item *>(ui->simplemastermenu->find_item("&File/&Export Parameters..."))))
  112. m->show();
  113. else
  114. ui->simplemastermenu->add("&File/&Export Parameters...",0,save_callback,ui);
  115. ui->sm_indicator1->value(1);
  116. ui->sm_indicator2->value(1);
  117. ui->sm_indicator1->tooltip(session_manager_name());
  118. ui->sm_indicator2->tooltip(session_manager_name());
  119. }
  120. else {
  121. Fl_Menu_Item *m;
  122. if((m=const_cast<Fl_Menu_Item *>(ui->mastermenu->find_item(
  123. "&File/&Import Parameters..."))))
  124. m->label("&Open Parameters...");
  125. if((m=const_cast<Fl_Menu_Item *>(ui->simplemastermenu->find_item(
  126. "&File/&Open Parameters..."))))
  127. m->label("&Open Parameters...");
  128. if((m=const_cast<Fl_Menu_Item *>(ui->mastermenu->find_item("&File/&Export Parameters..."))))
  129. m->hide();
  130. if((m=const_cast<Fl_Menu_Item *>(ui->simplemastermenu->find_item("&File/&Export Parameters..."))))
  131. m->hide();
  132. ui->sm_indicator1->value(0);
  133. ui->sm_indicator2->value(0);
  134. ui->sm_indicator1->tooltip(NULL);
  135. ui->sm_indicator2->tooltip(NULL);
  136. }
  137. #endif
  138. }