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.

164 lines
5.2KB

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