about summary refs log tree commit diff
path: root/main.c
diff options
context:
space:
mode:
authorZach DeCook <zachdecook@librem.one>2023-08-26 09:33:20 -0400
committerZach DeCook <zachdecook@librem.one>2023-08-26 09:33:20 -0400
commitc6346c6ef55614e0a3471634acdf80c09a601071 (patch)
tree67c750f869ac21604b45a9aa2f52ae32e1881b7b /main.c
parent2b1d0578c13ad8bfd80571c10a0b4b35d9891258 (diff)
downloadshemuvi-c6346c6ef55614e0a3471634acdf80c09a601071.tar.gz
File Load: create svg from file with verovio and dump into stdout
Diffstat (limited to 'main.c')
-rw-r--r--main.c34
1 files changed, 23 insertions, 11 deletions
diff --git a/main.c b/main.c
index 0b31738..8a86f6f 100644
--- a/main.c
+++ b/main.c
@@ -1,8 +1,15 @@
 #include <gtk/gtk.h>
+#include <verovio/c_wrapper.h>
+#include <stdio.h>
+
+// Largest file we want to read
+#define BUF_SIZE 200000
 
 /* Called when a file is chosen by the open menu. */
 static void set_file (GFile *file, gpointer data) {
 	char *name;
+	char buf[BUF_SIZE];
+	const char *output;
 
 	if (!file) {
 		return;
@@ -10,7 +17,21 @@ static void set_file (GFile *file, gpointer data) {
 
 	name = g_file_get_path (file);
 	puts(name);
-	/* TODO: load this into verovio */
+	// Porting Note: By Default verovio installs this to "/usr/local/share/verovio"
+	void *pointer = vrvToolkit_constructorResourcePath("/usr/share/verovio");
+	FILE *cfile = fopen(name, "r");
+	size_t read = fread(buf, 1, BUF_SIZE-1, cfile);
+	// If the file is longer than the buffer, truncate it (which may be okay for some formats...)
+	buf[read] = '\0';
+	fclose(cfile);
+	
+	vrvToolkit_loadData(pointer, buf);
+	output = vrvToolkit_renderToSVG(pointer, 1, FALSE);
+	puts(output);
+
+	// TODO: keep this around
+	free(pointer);
+	
 	g_free (name);
 }
 
@@ -33,16 +54,7 @@ file_opened (GObject *source,
   set_file (file, data);
 }
 
-static gboolean
-abort_mission (gpointer data)
-{
-  GCancellable *cancellable = data;
-
-  g_cancellable_cancel (cancellable);
-
-  return G_SOURCE_REMOVE;
-}
-
+/* Called when the "Open" button is clicked */
 static void open_file (GtkButton *picker, GtkLabel *label) {
   GtkWindow *parent = GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (picker)));
 	GtkFileDialog *dialog;