#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+#ifdef MIDI
+#include <sys/stat.h>
+#endif
#include "discovered.h"
#include "old_discovery.h"
return TRUE;
}
+#ifdef MIDI
+//
+// This is a file open dialog. If we choose a readable file here, it is just copied
+// to file "midi.inp" in the local directory
+//
+static gboolean midi_cb(GtkWidget *widget, GdkEventButton *event, gpointer data) {
+ GtkWidget *opfile,*message;
+ GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
+ gint res;
+ int fdin, fdout;
+ char c;
+ size_t len,bytes_read,bytes_written;
+
+ opfile = gtk_file_chooser_dialog_new ("Import MIDI description",
+ GTK_WINDOW(top_window),
+ action,
+ "Cancel",
+ GTK_RESPONSE_CANCEL,
+ "Open",
+ GTK_RESPONSE_ACCEPT,
+ NULL);
+
+ res = gtk_dialog_run (GTK_DIALOG (opfile));
+ if (res == GTK_RESPONSE_ACCEPT) {
+ char *filename;
+ struct stat statbuf;
+ GtkFileChooser *chooser = GTK_FILE_CHOOSER (opfile);
+ char *contents;
+ filename = gtk_file_chooser_get_filename (chooser);
+ fdin =open(filename, O_RDONLY);
+ bytes_read = bytes_written = 0;
+ if (fdin >= 0) {
+ fstat(fdin, &statbuf);
+ len=statbuf.st_size;
+ //
+ // Now first read the whole contents of the file, and then write it out.
+ // This is for new-bees trying to import the midi.inp in the working dir
+ //
+ contents=g_new(char, len);
+ bytes_read = bytes_written = 0;
+ if (contents) {
+ bytes_read=read(fdin, contents, len);
+ }
+ close(fdin);
+ }
+ fdout=0;
+ if (contents && bytes_read > 0) {
+ fdout=open("midi.inp", O_WRONLY | O_CREAT, 0644);
+ if (fdout >= 0) {
+ bytes_written=write(fdout, contents, len);
+ close(fdout);
+ g_free(contents);
+ }
+ }
+ if (fdin < 0) {
+ message = gtk_message_dialog_new (GTK_WINDOW(top_window),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ "Cannot read file!\n");
+ gtk_dialog_run (GTK_DIALOG (message));
+ gtk_widget_destroy(message);
+ }
+ if (fdout < 0) {
+ message = gtk_message_dialog_new (GTK_WINDOW(top_window),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ "Cannot write midi.inp file!\n");
+ gtk_dialog_run (GTK_DIALOG (message));
+ gtk_widget_destroy(message);
+ }
+ if (fdin >= 0 && fdout >= 0) {
+ message = gtk_message_dialog_new (GTK_WINDOW(top_window),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ "File Length : %ld\nBytes read : %ld\nBytes written: %ld\n",len,bytes_read,bytes_written);
+ gtk_dialog_run (GTK_DIALOG (message));
+ gtk_widget_destroy(message);
+ }
+ g_free(filename);
+ }
+ gtk_widget_destroy (opfile);
+ return TRUE;
+}
+#endif
+
#ifdef GPIO
static gboolean gpio_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
configure_gpio(discovery_dialog);
g_signal_connect (exit_b, "button-press-event", G_CALLBACK(exit_cb), NULL);
gtk_grid_attach(GTK_GRID(grid),exit_b,2,i,1,1);
+#ifdef MIDI
+ GtkWidget *midi_b=gtk_button_new_with_label("ImportMIDI");
+ g_signal_connect (midi_b, "button-press-event", G_CALLBACK(midi_cb), NULL);
+ gtk_grid_attach(GTK_GRID(grid),midi_b,3,i,1,1);
+#endif
+
i++;
GtkWidget *tcp_b=gtk_button_new_with_label("Use new TCP Addr:");
g_signal_connect (tcp_b, "button-press-event", G_CALLBACK(tcp_cb), NULL);