patch-ghostess-xml-patchlist 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. diff -u ghostess-20050916/src/ghostess.c ghostess-20050916-nw/src/ghostess.c
  2. --- ghostess-20050916/src/ghostess.c 2005-09-16 10:03:16.000000000 -0700
  3. +++ ghostess-20050916-nw/src/ghostess.c 2006-03-29 11:46:38.000000000 -0800
  4. @@ -14,6 +14,9 @@
  5. * Chris Cannam, and Richard Bown.
  6. * - midisine.c, copyright (C) 2004 Ian Esten.
  7. *
  8. + * Modifications for outputting XML formatted patch list
  9. + * by JP Mercury
  10. + *
  11. * This is a host for DSSI plugins. It listens for MIDI events on an
  12. * ALSA sequencer or CoreMIDI port, delivers them to DSSI synths and
  13. * outputs the result via JACK.
  14. @@ -848,7 +851,7 @@
  15. }
  16. int
  17. -write_configuration(FILE *fp)
  18. +write_configuration(char *filename)
  19. {
  20. int rc = 0;
  21. int id, instno, i, in, port;
  22. @@ -856,6 +859,21 @@
  23. char *arg1 = NULL,
  24. *arg2 = NULL;
  25. configure_item_t *item;
  26. + FILE *fp, *fp2;
  27. + char fn2[strlen(filename)+strlen(".xml")+1];
  28. + char tmp[255];
  29. + int j, slen;
  30. +
  31. + // Save configuration
  32. + if ((fp = fopen(filename, "w")) == NULL)
  33. + return 0;
  34. +
  35. + // Save XML patch list
  36. + strcpy(fn2,filename);
  37. + strcat(fn2,".xml");
  38. + if ((fp2 = fopen(fn2, "w")) == NULL)
  39. + return 0;
  40. + fprintf(fp2,"<patchlist>\n");
  41. if (fprintf(fp, "#!/bin/sh\n") < 0) goto error;
  42. if (dssi_path) {
  43. @@ -878,6 +896,7 @@
  44. for (instno = 0; instances[instno].id != id; instno++);
  45. instance = &instances[instno];
  46. + // Write config
  47. escape_for_shell(&arg1, instance->friendly_name);
  48. if (fprintf(fp, "-comment %s \\\n", arg1) < 0) goto error;
  49. @@ -910,14 +929,59 @@
  50. escape_for_shell(&arg1, instance->plugin->dll->name);
  51. escape_for_shell(&arg2, instance->plugin->label);
  52. if (fprintf(fp, " %s:%s \\\n", arg1, arg2) < 0) goto error;
  53. +
  54. + // Write patch list
  55. +
  56. +#if 0
  57. + instance->pluginProgramCount = i;
  58. + instance->pluginPrograms = (DSSI_Program_Descriptor *)
  59. + malloc(i * sizeof(DSSI_Program_Descriptor));
  60. + while (i > 0) {
  61. + const DSSI_Program_Descriptor *descriptor;
  62. + --i;
  63. + descriptor = instance->plugin->descriptor->
  64. + get_program(instanceHandles[instance->number], i);
  65. + instance->pluginPrograms[i].Bank = descriptor->Bank;
  66. + instance->pluginPrograms[i].Program = descriptor->Program;
  67. + instance->pluginPrograms[i].Name = strdup(descriptor->Name);
  68. + ghss_debug(GDB_PROGRAM, " %s: program %d is MIDI bank %lu program %lu, named '%s'",
  69. + instance->friendly_name, i,
  70. + instance->pluginPrograms[i].Bank,
  71. + instance->pluginPrograms[i].Program,
  72. + instance->pluginPrograms[i].Name);
  73. + }
  74. +#endif
  75. +
  76. + for (i = 0; i < instance->pluginProgramCount; i++) {
  77. + // Replace < and > characters in name (bad XML)
  78. + strncpy(tmp,instance->pluginPrograms[i].Name,254);
  79. + tmp[254] = '\0';
  80. + slen = strlen(tmp);
  81. + for (j = 0; j < slen; j++)
  82. + if (tmp[j] == '<' ||
  83. + tmp[j] == '>')
  84. + tmp[j] = ' ';
  85. +
  86. + fprintf(fp2,"<patch channel=\"%d\" "
  87. + "name=\"%s\" bank=\"%d\" program=\"%d\"/>\n",
  88. + instance->channel,
  89. + tmp,
  90. + (int) instance->pluginPrograms[i].Bank,
  91. + (int) instance->pluginPrograms[i].Program);
  92. + }
  93. }
  94. if (fprintf(fp, "\n") < 0) goto error;
  95. rc = 1;
  96. + fprintf(fp2,"</patchlist>\n");
  97. +
  98. error:
  99. if (arg1) free(arg1);
  100. if (arg2) free(arg2);
  101. + fclose(fp);
  102. + fclose(fp2);
  103. +
  104. return rc;
  105. }
  106. @@ -1670,7 +1734,10 @@
  107. if (itemplate->program_set) {
  108. instance->currentBank = itemplate->bank;
  109. instance->currentProgram = itemplate->program;
  110. - instance->pendingProgramChange = 0;
  111. + // JPM-Changed pendingProgramChange from 0 to -1
  112. + // was causing program list to not be dumped when
  113. + // -prog specified
  114. + instance->pendingProgramChange = -1;
  115. } else {
  116. instance->currentBank = 0;
  117. instance->currentProgram = 0;
  118. diff -u ghostess-20050916/src/ghostess.h ghostess-20050916-nw/src/ghostess.h
  119. --- ghostess-20050916/src/ghostess.h 2005-09-16 09:12:13.000000000 -0700
  120. +++ ghostess-20050916-nw/src/ghostess.h 2006-03-29 11:05:57.000000000 -0800
  121. @@ -188,7 +188,7 @@
  122. extern int midi_thread_running;
  123. extern pthread_mutex_t midiEventBufferMutex;
  124. -int write_configuration(FILE *fp);
  125. +int write_configuration(char *filename);
  126. void ui_osc_free(d3h_instance_t *instance);
  127. void start_ui(d3h_instance_t *instance);
  128. diff -u ghostess-20050916/src/gui_callbacks.c ghostess-20050916-nw/src/gui_callbacks.c
  129. --- ghostess-20050916/src/gui_callbacks.c 2005-09-16 10:09:22.000000000 -0700
  130. +++ ghostess-20050916-nw/src/gui_callbacks.c 2006-03-29 11:08:32.000000000 -0800
  131. @@ -120,8 +120,6 @@
  132. void
  133. on_save_file_ok( GtkWidget *widget, gpointer data )
  134. {
  135. - FILE *fp;
  136. -
  137. gtk_widget_hide(save_file_selection);
  138. file_selection_last_filename = (gchar *)gtk_file_selection_get_filename(
  139. GTK_FILE_SELECTION(save_file_selection));
  140. @@ -129,14 +127,9 @@
  141. ghss_debug(GDB_GUI, " on_save_file_ok: file '%s' selected",
  142. file_selection_last_filename);
  143. - if ((fp = fopen(file_selection_last_filename, "w")) == NULL) {
  144. - display_notice("Save Configuration failed:", strerror(errno));
  145. - return;
  146. - }
  147. - if (!write_configuration(fp)) {
  148. + if (!write_configuration(file_selection_last_filename)) {
  149. display_notice("Save Configuration failed:", strerror(errno));
  150. }
  151. - fclose(fp);
  152. display_notice("Configuration Saved.", "");
  153. }