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.

177 lines
5.3KB

  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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  17. /*******************************************************************************/
  18. #include "NSM.H"
  19. #include "../Nio/Nio.h"
  20. #ifndef NO_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. extern int Pexitprogram;
  29. #ifndef NO_UI
  30. #include "MasterUI.h"
  31. extern MasterUI *ui;
  32. #endif
  33. extern NSM_Client *nsm;
  34. extern char *instance_name;
  35. NSM_Client::NSM_Client()
  36. {
  37. project_filename = 0;
  38. display_name = 0;
  39. }
  40. int command_open(const char *name,
  41. const char *display_name,
  42. const char *client_id,
  43. char **out_msg);
  44. int command_save(char **out_msg);
  45. int
  46. NSM_Client::command_save(char **out_msg)
  47. {
  48. (void) out_msg;
  49. int r = ERR_OK;
  50. #ifndef NO_UI
  51. ui->do_save_master(project_filename);
  52. #endif
  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. Nio::stop();
  62. if(instance_name)
  63. free(instance_name);
  64. instance_name = strdup(client_id);
  65. Nio::start();
  66. char *new_filename;
  67. asprintf(&new_filename, "%s.xmz", name);
  68. struct stat st;
  69. int r = ERR_OK;
  70. #ifndef NO_UI
  71. if(0 == stat(new_filename, &st)) {
  72. if(ui->do_load_master_unconditional(new_filename, display_name) < 0) {
  73. *out_msg = strdup("Failed to load for unknown reason");
  74. r = ERR_GENERAL;
  75. return r;
  76. }
  77. }
  78. else
  79. ui->do_new_master_unconditional();
  80. #endif
  81. if(project_filename)
  82. free(project_filename);
  83. if(this->display_name)
  84. free(this->display_name);
  85. project_filename = new_filename;
  86. this->display_name = strdup(display_name);
  87. return r;
  88. }
  89. #ifndef NO_UI
  90. static void save_callback(Fl_Widget *, void *v)
  91. {
  92. MasterUI *ui = static_cast<MasterUI*>(v);
  93. ui->do_save_master();
  94. }
  95. #endif
  96. void
  97. NSM_Client::command_active(bool active)
  98. {
  99. #ifndef NO_UI
  100. if(active) {
  101. Fl_Menu_Item *m;
  102. //TODO see if there is a cleaner way of doing this without voiding
  103. //constness
  104. if((m=const_cast<Fl_Menu_Item *>(ui->mastermenu->find_item(
  105. "&File/&Open Parameters..."))))
  106. m->label("&Import Parameters...");
  107. if((m=const_cast<Fl_Menu_Item *>(ui->simplemastermenu->find_item(
  108. "&File/&Open Parameters..."))))
  109. m->label("&Import Parameters...");
  110. //TODO get this menu entry inserted at the right point
  111. if((m=const_cast<Fl_Menu_Item *>(ui->mastermenu->find_item("&File/&Export Parameters..."))))
  112. m->show();
  113. else
  114. ui->mastermenu->add("&File/&Export Parameters...",0,save_callback,ui);
  115. if((m=const_cast<Fl_Menu_Item *>(ui->simplemastermenu->find_item("&File/&Export Parameters..."))))
  116. m->show();
  117. else
  118. ui->simplemastermenu->add("&File/&Export Parameters...",0,save_callback,ui);
  119. ui->sm_indicator1->value(1);
  120. ui->sm_indicator2->value(1);
  121. ui->sm_indicator1->tooltip(session_manager_name());
  122. ui->sm_indicator2->tooltip(session_manager_name());
  123. }
  124. else {
  125. Fl_Menu_Item *m;
  126. if((m=const_cast<Fl_Menu_Item *>(ui->mastermenu->find_item(
  127. "&File/&Import Parameters..."))))
  128. m->label("&Open Parameters...");
  129. if((m=const_cast<Fl_Menu_Item *>(ui->simplemastermenu->find_item(
  130. "&File/&Open Parameters..."))))
  131. m->label("&Open Parameters...");
  132. if((m=const_cast<Fl_Menu_Item *>(ui->mastermenu->find_item("&File/&Export Parameters..."))))
  133. m->hide();
  134. if((m=const_cast<Fl_Menu_Item *>(ui->simplemastermenu->find_item("&File/&Export Parameters..."))))
  135. m->hide();
  136. ui->sm_indicator1->value(0);
  137. ui->sm_indicator2->value(0);
  138. ui->sm_indicator1->tooltip(NULL);
  139. ui->sm_indicator2->tooltip(NULL);
  140. }
  141. #endif
  142. }