1 #include <math.h>
2 #include "scripting/scheme-callbacks.h"
3 #include "command/commandfuncs.h"
4 #include "command/grace.h"
5 #include "command/lilydirectives.h"
6 #include "command/lyric.h"
7 #include "command/measure.h"
8 #include "command/object.h"
9 #include "command/processstaffname.h"
10 #include "command/select.h"
11 #include "command/score.h"
12 #include "command/scorelayout.h"
13 #include "core/cache.h"
14 #include "core/utils.h"
15 #include "core/view.h"
16 #include "core/graphicseditor.h"
17 #include "core/http.h"
18 #include "core/keymapio.h"
19 #include "audio/pitchentry.h"
20 #include "command/lilydirectives.h"
21 #include "audio/playback.h"
22 #include "audio/audiointerface.h"
23 #include "generated/scheme_cb.h"
24 #include "export/audiofile.h"
25 #include "export/guidedimportmidi.h"
26 #include "export/print.h"
27 #include "export/exportmidi.h"
28 #include "ui/markup.h"
29 #include "printview/svgview.h"
30 #include "printview/printview.h"
31 #include "display/calculatepositions.h"
32 #include "source/source.h"
33 #include "source/sourceaudio.h"
34
35 SCM
scheme_call_callback(SCM optional,callback_function callback)36 scheme_call_callback (SCM optional, callback_function callback) {
37 gboolean query=FALSE;
38 DenemoScriptParam param;
39 GString *gstr=NULL;
40 int length;
41 char *str=NULL;
42
43 if(scm_is_string(optional)){
44 str = scm_to_locale_stringn(optional, (size_t *)&length);
45 gstr = g_string_new_len(str, length);
46 if(!strncmp("query",str,5)) query = TRUE;
47 }
48 param.string = gstr;
49 param.status = FALSE;
50
51 callback (NULL, ¶m);
52 if(param.status && query)
53 return scm_from_locale_string (gstr->str);
54 if(gstr)
55 g_string_free(gstr, TRUE);
56 return SCM_BOOL(param.status);
57 }
58
59 SCM ReturnValue = SCM_BOOL_F;
60 static void
set_return_value(SCM val)61 set_return_value (SCM val)
62 {
63 ReturnValue = val;
64 }
65
66 static gboolean
scm_is_list(SCM scm)67 scm_is_list (SCM scm)
68 {
69 return scm_is_true (scm_list_p (scm));
70 }
71
72 SCM
scheme_popup_menu(SCM list)73 scheme_popup_menu (SCM list)
74 {
75
76 GtkWidget *menu = gtk_menu_new ();
77 set_return_value (SCM_BOOL_F);
78 if (scm_is_list (list))
79 {
80 gint i;
81 gint length = scm_to_int (scm_length (list));
82 for (i = 0; i < length; i++)
83 {
84 SCM el = scm_list_ref (list, scm_from_int (i));
85 if (scm_is_pair (el))
86 {
87 gchar *label = NULL;
88 gchar *tooltip = NULL;
89 SCM sym;
90 //g_debug("Note that %d is value and %d stringp\n", scm_pair_p(el), scm_string_p(el));
91 if (scm_is_string (scm_car (el)))
92 {
93
94 label = scm_to_locale_string (scm_car (el));
95 sym = scm_cdr (el);
96
97
98 }
99 else if (scm_is_pair (scm_car (el)))
100 {
101 label = scm_to_locale_string (scm_caar (el));
102 tooltip = scm_to_locale_string (scm_cdar (el));
103 sym = scm_cdr (el);
104 }
105 if (label)
106 {
107 GtkWidget *item = gtk_menu_item_new_with_label (label);
108 if (tooltip)
109 gtk_widget_set_tooltip_text (item, tooltip);
110 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
111 g_signal_connect_swapped (G_OBJECT (item), "activate", G_CALLBACK (set_return_value), sym);
112 }
113 else
114 {
115 set_return_value (SCM_BOOL_F);
116 break;
117 }
118 }
119 else if (scm_is_string (el))
120 {
121 GtkWidget *item = gtk_menu_item_new_with_label (scm_to_locale_string (el));
122 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
123 g_signal_connect_swapped (G_OBJECT (item), "activate", G_CALLBACK (set_return_value), el);
124 }
125 else
126 {
127 set_return_value (SCM_BOOL_F);
128 break;
129 }
130 }
131 gtk_widget_show_all (menu);
132 g_signal_connect (menu, "selection-done", gtk_main_quit, NULL);
133 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time ());
134 gtk_main ();
135
136 }
137 return ReturnValue;
138 }
toggle_value(gboolean * value)139 static void toggle_value (gboolean *value)
140 {
141 *value = !*value;
142 }
143
check_all(GtkWidget * button)144 void check_all (GtkWidget *button) {
145 GList *children = gtk_container_get_children (gtk_widget_get_parent (button));
146 for (;children; children=children->next)
147 {
148 GtkWidget *child = children->data;
149 if (GTK_IS_CHECK_BUTTON (child))
150 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (child), TRUE);
151 }
152 }
153
uncheck_all(GtkWidget * button)154 void uncheck_all (GtkWidget *button) {
155 GList *children = gtk_container_get_children (gtk_widget_get_parent (button));
156 for (;children; children=children->next)
157 {
158 GtkWidget *child = children->data;
159 if (GTK_IS_CHECK_BUTTON (child))
160 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (child), FALSE);
161 }
162 }
163
164 SCM
scheme_check_boxes(SCM list,SCM title)165 scheme_check_boxes (SCM list, SCM title)
166 {
167 gchar *thetitle = scm_is_string (title)?
168 scm_to_locale_string (title) :
169 _("Set Values");
170 GtkWidget *dialog = gtk_dialog_new_with_buttons (thetitle,
171 GTK_WINDOW(Denemo.window),
172 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
173 GTK_STOCK_OK,
174 GTK_RESPONSE_ACCEPT,
175 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
176 NULL);
177 GtkWidget *content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
178
179 if (scm_is_list (list))
180 {
181 gint i;
182 gint length = scm_to_int (scm_length (list));
183 gboolean *status;
184 status = (gint*)g_malloc0 (length* sizeof (gboolean));
185 GtkWidget *button = gtk_button_new_with_label (_("Check all"));
186 g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK(check_all), NULL);
187 gtk_container_add (GTK_CONTAINER (content_area), button);
188 button = gtk_button_new_with_label (_("Un-check all"));
189 g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK(uncheck_all), NULL);
190 gtk_container_add (GTK_CONTAINER (content_area), button);
191
192
193 scm_reverse (list);
194 for (i = 0; i < length; i++)
195 {
196 SCM el = scm_list_ref (list, scm_from_int (i));
197 if (scm_is_pair (el))
198 {
199 gchar *label = NULL;
200 if (scm_is_string (scm_car (el)) && scm_is_bool (scm_cdr (el)))
201 {
202 label = scm_to_locale_string (scm_car (el));
203 status[i] = scm_is_true (scm_cdr (el));
204 }
205 if (label)
206 {
207 GtkWidget *item = gtk_check_button_new_with_label (label);
208
209 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(item), status [i]);
210 gtk_container_add (GTK_CONTAINER (content_area), item);
211 g_signal_connect_swapped (G_OBJECT (item), "toggled", G_CALLBACK (toggle_value), &status[i]);
212 }
213 else
214 {
215 return SCM_BOOL_F;
216 }
217 }
218 }
219 gtk_widget_show_all (dialog);
220 gint result = gtk_dialog_run (GTK_DIALOG (dialog));
221 switch (result)
222 {
223 case GTK_RESPONSE_ACCEPT:
224 for (i = 0; i < length; i++)
225 {
226 scm_list_set_x (list, scm_from_int (i), scm_cons (scm_car (scm_list_ref (list, scm_from_int (i))), scm_from_bool (status[i])));
227 }
228 g_free (status);
229 break;
230 default:
231 gtk_widget_destroy (dialog);
232 return SCM_BOOL_F;
233 }
234 gtk_widget_destroy (dialog);
235 }
236 return list;
237 }
238
239
240
241 SCM
scheme_create_palette_button(SCM palette,SCM lbl,SCM tltp,SCM scrp)242 scheme_create_palette_button (SCM palette, SCM lbl, SCM tltp, SCM scrp)
243 {
244 SCM ret;
245 gchar *name = scm_to_locale_string (palette);
246 gchar *label = scm_to_locale_string (lbl);
247 gchar *tooltip = scm_to_locale_string (tltp);
248 gchar *script = scm_to_locale_string (scrp);
249
250 DenemoPalette *pal = create_palette (name, FALSE, TRUE);
251
252 ret = palette_add_button (pal, label, tooltip, script)?SCM_BOOL_T:SCM_BOOL_F;
253 gtk_widget_show_all (gtk_widget_get_parent(pal->box));
254 free(name);
255 free(label);
256 free(tooltip);
257 free(script);
258 return ret;
259 }
260 SCM
scheme_set_palette_shape(SCM palette,SCM horizontal,SCM limit)261 scheme_set_palette_shape (SCM palette, SCM horizontal, SCM limit)
262 {
263 gchar *name = scm_to_locale_string (palette);
264 gboolean horiz = scm_is_true (horizontal);
265 gint lim = scm_to_int (limit);
266
267 DenemoPalette *pal = create_palette (name, FALSE, horiz);
268 free(name);
269 if (lim>0) {
270 pal->limit = lim;
271 pal->rows = horiz;
272 repack_palette (pal);
273 return SCM_BOOL_T;
274 }
275 return SCM_BOOL_F;
276 }
277 SCM
scheme_show_palettes(SCM option,SCM show)278 scheme_show_palettes (SCM option, SCM show)
279 {
280 if(scm_is_true (option))
281 {
282 gchar *name;
283 if(scm_is_string (option))
284 {
285 name = scm_to_locale_string (option);
286 DenemoPalette *pal = get_palette (name);
287 if(pal==NULL)
288 {
289 mergePalette ((const gchar *)name);
290 pal = get_palette (name);
291 }
292 if(pal)
293 {
294 if (!scm_is_false (show))
295 {
296 gtk_widget_show (gtk_widget_get_parent(pal->box));
297 gtk_widget_show_all (pal->box);
298 } else
299 {
300 gtk_widget_hide (pal->box);
301 gtk_widget_hide (gtk_widget_get_parent(pal->box));
302 }
303 return SCM_BOOL_T;
304 }
305 else
306 {
307 return SCM_BOOL_F;
308 }
309 } else
310 {
311 name = choose_palette_by_name (FALSE, TRUE);
312 if(name)
313 {
314 DenemoPalette *pal = get_palette (name);
315 if(pal)
316 {
317 gtk_widget_show (gtk_widget_get_parent(pal->box));
318 gtk_widget_show_all (pal->box);
319 return SCM_BOOL_T;
320 }
321 else
322 {
323 return SCM_BOOL_F;
324 }
325 }
326 }
327 } else
328 {
329 if(Denemo.palettes)
330 {
331 GList *g;
332 for (g=Denemo.palettes;g;g=g->next)
333 {
334 DenemoPalette *pal = (DenemoPalette *) g->data;
335 if (!scm_is_false (show))
336 {
337 gtk_widget_show (gtk_widget_get_parent(pal->box));
338 gtk_widget_show_all (pal->box);
339 } else
340 {
341 gtk_widget_hide (pal->box);
342 gtk_widget_hide (gtk_widget_get_parent(pal->box));
343 }
344 }
345 return SCM_BOOL_T;
346 } else
347 return SCM_BOOL_F;
348 }
349 return SCM_BOOL_F;
350 }
351 SCM
scheme_select_palette(SCM aname)352 scheme_select_palette (SCM aname) {
353 gchar *name = NULL;
354 if(scm_is_string (aname))
355 name = scm_to_locale_string (aname);
356 else
357 if(!SCM_UNBNDP (aname))
358 name = choose_palette_by_name (FALSE, FALSE);
359 if(name) {
360 DenemoPalette *pal = get_palette (name);
361 if(pal)
362 Denemo.currentpalette = pal;
363 }
364 if(Denemo.currentpalette)
365 return scm_from_locale_string(Denemo.currentpalette->name);
366 return SCM_BOOL_F;
367 }
368
flash_input_cursor(void)369 static gint flash_input_cursor (void)
370 {
371 if (Denemo.input_filters->len > 0)
372 {
373 if (g_str_has_suffix(Denemo.input_filters->str, "|"))
374 g_string_truncate (Denemo.input_filters, Denemo.input_filters->len-1);
375 else
376 g_string_append_c (Denemo.input_filters, '|');
377 }
378 write_input_status ();
379 return TRUE;
380 }
381
choose_palette(GtkWidget * button)382 static void choose_palette (GtkWidget *button)
383 {
384 GtkWidget *win = gtk_widget_get_toplevel (button);
385 gchar *name = choose_palette_by_name (FALSE, FALSE);
386 if(name) {
387 DenemoPalette *pal = get_palette (name);
388 if(pal)
389 {
390 Denemo.currentpalette = pal;
391 gtk_window_set_title (GTK_WINDOW(win), pal->name);
392 }
393 }
394 }
check_character(GtkWidget * entry,GdkEventKey * event,GtkWidget * dialog)395 static gboolean check_character (GtkWidget *entry, GdkEventKey *event, GtkWidget *dialog)
396 {
397 if(event->keyval == GDK_KEY_Tab) {
398 choose_palette (entry);
399 return TRUE;
400 }
401 if (event->keyval == GDK_KEY_Return) {
402 gtk_dialog_response (GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
403 return TRUE;
404 }
405 return FALSE;
406 }
407 static gchar *
label_entry(gchar * wlabel,gchar * direction)408 label_entry (gchar * wlabel, gchar * direction)
409 {
410
411 GtkWidget *dialog;
412 GtkWidget *entry;
413 GtkWidget *label;
414 gchar *entry_string;
415 GString *string;
416 entry = gtk_entry_new ();
417 dialog = gtk_dialog_new_with_buttons (wlabel, GTK_WINDOW (Denemo.window), (GtkDialogFlags) (GTK_DIALOG_DESTROY_WITH_PARENT), NULL);
418 g_signal_connect(G_OBJECT(entry), "key-press-event", G_CALLBACK(check_character), dialog);
419 label = gtk_label_new (direction);
420 GtkWidget *content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
421 gtk_container_add (GTK_CONTAINER (content_area), label);
422 gtk_container_add (GTK_CONTAINER (content_area), entry);
423
424 label = gtk_label_new (_("Use <Tab> to switch palette\n<Return>to activate"));
425 gtk_container_add (GTK_CONTAINER (content_area), label);
426
427 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
428 gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE);
429 gtk_window_set_transient_for (GTK_WINDOW(dialog), GTK_WINDOW(Denemo.window));
430 gtk_window_set_keep_above (GTK_WINDOW (dialog), TRUE);
431 gtk_widget_show_all (dialog);
432 gtk_widget_grab_focus (entry);
433 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
434 {
435 entry_string = (gchar *) gtk_entry_get_text (GTK_ENTRY (entry));
436 string = g_string_new (entry_string);
437 gtk_widget_destroy (dialog);
438 return g_string_free (string, FALSE);
439 }
440 else
441 {
442 gtk_widget_destroy (dialog);
443 return NULL;
444 }
445 return NULL;
446
447
448 }
449 SCM
scheme_activate_palette_button(void)450 scheme_activate_palette_button (void) {
451 GdkEventKey event;
452 GString *input = g_string_new ("");
453
454 SCM ret = SCM_BOOL_F;
455 gint id = 0;
456
457 if(Denemo.palettes)
458 {
459 DenemoPalette *pal = Denemo.currentpalette;
460 if(pal==NULL)
461 pal = (DenemoPalette *) Denemo.palettes->data;
462 gchar *str = label_entry (pal->name, _("Key in (part of) label"));
463 pal = Denemo.currentpalette;
464 if(str)
465 {
466 g_string_assign (input, str);
467 g_free(str);
468 if(input->len && palette_action_button (pal, input->str))
469 {
470 ret = SCM_BOOL_T;
471 } else
472 {
473 infodialog ( _("No such label"));
474 gtk_widget_show (gtk_widget_get_parent(pal->box));
475 gtk_widget_show_all (pal->box);
476 }
477 }
478 }
479 return ret;
480 }
481
482 SCM
scheme_get_offset(void)483 scheme_get_offset (void)
484 {
485 #ifndef USE_EVINCE
486 g_debug("This feature requires denemo to be built with evince");
487 #else
488 gdouble offsetx, offsety;
489 if (get_offset (&offsetx, &offsety))
490 {
491 offsetx *= 100;
492 offsety *= 100;
493 offsetx = floor (offsetx);
494 offsety = floor (offsety);
495 offsetx /= 100;
496 offsety /= 100;
497
498 return scm_cons (scm_from_double (offsetx), scm_from_double (offsety));
499 }
500 #endif
501 return SCM_BOOL_F;
502 }
503
504 SCM
scheme_get_control_point(SCM pt)505 scheme_get_control_point (SCM pt)
506 {
507 #ifndef USE_EVINCE
508 g_debug("This feature requires denemo to be built with evince");
509 #else
510 if (scm_is_integer (pt))
511 {
512 gint which = scm_to_int (pt);
513 if (which > 0 && which < 5)
514 return SCM_BOOL (get_control_point (which));
515 }
516 #endif
517 return SCM_BOOL_F;
518 }
519
520 static void
prec(gdouble * val)521 prec (gdouble * val)
522 {
523 *val = round ((*val) * 100.0) / 100;
524 }
525
526 SCM
scheme_get_curve(void)527 scheme_get_curve (void)
528 {
529 #ifndef USE_EVINCE
530 g_debug("This feature requires denemo to be built with evince");
531 #else
532 gdouble x1, y1, x2, y2, x3, y3, x4, y4;
533 if (get_curve (&x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4))
534 {
535 prec (&x1);
536 prec (&y1);
537 prec (&x2);
538 prec (&y2);
539 prec (&x3);
540 prec (&y3);
541 prec (&x4);
542 prec (&y4);
543 return scm_list_n (scm_cons (scm_from_double (x1), scm_from_double (y1)), scm_cons (scm_from_double (x2), scm_from_double (y2)), scm_cons (scm_from_double (x3), scm_from_double (y3)), scm_cons (scm_from_double (x4), scm_from_double (y4)), SCM_UNDEFINED);
544 }
545 #endif
546 return SCM_BOOL_F;
547 }
548
549 SCM
scheme_get_positions(SCM is_slur)550 scheme_get_positions (SCM is_slur)
551 {
552 #ifndef USE_EVINCE
553 g_debug("This feature requires denemo to be built with evince");
554 #else
555 gdouble neary, fary;
556 if (get_positions (&neary, &fary, scm_is_true (is_slur) ? Slur: Beam))
557 {
558 return scm_cons (scm_from_double (neary), scm_from_double (fary));
559 }
560 #endif
561 return SCM_BOOL_F;
562 }
563
564 SCM
scheme_get_new_target(void)565 scheme_get_new_target (void)
566 {
567 #ifndef USE_EVINCE
568 g_debug("This feature requires denemo to be built with evince");
569 return SCM_BOOL_F;
570 #else
571 return scm_from_bool (get_new_target ());
572 #endif
573 }
574
575 SCM
scheme_get_new_point(void)576 scheme_get_new_point (void)
577 {
578 #ifndef USE_EVINCE
579 g_debug("This feature requires denemo to be built with evince");
580 return SCM_BOOL_F;
581 #else
582 return scm_from_bool (get_new_point ());
583 #endif
584 }
585
586 SCM
scheme_get_reference_point(void)587 scheme_get_reference_point (void)
588 {
589 #ifndef USE_EVINCE
590 g_debug("This feature requires denemo to be built with evince");
591 return SCM_BOOL_F;
592 #else
593 return scm_from_bool (get_reference_point ());
594 #endif
595 }
596
597 SCM
scheme_get_target_info(void)598 scheme_get_target_info (void)
599 {
600 DenemoMovement *si = Denemo.project->movement;
601 if (Denemo.project->movement->currentobject == NULL)
602 return SCM_BOOL_F;
603 SCM type = SCM_BOOL_F, grob = SCM_BOOL_F, tag = SCM_BOOL_F;
604 switch (si->target.type)
605 {
606 case TARGET_NONE:
607 type = SCM_BOOL_F;
608 break;
609 case TARGET_OBJECT:
610 type = scm_from_locale_string ("Object");
611 break;
612 case TARGET_CHORD:
613 type = scm_from_locale_string ("Chord");
614 break;
615 case TARGET_NOTE:
616 type = scm_from_locale_string ("Note");
617 break;
618 case TARGET_SLUR:
619 type = scm_from_locale_string ("Slur");
620 break;
621 case TARGET_TIE:
622 type = scm_from_locale_string ("Tie");
623 break;
624 case TARGET_CRESC:
625 type = scm_from_locale_string ("Cresc");
626 break;
627 case TARGET_DIM:
628 type = scm_from_locale_string ("Dim");
629 break;
630 default:
631 g_warning ("Unknown target type %d", si->target.type);
632 type = SCM_BOOL_F;
633 break;
634 }
635
636 if (si->target.type == TARGET_NOTE) {
637 DenemoObject *obj = si->currentobject->data;
638 if (obj->type == CHORD)
639 {
640 chord *thechord = ((chord *) ((DenemoObject *) obj->object));
641 if(thechord->figure)
642 grob = scm_from_locale_string ("BassFigure");
643 }
644 }
645
646
647 if (si->target.directivenum || (si->target.type == TARGET_OBJECT))
648 {
649 DenemoDirective *directive = NULL;
650 DenemoObject *obj = si->currentobject->data;
651 if (si->target.type == TARGET_CHORD)
652 {
653 if (obj->type == CHORD)
654 {
655 GList *directives = ((chord *) ((DenemoObject *) obj->object))->directives;
656 if (directives)
657 {
658 directive = (DenemoDirective *) g_list_nth_data (directives, si->target.directivenum - 1);
659 }
660 }
661 }
662 else if (si->target.type == TARGET_NOTE)
663 {
664 if (obj->type == CHORD)
665 {
666 directive = get_note_directive_number (si->target.directivenum);
667 }
668 }
669 else if (si->target.type == TARGET_OBJECT)
670 {
671 if (obj->type == LILYDIRECTIVE)
672 directive = (DenemoDirective *) obj->object;
673 }
674 if (directive)
675 {
676 if (directive->grob)
677 {
678 grob = scm_from_locale_string (directive->grob->str);
679 }
680 else
681 grob = SCM_BOOL_F;
682 }
683 if (directive && directive->tag)
684 {
685 tag = scm_from_locale_string (directive->tag->str);
686 }
687 }
688 return scm_list_n (type, grob, tag, SCM_UNDEFINED);
689 }
690
691 SCM
scheme_http(SCM hname,SCM page,SCM other,SCM poststr)692 scheme_http (SCM hname, SCM page, SCM other, SCM poststr)
693 {
694 char *name = NULL, *thepage = NULL, *oth = NULL, *post = NULL;
695
696 if (scm_is_string (hname))
697 {
698 name = scm_to_locale_string (hname);
699 }
700 if (scm_is_string (page))
701 {
702 thepage = scm_to_locale_string (page);
703 }
704 if (scm_is_string (other))
705 {
706 oth = scm_to_locale_string (other);
707 }
708 if (scm_is_string (poststr))
709 {
710 post = scm_to_locale_string (poststr);
711 }
712
713 if (name && thepage && post && oth)
714 {
715 gchar *ret = (gchar *)post_denemodotorg (name, thepage, oth, post);
716 SCM scm = scm_from_locale_string (ret);
717 g_free (ret);
718 free (name);
719 free (thepage);
720 free (oth);
721 free (post);
722 return scm;
723 }
724 else
725 {
726 free (name);
727 free (thepage);
728 free (oth);
729 free (post);
730 return SCM_BOOL (FALSE);
731 }
732 }
733
734 //FIXME inelegant!
735 static gint
interpret_lilypond_notename(gchar * x,gint * mid_c_offset,gint * enshift)736 interpret_lilypond_notename (gchar * x, gint * mid_c_offset, gint * enshift)
737 {
738 //g_debug("Mid c offset of %d\n", *x-'c');
739 gchar *c;
740 gint octave = -1; /* middle c is c' */
741 gint accs = 0;
742
743 for (c = x + 1; *c; c++)
744 {
745 if (*c == 'i' && *(c + 1) == 's')
746 {
747 accs++;
748 c++;;
749 }
750 else if (*c == 'e' && *(c + 1) == 's')
751 {
752 accs--;
753 c++;
754 }
755 else if (*c == ',')
756 {
757 octave--;
758 }
759 else if (*c == '\'')
760 {
761 octave++;
762 }
763 }
764 if (*x == 'a' || *x == 'b')
765 octave++;
766
767 *mid_c_offset = *x - 'c' + 7 * octave;
768 *enshift = accs;
769 return *mid_c_offset;
770 }
771
772 static gint
lilypond_to_enshift(gchar * enshift_name)773 lilypond_to_enshift (gchar * enshift_name)
774 {
775 gint enshift = 0;
776 gchar *c;
777 for (c = enshift_name; *c; c++)
778 {
779 if (*c == 'i' && *(c + 1) == 's')
780 {
781 enshift++;
782 c++;
783 }
784 else if (*c == 'e' && *(c + 1) == 's')
785 {
786 enshift--;
787 c++;
788 }
789 }
790 return enshift;
791 }
792
793 /*
794 execute init script local dir for menupath or fallback on system dir
795 */
796 SCM
scheme_execute_init(gchar * menupath)797 scheme_execute_init (gchar * menupath)
798 {
799 GList* dirs = NULL;
800 dirs = g_list_append(dirs, g_build_filename (get_user_data_dir (TRUE), COMMANDS_DIR, "menus", menupath, NULL));
801 dirs = g_list_append(dirs, g_build_filename (get_system_data_dir (), COMMANDS_DIR, "menus", menupath, NULL));
802
803 gchar* path = find_path_for_file (INIT_SCM, dirs);
804
805 if(path){
806 g_message ("About to load from %s", path);
807 eval_file_with_catch (path); //ret = scm_c_primitive_load(filename);
808 }
809 return SCM_BOOL (TRUE);
810 }
811
812 void
execute_init_scripts(gchar * menupath)813 execute_init_scripts (gchar * menupath)
814 {
815 (void) scheme_execute_init (menupath);
816 }
817
818 /* called by a script if it requires initialization
819 the initialization script is expected to be in init.scm in the menupath of the action that invoked the script*/
820 SCM
scheme_initialize_script(SCM action_name)821 scheme_initialize_script (SCM action_name)
822 {
823 SCM ret = SCM_BOOL_T;
824 char *name = scm_to_locale_string (action_name);
825
826 gint idx = lookup_command_from_name (Denemo.map, name);
827 command_row* row = NULL;
828 keymap_get_command_row(Denemo.map, &row, idx);
829
830 ret = scheme_execute_init (row->menupath);
831 if (name)
832 free (name);
833 return ret;
834 }
835
836 /* pass in a path (from below menus) to a command script. Loads the command from .denemo or system
837 * if it can be found
838 * It is used at startup in .denemo files like ReadingNoteNames.denemo
839 * which executes
840 (d-LoadCommand "MainMenu/Educational/ReadingNoteNames")
841 * to ensure that the command it needs is in the command set.
842 */
843 SCM
scheme_load_command(SCM command)844 scheme_load_command (SCM command)
845 {
846 gboolean ret;
847 char *name;
848 name = scm_to_locale_string (command);
849 GList* files = NULL;
850 files = g_list_append(files, g_build_filename (get_user_data_dir (TRUE), COMMANDS_DIR, "menus", name, NULL));
851 files = g_list_append(files, g_build_filename (get_user_data_dir (TRUE), "download", COMMANDS_DIR, name, NULL));
852 files = g_list_append(files, g_build_filename (get_system_data_dir (), COMMANDS_DIR, name, NULL));
853 ret = load_keymap_files(files);
854
855 if (name)
856 free (name);
857 return SCM_BOOL (ret);
858 }
859
860 SCM
scheme_activate_menu_item(SCM menupath)861 scheme_activate_menu_item (SCM menupath)
862 {
863 if (scm_is_string (menupath))
864 {
865 char *item;
866 item = scm_to_locale_string (menupath);
867 if (item)
868 {
869 gboolean ret = activate_action (item) ? TRUE : FALSE;
870 free (item);
871 return SCM_BOOL (ret);
872 }
873 }
874 return SCM_BOOL_F;
875 }
876
877
878 SCM
scheme_hide_buttons(SCM hide)879 scheme_hide_buttons (SCM hide)
880 {
881 SCM ret = SCM_BOOL_F;
882 GtkWidget *widget = Denemo.project->buttonbox;
883 if (GTK_IS_CONTAINER (widget))
884 {
885 ret = SCM_BOOL_T;
886 if (scm_is_false (hide))
887 gtk_container_foreach (GTK_CONTAINER (widget), (GtkCallback) gtk_widget_show, NULL);
888 else
889 gtk_container_foreach (GTK_CONTAINER (widget), (GtkCallback) gtk_widget_hide, NULL);
890 }
891 return ret;
892 }
893
894 SCM
scheme_destroy_buttons(void)895 scheme_destroy_buttons (void)
896 {
897 SCM ret = SCM_BOOL_F;
898 GtkWidget *widget = Denemo.project->buttonbox;
899
900 if (GTK_IS_CONTAINER (widget))
901 {
902 gtk_container_foreach (GTK_CONTAINER (widget), (GtkCallback) gtk_widget_destroy, NULL);
903 ret = SCM_BOOL_T;
904 }
905 return ret;
906 }
907
908
909 /* hide all menus, leaving only the score titles, used for educational games */
910 SCM
scheme_hide_menus(SCM hide)911 scheme_hide_menus (SCM hide)
912 {
913 if (Denemo.project->view != DENEMO_MENU_VIEW)
914 {
915 activate_action ("/MainMenu/ViewMenu/" ToggleScoreTitles_STRING);
916 ToggleReduceToDrawingArea (NULL, NULL);
917 return SCM_BOOL (TRUE);
918 }
919 gboolean show = FALSE;
920 if (scm_is_false (hide))
921 show = TRUE;
922 if(!Denemo.non_interactive){
923 toggle_to_drawing_area (show);
924 activate_action ("/MainMenu/ViewMenu/" ToggleScoreTitles_STRING);
925 }
926 return SCM_BOOL (TRUE);
927 }
928
929 SCM
scheme_hide_window(SCM hide)930 scheme_hide_window (SCM hide)
931 {
932 gboolean show = FALSE;
933 gboolean showing = gtk_widget_get_visible (Denemo.window);
934 if (scm_is_false (hide))
935 show = TRUE;
936 if (show)
937 gtk_widget_show (Denemo.window);
938 else
939 gtk_widget_hide (Denemo.window);
940 return SCM_BOOL (showing == show);
941 }
942
943
944 /* when a script calls a command which is itself a script it comes through here */
945 SCM
scheme_script_callback(SCM script,SCM params)946 scheme_script_callback (SCM script, SCM params)
947 {
948 char *name = NULL;
949 SCM ret = SCM_BOOL_F;
950 if (scm_is_string (script))
951 {
952 name = scm_to_locale_string (script);
953 gint idx = lookup_command_from_name(Denemo.map, name);
954 if (name)
955 {
956 if (!is_action_name_builtin(name))
957 {
958 gchar *paramvar = g_strdup_printf ("%s::params", name);
959 scm_c_define (paramvar, params);
960
961 gchar *text = get_scheme_from_idx (idx);
962 if (text)
963 {
964 //undo is a queue so this is the end :)
965 stage_undo (Denemo.project->movement, ACTION_STAGE_END);
966 ret = SCM_BOOL (!call_out_to_guile (text));
967 stage_undo (Denemo.project->movement, ACTION_STAGE_START);
968 }
969 else if(!Denemo.non_interactive){
970 GtkAction *action = lookup_action_from_name (name);
971 ret = SCM_BOOL (activate_script (action, NULL));
972 }
973 else
974 g_warning("Could not execute %s script", name);
975 scm_c_define (paramvar, SCM_BOOL_F);
976 g_free (paramvar);
977 }
978 if (name)
979 free (name);
980 }
981 }
982 return ret;
983 }
984
985 void
create_scheme_function_for_script(gchar * name)986 create_scheme_function_for_script (gchar * name)
987 {
988 gchar *proc = g_strdup_printf ("(d-%s #:optional params)", name);
989 gchar *value = g_strdup_printf ("(d-ScriptCallback \"%s\" params)", name);
990 gchar *def = g_strdup_printf ("(define %s::params #f) (define* %s %s)", name, proc, value);
991
992 //g_debug("Defining %s\n", def);
993 call_out_to_guile (def);
994 g_free (proc);
995 g_free (value);
996 g_free (def);
997
998 // define_scheme_literal_variable(proc, value, "A scheme procedure to call the script of that name");
999 }
1000
1001
1002 SCM
scheme_debug_object(SCM optional)1003 scheme_debug_object (SCM optional)
1004 {
1005 DenemoObject *curObj;
1006
1007 if (!Denemo.project || !(Denemo.project->movement) || !(Denemo.project->movement->currentobject) || !(curObj = Denemo.project->movement->currentobject->data))
1008 return SCM_BOOL (FALSE);
1009 g_debug ("*************\nType = %d\nbasic_durinticks = %d\ndurinticks - %d\nstarttickofnextnote = %d\n***********\n", curObj->type, curObj->basic_durinticks, curObj->durinticks, curObj->starttickofnextnote);
1010 return SCM_BOOL (TRUE);
1011 }
1012 SCM
scheme_display_object(void)1013 scheme_display_object (void)
1014 {
1015 DenemoObject *curObj;
1016
1017 if (!Denemo.project || !(Denemo.project->movement) || !(Denemo.project->movement->currentobject) || !(curObj = Denemo.project->movement->currentobject->data))
1018 return SCM_BOOL (FALSE);
1019 display_current_object ();
1020 return SCM_BOOL (TRUE);
1021 }
1022 SCM
scheme_get_editing_time(void)1023 scheme_get_editing_time (void)
1024 {
1025 SCM ret;
1026 gchar *edit_time = time_spent_editing();
1027 ret = scm_from_locale_string (edit_time);
1028 g_free (edit_time);
1029 return ret;
1030 }
1031
1032 SCM
scheme_destroy_scheme_init(void)1033 scheme_destroy_scheme_init (void)
1034 {
1035 if(confirm(_("Destroying Customized Buttons"), _("Remove buttons and other customized scheme on startup?")))
1036 {
1037 destroy_local_scheme_init();
1038 return SCM_BOOL_T;
1039 }
1040 return SCM_BOOL_F;
1041 }
1042 SCM
scheme_load_keybindings(SCM name)1043 scheme_load_keybindings (SCM name)
1044 {
1045 char *filename;
1046 if (scm_is_string (name))
1047 {
1048 filename = scm_to_locale_string (name);
1049 GList* files = NULL;
1050
1051 files = g_list_append(files, g_strdup(filename));
1052 files = g_list_append(files, g_build_filename (get_user_data_dir (TRUE), COMMANDS_DIR, filename, NULL));
1053 files = g_list_append(files, g_build_filename (get_user_data_dir (TRUE), "download", COMMANDS_DIR, filename, NULL));
1054 files = g_list_append(files, g_build_filename (get_system_data_dir (), COMMANDS_DIR, filename, NULL));
1055 g_free (name);
1056
1057 return SCM_BOOL(load_keymap_files(files));
1058 }
1059 //if (name) g_free(name); CHECKME
1060 return SCM_BOOL_F;
1061 }
1062
1063 SCM
scheme_save_keybindings(SCM name)1064 scheme_save_keybindings (SCM name)
1065 {
1066 char *filename;
1067 if (scm_is_string (name))
1068 {
1069 filename = scm_to_locale_string (name);
1070 if (save_xml_keybindings (filename) == 0)
1071 {
1072 if (filename)
1073 free (filename);
1074 return SCM_BOOL_T;
1075 }
1076 }
1077 return SCM_BOOL_F;
1078 }
1079
1080 SCM
scheme_clear_keybindings(SCM optional)1081 scheme_clear_keybindings (SCM optional)
1082 {
1083 keymap_clear_bindings (Denemo.map);
1084 return SCM_BOOL_T;
1085 }
1086
1087
1088 SCM
scheme_load_commandset(SCM name)1089 scheme_load_commandset (SCM name)
1090 {
1091 char *filename;
1092 if (scm_is_string (name))
1093 {
1094 filename = scm_to_locale_string (name);
1095 if (load_xml_keymap (filename) == 0)
1096 {
1097 if (filename)
1098 free (filename);
1099 return SCM_BOOL_T;
1100 }
1101 }
1102 return SCM_BOOL_F;
1103 }
1104
1105 #ifdef _WITH_X11_
1106 #if 1 //GTK3 Test
1107 SCM
scheme_user_screenshot(SCM type,SCM position)1108 scheme_user_screenshot (SCM type, SCM position)
1109 {
1110 GList **sources;
1111 SCM ret = SCM_BOOL_F;
1112 gint pos = -1;
1113 if ((!SCM_UNBNDP (position)) && scm_is_integer (position))
1114 pos = scm_to_int (position);
1115
1116 if (scm_is_false (type))
1117 sources = &Denemo.project->movement->sources;
1118 else
1119 sources = &((DenemoStaff *) Denemo.project->movement->currentstaff->data)->sources;
1120 scheme_hide_window (SCM_BOOL_T);
1121 GdkRectangle *rect = screenshot_find_rectangle ();
1122 if (rect)
1123 {
1124 //g_debug("%d %d %d %d\n", rect->x, rect->y, rect->width, rect->height);
1125 GdkPixbuf *screenshot = screenshot_get_pixbuf (gdk_get_default_root_window (), rect);
1126 if (screenshot)
1127 {
1128 *sources = g_list_insert (*sources, GINT_TO_POINTER (screenshot), pos); //-1 appends
1129 ret = SCM_BOOL_T;
1130 }
1131 }
1132 scheme_hide_window (SCM_BOOL_F);
1133
1134 return ret;
1135 }
1136
1137 SCM
scheme_delete_screenshot(SCM type)1138 scheme_delete_screenshot (SCM type)
1139 {
1140 GList **sources;
1141 if (scm_is_false (type))
1142 sources = &Denemo.project->movement->sources;
1143 else
1144 sources = &((DenemoStaff *) Denemo.project->movement->currentstaff->data)->sources;
1145 if (*sources)
1146 {
1147 GList *g = g_list_nth (*sources, Denemo.project->movement->currentmeasurenum - 1);
1148 if (g)
1149 {
1150 *sources = g_list_remove_link (*sources, g);
1151 //FIXME free g->data and g
1152 return SCM_BOOL_T;
1153 }
1154 }
1155 return SCM_BOOL_F;
1156 }
1157 #endif
1158 #endif //_WITH_X11_
1159 SCM
scheme_push_clipboard(SCM optional)1160 scheme_push_clipboard (SCM optional)
1161 {
1162 push_clipboard ();
1163 return SCM_BOOL_T;
1164 }
1165
1166 SCM
scheme_pop_clipboard(SCM optional)1167 scheme_pop_clipboard (SCM optional)
1168 {
1169 if (pop_clipboard ())
1170 return SCM_BOOL_T;
1171 else
1172 return SCM_BOOL_F;
1173 }
1174
1175 SCM
scheme_delete_selection(SCM optional)1176 scheme_delete_selection (SCM optional)
1177 {
1178 if ((!Denemo.project->movement) || (!Denemo.project->movement->markstaffnum))
1179 return SCM_BOOL_F;
1180 delete_selection ();
1181 return SCM_BOOL_T;
1182 }
1183
1184 SCM
scheme_set_thumbnail_selection(SCM optional)1185 scheme_set_thumbnail_selection (SCM optional)
1186 {
1187 if ((!Denemo.project->movement) || (!Denemo.project->movement->markstaffnum))
1188 return SCM_BOOL_F;
1189 if (Denemo.project->movement == Denemo.project->movements->data)
1190 {
1191 memcpy (&Denemo.project->thumbnail, &Denemo.project->movement->selection, sizeof (DenemoSelection));
1192 return SCM_BOOL_T;
1193 }
1194 return SCM_BOOL_F;
1195 }
1196
1197 SCM
scheme_set_newbie(SCM optional)1198 scheme_set_newbie (SCM optional)
1199 {
1200 SCM ret = SCM_BOOL (Denemo.prefs.newbie);
1201 if (scm_is_true (optional))
1202 {
1203 Denemo.prefs.tooltip_timeout = 1000;
1204 Denemo.prefs.tooltip_browse_timeout = 700;
1205 Denemo.prefs.tooltip_browse_mode_timeout = 1000;
1206
1207 Denemo.prefs.learning = 1;
1208 Denemo.prefs.newbie = 1;
1209 }
1210 else
1211 {
1212 Denemo.prefs.tooltip_timeout = Denemo.prefs.tooltip_browse_timeout = 2000;
1213 Denemo.prefs.newbie = 0;
1214 gtk_widget_set_tooltip_text (Denemo.scorearea, NULL);
1215 }
1216 return ret;
1217 }
1218
1219 SCM
scheme_get_checksum(SCM str)1220 scheme_get_checksum (SCM str)
1221 {
1222 SCM ret = SCM_BOOL_F;
1223 if (scm_is_string (str))
1224 {
1225 gchar *chk;
1226 gchar *thestring = scm_to_locale_string (str);
1227 chk = g_compute_checksum_for_string (G_CHECKSUM_MD5, thestring, -1);
1228 ret = scm_from_locale_string (chk);
1229 g_free (chk);
1230 }
1231 return ret;
1232 }
1233
1234 SCM
scheme_create_thumbnail(SCM optional,SCM filename)1235 scheme_create_thumbnail (SCM optional, SCM filename)
1236 {
1237 #ifndef USE_EVINCE
1238 g_debug("This feature requires denemo to be built with evince");
1239 return SCM_BOOL_F;
1240 #else
1241 gchar* path = scm_is_string (filename) ? scm_to_locale_string(filename) : NULL;
1242 gboolean ret;
1243 if ((!SCM_UNBNDP (optional)) && scm_is_true (optional))
1244 ret = create_thumbnail (TRUE, path);
1245 else
1246 ret = create_thumbnail (FALSE, path);
1247 return SCM_BOOL (ret);
1248 #endif
1249 }
1250
1251 SCM
scheme_exit(SCM optional)1252 scheme_exit (SCM optional)
1253 {
1254 exit (0);
1255 }
1256
1257 SCM
scheme_create_layout(SCM name)1258 scheme_create_layout (SCM name)
1259 {
1260 if (scm_is_string (name))
1261 {
1262 gchar *layout_name = scm_to_locale_string (name);
1263 return scm_from_bool (create_custom_scoreblock (layout_name, TRUE));
1264 }
1265 return SCM_BOOL_F;
1266 }
1267 SCM
scheme_delete_layout(SCM name)1268 scheme_delete_layout (SCM name)
1269 {
1270 if (scm_is_string (name))
1271 {
1272 gchar *layout_name = scm_to_locale_string (name);
1273 return scm_from_bool (delete_custom_scoreblock (layout_name));
1274 }
1275 return SCM_BOOL_F;
1276 }
1277 SCM
scheme_lilypond_for_part(void)1278 scheme_lilypond_for_part (void)
1279 {
1280 gint save = Denemo.project->movement->markstaffnum;
1281 Denemo.project->movement->markstaffnum = 0;
1282 if (!select_custom_layout_for_name (((DenemoStaff *) (Denemo.project->movement->currentstaff->data))->lily_name->str))
1283 generate_lilypond_part ();
1284 Denemo.project->movement->markstaffnum = save;
1285 return SCM_BOOL_T;
1286 }
1287
1288 SCM
scheme_typeset_part(void)1289 scheme_typeset_part (void)
1290 {
1291 #ifndef USE_EVINCE
1292 g_debug("This feature requires denemo to be built with evince");
1293 return SCM_BOOL_F;
1294 #else
1295 typeset_part ();
1296 return SCM_BOOL_T;
1297 #endif
1298 }
1299
1300 SCM
scheme_reduce_layout_to_lilypond(void)1301 scheme_reduce_layout_to_lilypond (void)
1302 {
1303 make_scoreblock_editable ();
1304 return SCM_BOOL_T;
1305 }
1306
1307 SCM
scheme_get_current_staff_layout_id(void)1308 scheme_get_current_staff_layout_id (void)
1309 {
1310 guint id;
1311 if (((DenemoStaff *) (Denemo.project->movement->currentstaff->data))->voicecontrol == DENEMO_PRIMARY)
1312 {
1313 id = get_layout_id_for_name(((DenemoStaff *) (Denemo.project->movement->currentstaff->data))->lily_name->str);
1314 return scm_from_int(id);
1315 }
1316 return SCM_BOOL_F;
1317 }
1318 SCM
scheme_get_layout_id(void)1319 scheme_get_layout_id (void)
1320 {
1321 DenemoScoreblock *sb = (DenemoScoreblock *)selected_scoreblock ();
1322 if (sb)
1323 return scm_from_int (sb->id);
1324 return SCM_BOOL_F;
1325 }
1326 SCM
scheme_select_layout_id(SCM the_id)1327 scheme_select_layout_id (SCM the_id)
1328 {
1329 if (scm_is_integer (the_id))
1330 {
1331 gint id = scm_to_int (the_id);
1332 return SCM_BOOL (select_layout_id (id));
1333 }
1334 return SCM_BOOL_F;
1335 }
1336
1337 SCM
scheme_select_default_layout(void)1338 scheme_select_default_layout (void)
1339 {
1340 select_default_scoreblock ();
1341 return SCM_BOOL_T;
1342 }
1343
1344 SCM
scheme_get_layout_name(void)1345 scheme_get_layout_name (void)
1346 {
1347 DenemoScoreblock *sb = (DenemoScoreblock *)selected_scoreblock ();
1348 if (sb && sb->name)
1349 return scm_from_locale_string (sb->name);
1350 return SCM_BOOL_F;
1351 }
1352
1353 SCM
scheme_select_next_layout(void)1354 scheme_select_next_layout (void)
1355 {
1356 if (gtk_widget_get_visible (Denemo.project->score_layout))
1357 {
1358 DenemoScoreblock *sb = (DenemoScoreblock *)get_next_scoreblock ();
1359 return sb ? SCM_BOOL_T : SCM_BOOL_F;
1360 }
1361 return SCM_BOOL_F;
1362 }
1363
1364 SCM
scheme_select_first_layout(void)1365 scheme_select_first_layout (void)
1366 {
1367 if (gtk_widget_get_visible (Denemo.project->score_layout))
1368 {
1369 DenemoScoreblock *sb = (DenemoScoreblock *)get_first_scoreblock ();
1370 return sb ? SCM_BOOL_T : SCM_BOOL_F;
1371 }
1372 return SCM_BOOL_F;
1373 }
1374
1375
1376 SCM
scheme_select_next_custom_layout(void)1377 scheme_select_next_custom_layout (void)
1378 {
1379 return SCM_BOOL (iterate_custom_layout (FALSE));
1380 }
1381
1382 SCM
scheme_select_first_custom_layout(void)1383 scheme_select_first_custom_layout (void)
1384 {
1385 return SCM_BOOL (iterate_custom_layout (TRUE));
1386 }
1387 SCM
scheme_get_filename(void)1388 scheme_get_filename (void)
1389 {
1390 if(Denemo.project && Denemo.project->filename && Denemo.project->filename->len && strcmp ("Unnamed", Denemo.project->filename->str))
1391 return scm_from_locale_string (Denemo.project->filename->str);
1392 return SCM_BOOL_F;
1393 }
1394 SCM
scheme_path_from_filename(SCM filepath)1395 scheme_path_from_filename (SCM filepath)
1396 {
1397 SCM ret = SCM_BOOL_F;
1398 if (scm_is_string (filepath))
1399 {
1400 char *temp = scm_to_locale_string (filepath);
1401 gchar *dirname = g_path_get_dirname (temp);
1402 free(temp);
1403 ret = scm_from_locale_string (dirname);
1404 g_free(dirname);
1405 }
1406 return ret;
1407 }
1408
1409 SCM
scheme_filename_from_path(SCM filepath)1410 scheme_filename_from_path (SCM filepath)
1411 {
1412 SCM ret = SCM_BOOL_F;
1413 if (scm_is_string (filepath))
1414 {
1415 char *temp = scm_to_locale_string (filepath);
1416 gchar *dirname = g_path_get_basename (temp);
1417 free(temp);
1418 ret = scm_from_locale_string (dirname);
1419 g_free(dirname);
1420 }
1421 return ret;
1422 }
1423
1424 SCM
scheme_file_exists(SCM filepath)1425 scheme_file_exists (SCM filepath)
1426 {
1427 SCM ret = SCM_BOOL_F;
1428 if (scm_is_string (filepath))
1429 {
1430 char *temp = scm_to_locale_string (filepath);
1431 return SCM_BOOL(g_file_test(temp, G_FILE_TEST_EXISTS));
1432 }
1433 return ret;
1434 }
1435
1436 SCM
scheme_choose_file(SCM title,SCM startdir,SCM list)1437 scheme_choose_file (SCM title, SCM startdir, SCM list)
1438 {
1439 gchar *thetitle = g_strdup(_( "Choose File"));
1440 gchar *thedir = get_project_dir();
1441 GList *exts = NULL;
1442 gchar *filename;
1443 SCM ret = SCM_BOOL_F;
1444 if (scm_is_string (title))
1445 { char *temp = scm_to_locale_string (title);
1446 thetitle = g_strdup(temp);
1447 free(temp);
1448 }
1449 if (scm_is_string (startdir))
1450 {
1451 char *temp = scm_to_locale_string (startdir);
1452 g_free(thedir);
1453 thedir = g_strdup(temp);
1454 free(temp);
1455 }
1456 if (scm_is_list(list))
1457 {
1458 gint length = scm_to_int (scm_length (list));
1459 int i;
1460 for (i=0;i<length;i++)
1461 {
1462 SCM glob = scm_list_ref (list, scm_from_int(i));
1463 if (scm_is_string (glob))
1464 { char *extension = scm_to_locale_string (glob);
1465 exts = g_list_append (exts, g_strdup(extension));
1466 free(extension);
1467 }
1468 }
1469 }
1470 filename = choose_file (thetitle, thedir, exts);
1471 g_free(thetitle);
1472 g_free(thedir);
1473 g_list_free_full (exts, g_free);
1474 if(filename)
1475 ret = scm_from_locale_string(filename);
1476 g_free(filename);
1477 return ret;
1478 }
1479
1480 SCM
scheme_edit_graphics(SCM name,SCM newname)1481 scheme_edit_graphics (SCM name, SCM newname)
1482 {
1483 SCM ret = SCM_BOOL_F;
1484 gchar *opened = NULL;
1485 gchar *thenewname = NULL;
1486 if(scm_is_string (newname))
1487 thenewname = scm_to_locale_string (newname);
1488 if (scm_is_string (name))
1489 {
1490 gchar *filename = scm_to_locale_string (name);
1491
1492 opened = edit_graphics_file (filename, thenewname);
1493 free (filename);
1494 } else
1495 {
1496 opened = edit_graphics_file (NULL, thenewname);
1497 }
1498 if(opened)
1499 ret = scm_from_locale_string (opened);
1500 g_free (opened);
1501 if(thenewname) free(thenewname);
1502 return ret;
1503 }
1504
1505 SCM
scheme_open_source(SCM link)1506 scheme_open_source (SCM link)
1507 {
1508 SCM ret = SCM_BOOL_F;
1509 #ifndef USE_EVINCE
1510 g_debug("This feature requires denemo to be built with evince");
1511 #else
1512 if (scm_is_string (link))
1513 {
1514 gchar *thestring = scm_to_locale_string (link);
1515 gchar *filename;
1516 #ifdef G_OS_WIN32
1517 filename = thestring;
1518 (void) strtok (thestring+2, ":");//skip leading drive name on windows
1519 #else
1520 filename = strtok (thestring, ":");//will not work if filename contains ':' characters.
1521 #endif
1522 if (filename)
1523 {
1524 gint x, y, page;
1525
1526 gchar *xstr = strtok (NULL, ":");
1527 gchar *ystr = strtok (NULL, ":");
1528 gchar *pstr = strtok (NULL, ":");
1529 x = xstr ? atoi (xstr) : 0;
1530 y = ystr ? atoi (ystr) : 0;
1531 page = pstr ? atoi (pstr) : 0;
1532
1533 if (open_source (filename, x, y, page))
1534 ret = SCM_BOOL_T;
1535 }
1536 if (thestring)
1537 free (thestring);
1538 }
1539 #endif
1540 return ret;
1541 }
1542
1543 SCM
scheme_open_source_file(SCM optional)1544 scheme_open_source_file (SCM optional)
1545 {
1546 if (open_source_file ())
1547 return SCM_BOOL_T;
1548 return SCM_BOOL_F;
1549 }
1550 SCM
scheme_open_proofread_file(SCM optional)1551 scheme_open_proofread_file (SCM optional)
1552 {
1553 if (open_proof_file ())
1554 return SCM_BOOL_T;
1555 return SCM_BOOL_F;
1556 }
1557
1558 SCM
scheme_export_recorded_audio(void)1559 scheme_export_recorded_audio (void)
1560 {
1561
1562 return SCM_BOOL (export_recorded_audio ());
1563
1564 }
1565
1566 SCM
scheme_open_source_audio_file(SCM optional)1567 scheme_open_source_audio_file (SCM optional)
1568 {
1569 if(open_source_audio_file () && Denemo.project->movement->recording && Denemo.project->movement->recording->samplerate) {
1570 return scm_from_double (Denemo.project->movement->recording->nframes/(double)Denemo.project->movement->recording->samplerate);
1571 }
1572 return SCM_BOOL_F;
1573 }
1574
1575 SCM
scheme_close_source_audio(SCM optional)1576 scheme_close_source_audio (SCM optional)
1577 {
1578 return SCM_BOOL (close_source_audio ());
1579 }
1580
1581 SCM
scheme_start_audio_play(SCM annotate)1582 scheme_start_audio_play (SCM annotate)
1583 {
1584 if (Denemo.project->movement->recording)
1585 {
1586 start_audio_playing (scm_is_true (annotate));
1587 return SCM_BOOL_T;
1588 }
1589 return SCM_BOOL_F;
1590 }
1591
1592 SCM
scheme_set_audio_lead_in(SCM seconds)1593 scheme_set_audio_lead_in (SCM seconds)
1594 {
1595 if (scm_is_real (seconds))
1596 {
1597 gdouble secs = scm_to_double (seconds);
1598 return SCM_BOOL (set_lead_in (secs));
1599 }
1600 return SCM_BOOL_F;
1601 }
1602
1603 SCM
scheme_stop_audio_play(SCM annotate)1604 scheme_stop_audio_play (SCM annotate)
1605 {
1606 if (audio_is_playing ())
1607 {
1608 stop_audio_playing ();
1609 return SCM_BOOL_T;
1610 }
1611 return SCM_BOOL_F;
1612 }
1613
1614 SCM
scheme_audio_is_playing(void)1615 scheme_audio_is_playing (void)
1616 {
1617 return SCM_BOOL (audio_is_playing ());
1618 }
1619
1620 SCM
scheme_next_audio_timing(SCM optional)1621 scheme_next_audio_timing (SCM optional)
1622 {
1623 if (Denemo.project->movement->recording)
1624 {
1625 gdouble timing = get_audio_timing ();
1626 if (timing > 0.0)
1627 return scm_from_double (timing);
1628 }
1629 return SCM_BOOL_F;
1630 }
1631
1632 SCM
scheme_take_snapshot(SCM optional)1633 scheme_take_snapshot (SCM optional)
1634 {
1635 return SCM_BOOL (take_snapshot ());
1636 }
1637
1638 SCM
scheme_increase_guard(SCM optional)1639 scheme_increase_guard (SCM optional)
1640 {
1641 if (Denemo.project->movement->undo_guard++)
1642 return SCM_BOOL_F;
1643 return SCM_BOOL_T;
1644 }
1645
1646 SCM
scheme_decrease_guard(SCM optional)1647 scheme_decrease_guard (SCM optional)
1648 {
1649 if (Denemo.project->movement->undo_guard > 0)
1650 return SCM_BOOL (!--Denemo.project->movement->undo_guard);
1651 Denemo.project->movement->undo_guard = 0;
1652 return SCM_BOOL_T;
1653 }
1654
1655 //From a script undo must undo only the modifications to the start of the
1656 //script, and push another STAGE_END for the end of the actions that it will do
1657 //after the invocation of undo. This function overrides the built-in undo called
1658 //directly by the user.
1659 SCM
scheme_undo(SCM optional)1660 scheme_undo (SCM optional)
1661 {
1662 stage_undo (Denemo.project->movement, ACTION_STAGE_START);
1663 undowrapper (NULL, NULL);
1664 stage_undo (Denemo.project->movement, ACTION_STAGE_END);
1665 return SCM_BOOL_T;
1666 }
1667
1668 //Break the script up for undo purposes
1669 SCM
scheme_stage_for_undo(SCM optional)1670 scheme_stage_for_undo (SCM optional)
1671 {
1672 stage_undo (Denemo.project->movement, ACTION_STAGE_START);
1673 stage_undo (Denemo.project->movement, ACTION_STAGE_END);
1674 return SCM_BOOL_T;
1675 }
1676
1677 SCM
scheme_get_last_change(SCM optional)1678 scheme_get_last_change (SCM optional)
1679 {
1680 SCM ret = SCM_BOOL_F;
1681 gchar *last = get_last_change (Denemo.project->movement);
1682 if (last)
1683 ret = scm_from_locale_string (last);
1684 g_free (last);
1685 return ret;
1686 }
1687
1688
1689
1690
1691 SCM
scheme_new_window(SCM optional)1692 scheme_new_window (SCM optional)
1693 {
1694 stage_undo (Denemo.project->movement, ACTION_STAGE_START);
1695
1696 //gint current = Denemo.project->scorearea->allocation.width;
1697 newview (NULL, NULL);
1698 // Denemo.project->scorearea->allocation.width = current;
1699
1700 stage_undo (Denemo.project->movement, ACTION_STAGE_END);
1701 return SCM_BOOL_T;
1702 }
1703
1704
1705 SCM
scheme_zoom(SCM factor)1706 scheme_zoom (SCM factor)
1707 {
1708 if (scm_is_real (factor))
1709 Denemo.project->movement->zoom = scm_to_double (factor);
1710 else if (scm_is_string (factor))
1711 {
1712 char *name;
1713 name = scm_to_locale_string (factor);
1714 if (name)
1715 {
1716 Denemo.project->movement->zoom = atof (name);
1717 free (name);
1718 }
1719 }
1720 else
1721 {
1722 return scm_from_double (Denemo.project->movement->zoom);
1723 }
1724 scorearea_configure_event (Denemo.scorearea, NULL);
1725 if (Denemo.project->movement->zoom > 0.01)
1726 {
1727 return scm_from_int (Denemo.project->movement->zoom);
1728 }
1729 Denemo.project->movement->zoom = 1.0;
1730 return SCM_BOOL_F;
1731 }
1732
1733 SCM
scheme_master_tempo(SCM factor)1734 scheme_master_tempo (SCM factor)
1735 {
1736 DenemoMovement *si = Denemo.project->movement;
1737 gdouble request_time = get_time ();
1738 gdouble duration = request_time - si->tempo_change_time;
1739 si->start_player += duration * (1.0 - si->master_tempo);
1740
1741 if (scm_is_real (factor))
1742 si->master_tempo = scm_to_double (factor);
1743 else if (scm_is_string (factor))
1744 {
1745 char *name;
1746 name = scm_to_locale_string (factor);
1747 if (name)
1748 {
1749 si->master_tempo = atof (name);
1750 free (name);
1751 }
1752 }
1753 else
1754 {
1755 return scm_from_double (si->master_tempo);
1756 }
1757 if (si->master_tempo < 0.0)
1758 si->master_tempo = 1.0;
1759
1760 si->tempo_change_time = request_time;
1761 return scm_from_double (si->master_tempo);
1762 }
1763
1764 SCM
scheme_movement_tempo(SCM bpm)1765 scheme_movement_tempo (SCM bpm)
1766 {
1767 DenemoMovement *si = Denemo.project->movement;
1768 if (scm_is_real (bpm))
1769 si->tempo = scm_to_int (bpm);
1770 if (scm_is_string (bpm))
1771 {
1772 char *name;
1773 name = scm_to_locale_string (bpm);
1774 if (name)
1775 {
1776 gdouble tempo = atof (name);
1777 si->tempo = tempo;
1778 set_master_tempo (si, si->master_tempo);
1779 free (name);
1780 }
1781 }
1782
1783 if (si->tempo < 1)
1784 si->tempo = 120;
1785 return scm_from_int (si->tempo);
1786 }
1787
1788 SCM
scheme_master_volume(SCM factor)1789 scheme_master_volume (SCM factor)
1790 {
1791 DenemoMovement *si = Denemo.project->movement;
1792 if (scm_is_real (factor))
1793 si->master_volume = scm_to_double (factor);
1794 if (scm_is_string (factor))
1795 {
1796 char *name;
1797 name = scm_to_locale_string (factor);
1798 if (name)
1799 {
1800 si->master_volume = atof (name);
1801 free (name);
1802 }
1803 }
1804 if (si->master_volume < 0.0)
1805 si->master_volume = 1.0;
1806 return scm_from_double (si->master_volume);
1807 }
1808
1809 SCM
scheme_staff_master_volume(SCM level)1810 scheme_staff_master_volume (SCM level)
1811 {
1812 DenemoStaff *thestaff = (DenemoStaff *) Denemo.project->movement->currentstaff->data;
1813 if (scm_is_real (level))
1814 {
1815 gdouble master_volume = scm_to_double (level);
1816 thestaff->volume = (gint) (master_volume * 127);
1817 if (thestaff->volume > 127)
1818 thestaff->volume = 127;
1819 if (thestaff->volume < 0)
1820 thestaff->volume = 0;
1821
1822 return scm_from_double (thestaff->volume / 127.0);
1823 }
1824 if (scm_is_false (level))
1825 {
1826 thestaff->mute = TRUE;
1827 return scm_from_double (0.0);
1828 }
1829 if (level == SCM_UNDEFINED)
1830 return thestaff->mute?scm_from_double (0.0) : scm_from_double (thestaff->volume / 127.0);
1831 thestaff->mute = FALSE;
1832 return scm_from_double (thestaff->volume / 127.0);
1833 }
1834
1835 SCM
scheme_get_midi_tuning(void)1836 scheme_get_midi_tuning (void)
1837 {
1838 gchar *cents = get_cents_string ();
1839 SCM ret = scm_from_locale_string (cents);
1840 g_free (cents);
1841 return ret;
1842 }
1843
1844 SCM
scheme_get_sharpest(void)1845 scheme_get_sharpest (void)
1846 {
1847 gchar *name = get_sharpest ();
1848 SCM ret = scm_from_locale_string (name);
1849 g_free (name);
1850 return ret;
1851 }
1852
1853 SCM
scheme_get_flattest(void)1854 scheme_get_flattest (void)
1855 {
1856 gchar *name = get_flattest ();
1857 SCM ret = scm_from_locale_string (name);
1858 g_free (name);
1859 return ret;
1860 }
1861
1862 SCM
scheme_get_temperament(void)1863 scheme_get_temperament (void)
1864 {
1865 gchar *name = get_temperament_name ();
1866 SCM ret = scm_from_locale_string (name);
1867 g_free (name);
1868 return ret;
1869 }
1870
1871 static SCM
ignore_handler(gchar * data SCM_UNUSED,SCM tag,SCM throw_args SCM_UNUSED)1872 ignore_handler (gchar * data SCM_UNUSED, SCM tag, SCM throw_args SCM_UNUSED)
1873 {
1874 // g_warning("ignoring throw");
1875 return SCM_BOOL_F;
1876 }
1877
1878 void
set_meantone_tuning(gint step)1879 set_meantone_tuning (gint step)
1880 {
1881 SCM thestep = scm_from_int (step);
1882 if (SCM_BOOL_F == scm_internal_catch (SCM_BOOL_T, (scm_t_catch_body) scm_c_lookup, (void *) "SetQuarterCommaMeanTone", (scm_t_catch_handler) ignore_handler, (void *) "whoops"))
1883 return;
1884 SCM func_symbol = scm_c_lookup ("SetQuarterCommaMeanTone");
1885 SCM func = scm_variable_ref (func_symbol);
1886 scm_call_1 (func, thestep);
1887 }
1888
1889 SCM
scheme_set_enharmonic_position(SCM position)1890 scheme_set_enharmonic_position (SCM position)
1891 {
1892 if (scm_is_integer (position))
1893 {
1894 gint pos = scm_to_int (position);
1895 set_enharmonic_position (pos);
1896 return SCM_BOOL_T;
1897 }
1898 return SCM_BOOL_F;
1899 }
1900
1901 SCM
scheme_rewind_midi(SCM start)1902 scheme_rewind_midi (SCM start)
1903 {
1904 DenemoProject *gui = Denemo.project;
1905 double thetime = 0.0;
1906 SCM scm = SCM_BOOL_T;
1907 gint err;
1908 if ((gui->movement->smf == NULL) || (gui->movement->smfsync != gui->movement->changecount))
1909 generate_midi ();
1910 if (scm_is_real (start))
1911 thetime = scm_to_double (start);
1912 if (thetime > 0.0)
1913 {
1914 err = smf_seek_to_seconds (gui->movement->smf, thetime);
1915 if (err)
1916 scm = SCM_BOOL_F;
1917 }
1918 else
1919 smf_rewind (gui->movement->smf);
1920 return scm;
1921 }
1922
1923
1924 SCM
scheme_next_midi_notes(SCM interval)1925 scheme_next_midi_notes (SCM interval)
1926 {
1927 SCM scm = scm_list_n (SCM_UNDEFINED);
1928 DenemoMovement *si = Denemo.project->movement;
1929 if (scm_is_real (interval))
1930 {
1931 double margin = scm_to_double (interval);
1932 double start = -1.0; //unset
1933 smf_event_t *event = si->smf ? smf_peek_next_event (si->smf) : NULL;
1934 if (event)
1935 {
1936 while ((event = smf_peek_next_event (si->smf)))
1937 {
1938 gint key;
1939 if ((key = noteon_key (event)))
1940 {
1941 if (start < 0.0)
1942 start = event->time_seconds;
1943 if ((event->time_seconds - start) < margin)
1944 {
1945 event = smf_get_next_event (si->smf);
1946 scm = scm_cons (scm_from_int (key), scm);
1947 }
1948 else
1949 {
1950 break;
1951 }
1952 }
1953 else
1954 {
1955 event = smf_get_next_event (si->smf);
1956 }
1957 }
1958 }
1959 scm = scm_cons (scm, scm_from_double (start));
1960 return scm;
1961 }
1962 return SCM_BOOL_F;
1963 }
1964
1965 SCM
scheme_get_midi_on_time(void)1966 scheme_get_midi_on_time (void)
1967 {
1968 if (!(Denemo.project->movement->currentobject))
1969 return SCM_BOOL_F;
1970 GList *curObj = Denemo.project->movement->currentobject;
1971 while (curObj && (((DenemoObject *)curObj->data)->type != CHORD))
1972 curObj = curObj->next; //find first note/rest after the cursor
1973 if (curObj && (Denemo.project->movement->smfsync == Denemo.project->movement->changecount))
1974 return scm_from_double (((DenemoObject *)curObj->data)->earliest_time);
1975 return SCM_BOOL_F;
1976 }
1977
1978 SCM
scheme_get_midi_off_time(void)1979 scheme_get_midi_off_time (void)
1980 {
1981 if (!(Denemo.project->movement->currentobject))
1982 return SCM_BOOL_F;
1983 GList *curObj = Denemo.project->movement->currentobject;
1984 while (curObj && (((DenemoObject *)curObj->data)->type != CHORD))
1985 curObj = curObj->prev; //find last note/rest before the cursor
1986 if (curObj && (Denemo.project->movement->smfsync == Denemo.project->movement->changecount))
1987 return scm_from_double (((DenemoObject *)curObj->data)->latest_time);
1988 return SCM_BOOL_F;
1989 }
1990
1991 SCM
scheme_midi_in_listening(void)1992 scheme_midi_in_listening (void)
1993 {
1994 midi_in_adjust (GDK_SHIFT_MASK);
1995 return SCM_BOOL_T;
1996 }
1997 SCM
scheme_midi_in_checking(void)1998 scheme_midi_in_checking (void)
1999 {
2000 midi_in_adjust (GDK_CONTROL_MASK);
2001 return SCM_BOOL_T;
2002 }
2003 SCM
scheme_midi_in_append_edit(void)2004 scheme_midi_in_append_edit (void)
2005 {
2006 midi_in_adjust (0);
2007 return SCM_BOOL_T;
2008 }
2009
2010 SCM
scheme_restart_play(void)2011 scheme_restart_play (void)
2012 {
2013 restart_play ();
2014 return SCM_BOOL_T;
2015 }
2016
convert_and_adjust(SCM time)2017 static double convert_and_adjust (SCM time) {
2018 return scm_to_double (time) * get_playback_speed();
2019 }
2020 SCM
scheme_set_playback_interval(SCM start,SCM end)2021 scheme_set_playback_interval (SCM start, SCM end)
2022 {
2023 stop_midi_playback(NULL, NULL);
2024 if (scm_is_real (start) && scm_is_real (end))
2025 {
2026 Denemo.project->movement->start_time = convert_and_adjust (start);
2027 Denemo.project->movement->end_time = convert_and_adjust (end);
2028 set_start_and_end_objects_for_draw ();
2029 return SCM_BOOL_T;
2030 }
2031 if (scm_is_real (start))
2032 {
2033 Denemo.project->movement->start_time = convert_and_adjust (start);
2034 set_start_and_end_objects_for_draw ();
2035 return SCM_BOOL_T;
2036 }
2037 if (scm_is_real (end))
2038 {
2039 Denemo.project->movement->end_time = convert_and_adjust (end);
2040 set_start_and_end_objects_for_draw ();
2041 return SCM_BOOL_T;
2042 }
2043 if (scm_is_string (start) && scm_is_string (end))
2044 {
2045 char *name;
2046 name = scm_to_locale_string (start);
2047 if (name)
2048 {
2049 Denemo.project->movement->start_time = atof (name);
2050 free (name);
2051 }
2052 name = scm_to_locale_string (end);
2053 if (name)
2054 {
2055 Denemo.project->movement->end_time = atof (name);
2056 free (name);
2057 }
2058 set_start_and_end_objects_for_draw ();
2059 return SCM_BOOL_T;
2060 }
2061 if (scm_is_string (start))
2062 {
2063 char *name;
2064 name = scm_to_locale_string (start);
2065 if (name)
2066 {
2067 Denemo.project->movement->start_time = atof (name);
2068 free (name);
2069 }
2070 set_start_and_end_objects_for_draw ();
2071 return SCM_BOOL_T;
2072 }
2073 if (scm_is_string (end))
2074 {
2075 char *name;
2076 name = scm_to_locale_string (end);
2077 if (name)
2078 {
2079 Denemo.project->movement->end_time = atof (name);
2080 free (name);
2081 }
2082 set_start_and_end_objects_for_draw ();
2083 return SCM_BOOL_T;
2084 }
2085 return SCM_BOOL_F;
2086 }
2087
2088 SCM
scheme_adjust_playback_start(SCM adj)2089 scheme_adjust_playback_start (SCM adj)
2090 {
2091 SCM ret = SCM_BOOL_F;
2092 if (scm_is_real (adj))
2093 {
2094 stop_midi_playback(NULL, NULL);
2095 Denemo.project->movement->start_time += convert_and_adjust (adj);
2096 if (Denemo.project->movement->start_time < 0.0)
2097 Denemo.project->movement->start_time = 0.0;
2098 else
2099 ret = SCM_BOOL_T;
2100 }
2101 set_start_and_end_objects_for_draw ();
2102 return ret;
2103 }
2104
2105 SCM
scheme_adjust_playback_end(SCM adj)2106 scheme_adjust_playback_end (SCM adj)
2107 {
2108 SCM ret = SCM_BOOL_F;
2109 if (scm_is_real (adj))
2110 {
2111 stop_midi_playback(NULL, NULL);
2112 if (Denemo.project->movement->end_time > 0)
2113 Denemo.project->movement->end_time += convert_and_adjust (adj);
2114 if (Denemo.project->movement->end_time > 0.0)
2115 ret = SCM_BOOL_T;
2116 }
2117 set_start_and_end_objects_for_draw ();
2118 return ret;
2119 }
2120
2121
2122 SCM
scheme_get_help(SCM command)2123 scheme_get_help (SCM command)
2124 {
2125 char *name = NULL;
2126 if (scm_is_string (command))
2127 name = scm_to_locale_string (command);
2128 if (name == NULL)
2129 {
2130 return SCM_BOOL_F;
2131 }
2132 gint idx = lookup_command_from_name (Denemo.map, name);
2133 if (name)
2134 free (name);
2135 if (idx < 0)
2136 {
2137 #if 0
2138 SCM help = scm_c_eval_string (g_strconcat ("Help-d-", name));
2139 return help;
2140 #else
2141 return SCM_BOOL_F;
2142 #endif
2143 }
2144 return scm_from_locale_string ((gchar *) lookup_tooltip_from_idx (Denemo.map, idx));
2145 }
2146
2147 SCM
scheme_get_lily_version(SCM optional)2148 scheme_get_lily_version (SCM optional)
2149 {
2150 gchar *version = get_lily_version_string ();
2151 return scm_from_locale_string (version);
2152 }
2153
2154 SCM
scheme_check_lily_version(SCM check_version)2155 scheme_check_lily_version (SCM check_version)
2156 {
2157 char *version;
2158 if (scm_is_string (check_version))
2159 {
2160 version = scm_to_locale_string (check_version);
2161 }
2162 else
2163 {
2164 return SCM_BOOL_F;
2165 }
2166 gint result = check_lily_version (version);
2167 if (version)
2168 free (version);
2169 if (result > 0)
2170 {
2171 return SCM_BOOL_T;
2172 }
2173 else
2174 {
2175 return SCM_BOOL_F;
2176 }
2177 }
2178
2179 SCM
scheme_get_id(SCM command)2180 scheme_get_id (SCM command)
2181 {
2182 char *name;
2183 if (scm_is_string (command))
2184 {
2185 gint id;
2186 name = scm_to_locale_string (command);
2187 id = lookup_command_from_name (Denemo.map, name);
2188 if (name)
2189 free (name);
2190 if (id != -1)
2191 {
2192 return scm_from_int (id);
2193 }
2194 }
2195 return SCM_BOOL_F;
2196 }
2197
2198 SCM
scheme_add_keybinding(SCM command,SCM binding)2199 scheme_add_keybinding (SCM command, SCM binding)
2200 {
2201 char *shortcut;
2202 char *name;
2203 gint id;
2204 gint old_id = -1;
2205 if (scm_is_string (binding))
2206 {
2207 shortcut = scm_to_locale_string (binding);
2208 if (scm_is_string (command))
2209 {
2210 name = scm_to_locale_string (command);
2211 old_id = add_keybinding_for_name (name, shortcut);
2212 }
2213 else if (scm_is_integer (command))
2214 {
2215 id = scm_to_int (command);
2216 if (id >= 0)
2217 old_id = add_keybinding_for_command (id, shortcut);
2218 }
2219 if (shortcut)
2220 free (shortcut);
2221 if (name)
2222 free (name);
2223 }
2224 if (old_id >= 0)
2225 {
2226 return scm_from_int (old_id);
2227 }
2228 else
2229 {
2230 return SCM_BOOL_F;
2231 }
2232 }
2233
2234 SCM
scheme_get_label(SCM command)2235 scheme_get_label (SCM command)
2236 {
2237 char *name;
2238 if (scm_is_string (command))
2239 {
2240 name = scm_to_locale_string (command);
2241 }
2242 else
2243 {
2244 return SCM_BOOL_F;
2245 }
2246 if (name == NULL)
2247 {
2248 return SCM_BOOL_F;
2249 }
2250 gint idx = lookup_command_from_name (Denemo.map, name);
2251 if (name)
2252 free (name);
2253 if (idx < 0)
2254 {
2255 return SCM_BOOL_F;
2256 }
2257 return scm_from_locale_string ((gchar *) lookup_label_from_idx (Denemo.map, idx));
2258 }
2259
2260
2261
2262
2263 SCM
scheme_get_menu_position(SCM command)2264 scheme_get_menu_position (SCM command)
2265 {
2266 char *name;
2267 SCM ret;
2268 gchar *menuposition = NULL;
2269 if (scm_is_string (command))
2270 {
2271 name = scm_to_locale_string (command);
2272 }
2273 else
2274 {
2275 return SCM_BOOL_F;
2276 }
2277 if (name == NULL)
2278 {
2279 return SCM_BOOL_F;
2280 }
2281
2282 gint idx = lookup_command_from_name (Denemo.map, name);
2283 command_row* row = NULL;
2284 keymap_get_command_row(Denemo.map, &row, idx);
2285 if (name)
2286 free (name);
2287 if (idx < 0)
2288 {
2289 return SCM_BOOL_F;
2290 }
2291 menuposition = get_menu_position (row->menupath);
2292
2293 if(menuposition && *menuposition) {
2294 ret = scm_from_locale_string (menuposition);
2295 g_free(menuposition);
2296 }
2297 return ret;
2298 }
2299
2300
2301 SCM
scheme_get_menu_path(SCM command)2302 scheme_get_menu_path (SCM command)
2303 {
2304 char *name;
2305 if (scm_is_string (command))
2306 {
2307 name = scm_to_locale_string (command);
2308 }
2309 else
2310 {
2311 return SCM_BOOL_F;
2312 }
2313 if (name == NULL)
2314 {
2315 return SCM_BOOL_F;
2316 }
2317 gint idx = lookup_command_from_name (Denemo.map, name);
2318 command_row* row = NULL;
2319 keymap_get_command_row(Denemo.map, &row, idx);
2320 if (name)
2321 free (name);
2322 if (idx < 0)
2323 {
2324 return SCM_BOOL_F;
2325 }
2326 if (row->menupath == NULL)
2327 {
2328 return SCM_BOOL_F;
2329 }
2330 return scm_from_locale_string (row->menupath);
2331 }
2332
2333 SCM
scheme_get_verse(SCM number)2334 scheme_get_verse (SCM number)
2335 {
2336 gchar *text = NULL;
2337 DenemoProject *gui = Denemo.project;
2338 if (scm_is_integer (number))
2339 {
2340 text = get_lyrics_for_verse_num (scm_to_int (number));
2341 }
2342 else
2343 {
2344 DenemoStaff *staff = (DenemoStaff *) gui->movement->currentstaff->data;
2345 text = get_lyrics_for_current_verse (staff);
2346 }
2347 if (text)
2348 {
2349 SCM scm = scm_from_locale_string (text);
2350 //wrong!! g_free(text);
2351 return scm;
2352 }
2353 return SCM_BOOL_F;
2354 }
2355
2356 SCM
scheme_syllable_count(void)2357 scheme_syllable_count (void)
2358 {
2359 if(Denemo.project->movement->currentobject)
2360 return scm_from_int (syllable_count ());
2361 return SCM_BOOL_F;
2362 }
2363
2364 SCM
scheme_typeset_lyrics_for_staff(SCM on)2365 scheme_typeset_lyrics_for_staff (SCM on)
2366 {
2367 DenemoStaff *staff = (DenemoStaff *) Denemo.project->movement->currentstaff->data;
2368 if (scm_is_bool (on))
2369 staff->hide_lyrics = !scm_is_true (on);
2370 return scm_from_bool (!staff->hide_lyrics);
2371 }
2372 SCM
scheme_synchronize_lyric_cursor(SCM val)2373 scheme_synchronize_lyric_cursor (SCM val)
2374 {
2375 gint offset = 0;
2376 if(scm_is_integer (val))
2377 offset = scm_to_int (val);
2378 return SCM_BOOL(synchronize_lyric_cursor(offset));
2379
2380 }
2381 SCM
scheme_insert_text_in_verse(SCM text)2382 scheme_insert_text_in_verse (SCM text)
2383 {
2384 if (scm_is_string (text))
2385 {
2386 char *thetext;
2387 thetext = scm_to_locale_string (text);
2388 return SCM_BOOL(insert_text_in_verse(thetext));
2389 }
2390 return SCM_BOOL_F;
2391 }
2392 SCM
scheme_put_verse(SCM verse)2393 scheme_put_verse (SCM verse)
2394 {
2395 DenemoProject *gui = Denemo.project;
2396 DenemoStaff *staff = (DenemoStaff *) gui->movement->currentstaff->data;
2397 if (scm_is_string (verse))
2398 {
2399 char *text;
2400 text = scm_to_locale_string (verse);
2401 gboolean ret = put_lyrics_for_current_verse (staff, text);
2402 if (text)
2403 free (text);
2404 return SCM_BOOL (ret);
2405 }
2406 return SCM_BOOL_F;
2407 }
2408
2409 SCM
scheme_append_to_verse(SCM verse)2410 scheme_append_to_verse (SCM verse)
2411 {
2412 DenemoProject *gui = Denemo.project;
2413 DenemoStaff *staff = (DenemoStaff *) gui->movement->currentstaff->data;
2414 if (scm_is_string (verse))
2415 {
2416 char *text;
2417 text = scm_to_locale_string (verse);
2418 gboolean ret = append_lyrics_for_current_verse (staff, text);
2419 if (text)
2420 free (text);
2421 return SCM_BOOL (ret);
2422 }
2423 return SCM_BOOL_F;
2424 }
2425
2426 /* write MIDI/Audio filter status */
2427 SCM
scheme_input_filter_names(SCM filtername)2428 scheme_input_filter_names (SCM filtername)
2429 {
2430 char *name = NULL;
2431
2432 if (scm_is_string (filtername))
2433 {
2434 name = scm_to_locale_string (filtername);
2435 if (name)
2436 {
2437 g_string_printf (Denemo.input_filters, "MIDI Input: %s", name);
2438 gtk_widget_show (Denemo.input_label);
2439 write_input_status ();
2440 free (name);
2441 return SCM_BOOL_T;
2442 }
2443 }
2444 else
2445 {
2446 gtk_widget_hide (Denemo.input_label);
2447 }
2448 return SCM_BOOL_F;
2449 }
2450
2451 /* write a status label on bottom right of window*/
2452 SCM
scheme_write_status(SCM filtername)2453 scheme_write_status (SCM filtername)
2454 {
2455 char *name = NULL;
2456
2457 if (scm_is_string (filtername))
2458 {
2459 name = scm_to_locale_string (filtername);
2460 if (name && Denemo.input_filters)
2461 {
2462
2463 g_string_assign (Denemo.input_filters, name);
2464 gtk_widget_show (Denemo.input_label);
2465 write_input_status ();
2466 free (name);
2467 return SCM_BOOL_T;
2468 }
2469 }
2470 else
2471 {
2472 gtk_widget_hide (Denemo.input_label);
2473 }
2474 return SCM_BOOL_F;
2475 }
2476
2477 SCM
scheme_goto_position(SCM movement,SCM staff,SCM measure,SCM object)2478 scheme_goto_position (SCM movement, SCM staff, SCM measure, SCM object)
2479 {
2480 gint movementnum, staffnum, measurenum, objectnum;
2481 if (scm_is_integer (movement))
2482 movementnum = scm_to_int (movement);
2483 else
2484 movementnum = g_list_index (Denemo.project->movements, Denemo.project->movement) + 1;
2485 if (scm_is_integer (staff))
2486 staffnum = scm_to_int (staff);
2487 else
2488 staffnum = Denemo.project->movement->currentstaffnum;
2489
2490 if (scm_is_integer (measure))
2491 measurenum = scm_to_int (measure);
2492 else
2493 measurenum = Denemo.project->movement->currentmeasurenum;
2494
2495 if (scm_is_integer (object))
2496 objectnum = scm_to_int (object);
2497 else
2498 objectnum = 1 + Denemo.project->movement->cursor_x;
2499
2500 gint origmvt = g_list_index (Denemo.project->movements, Denemo.project->movement) + 1, origstaff = Denemo.project->movement->currentstaffnum, origmeas = Denemo.project->movement->currentmeasurenum, origpos = 1 + Denemo.project->movement->cursor_x;
2501 goto_movement_staff_obj (NULL, movementnum, staffnum, measurenum, objectnum, 0);
2502 if ((movementnum == g_list_index (Denemo.project->movements, Denemo.project->movement) + 1) && (staffnum == Denemo.project->movement->currentstaffnum) && (measurenum == Denemo.project->movement->currentmeasurenum) && (objectnum == 1 + Denemo.project->movement->cursor_x))
2503 return SCM_BOOL_T;
2504 else
2505 goto_movement_staff_obj (NULL, origmvt, origstaff, origmeas, origpos, 0);
2506
2507 return SCM_BOOL_F;
2508 }
2509
2510 SCM
scheme_shift_cursor(SCM value)2511 scheme_shift_cursor (SCM value)
2512 {
2513 if (!scm_is_integer (value))
2514 return SCM_BOOL_F;
2515 gint shift = scm_to_int (value);
2516 Denemo.project->movement->cursor_y += shift;
2517 Denemo.project->movement->staffletter_y = offsettonumber (Denemo.project->movement->staffletter_y + shift);
2518 return SCM_BOOL_T;
2519
2520
2521
2522 }
2523
2524 SCM
scheme_mid_c_offsettoname(gint offset)2525 scheme_mid_c_offsettoname (gint offset)
2526 {
2527 gchar *notename = g_strdup_printf ("%c", mid_c_offsettoname (offset));
2528 SCM scm = scm_from_locale_string (notename);
2529 g_free (notename);
2530 return scm;
2531 }
2532
2533 SCM
scheme_get_horizontal_position(void)2534 scheme_get_horizontal_position (void)
2535 {
2536 return scm_from_int (1 + Denemo.project->movement->cursor_x);
2537 }
2538
2539 SCM
scheme_set_object_display_width(SCM value)2540 scheme_set_object_display_width (SCM value)
2541 {
2542 if (!scm_is_integer (value))
2543 return SCM_BOOL_F;
2544 if (Denemo.project->movement->currentobject)
2545 {
2546 DenemoObject *obj = Denemo.project->movement->currentobject->data;
2547 gint minpixels = scm_to_int (value);
2548 obj->minpixelsalloted = minpixels;
2549 return SCM_BOOL_T;
2550 }
2551 return SCM_BOOL_F;
2552 }
2553
2554
2555
2556
2557 SCM
scheme_get_movement(void)2558 scheme_get_movement (void)
2559 {
2560 gint num = g_list_index (Denemo.project->movements, Denemo.project->movement) + 1;
2561 return scm_from_int (num);
2562 }
2563
2564 SCM
scheme_get_staff(void)2565 scheme_get_staff (void)
2566 {
2567 gint num = Denemo.project->movement->currentstaffnum;
2568 return scm_from_int (num);
2569 }
2570
2571 SCM
scheme_staff_hidden(SCM set)2572 scheme_staff_hidden (SCM set)
2573 {
2574 DenemoProject *gui = Denemo.project;
2575 DenemoStaff *staff = (DenemoStaff *) gui->movement->currentstaff->data;
2576 if (scm_is_bool (set))
2577 staff->hidden = scm_is_true (set);
2578 return SCM_BOOL (staff->hidden);
2579 }
2580
2581 SCM
scheme_get_voice_identifier(void)2582 scheme_get_voice_identifier (void)
2583 {
2584 gint snum = Denemo.project->movement->currentstaffnum;
2585 gint mnum = g_list_index (Denemo.project->movements, Denemo.project->movement) + 1;
2586 GString *voice_ident = g_string_new ("");
2587 GString *name = g_string_new ("");
2588 g_string_printf (name, "Mvmnt%dVoice%d", mnum, snum);
2589 set_lily_name (name, voice_ident);
2590 SCM ret = scm_from_locale_string (voice_ident->str);
2591 g_string_free (name, TRUE);
2592 g_string_free (voice_ident, TRUE);
2593 return ret;
2594 }
2595
2596
2597 SCM
scheme_get_measure(void)2598 scheme_get_measure (void)
2599 {
2600 gint num = Denemo.project->movement->currentmeasurenum;
2601 return scm_from_int (num);
2602 }
2603
2604 SCM
scheme_get_cursor_note(SCM optional)2605 scheme_get_cursor_note (SCM optional)
2606 {
2607 DenemoProject *gui = Denemo.project;
2608 return scheme_mid_c_offsettoname (gui->movement->cursor_y);
2609 }
2610
2611 SCM
scheme_get_cursor_note_with_octave(SCM optional)2612 scheme_get_cursor_note_with_octave (SCM optional)
2613 {
2614 DenemoProject *gui = Denemo.project;
2615 scm_from_locale_string (mid_c_offsettolily (gui->movement->cursor_y, 0));
2616 return SCM_BOOL_T;
2617 }
2618
2619
2620 SCM
scheme_set_prefs(SCM xml)2621 scheme_set_prefs (SCM xml)
2622 {
2623 if (scm_is_string (xml))
2624 {
2625 char *xmlprefs;
2626 xmlprefs = scm_to_locale_string (xml);
2627 gint fail = readxmlprefsString (xmlprefs);
2628 if (xmlprefs)
2629 free (xmlprefs);
2630 return SCM_BOOL (!fail);
2631 }
2632 return SCM_BOOL (FALSE);
2633 }
2634
2635
2636 SCM
scheme_get_boolean_pref(SCM pref)2637 scheme_get_boolean_pref (SCM pref)
2638 {
2639 gchar *prefname = NULL;
2640 gboolean val;
2641 if (scm_is_string (pref))
2642 {
2643 prefname = scm_to_locale_string (pref);
2644 val = get_bool_pref (prefname);
2645 free (prefname);
2646 return SCM_BOOL (val);
2647 }
2648 return SCM_BOOL_F;
2649 }
2650
2651 SCM
scheme_get_int_pref(SCM pref)2652 scheme_get_int_pref (SCM pref)
2653 {
2654 gchar *prefname = NULL;
2655 gint val;
2656 if (scm_is_string (pref))
2657 {
2658 prefname = scm_to_locale_string (pref);
2659 val = get_int_pref (prefname);
2660 free (prefname);
2661 return scm_from_int (val);
2662 }
2663 return SCM_BOOL_F;
2664 }
2665
2666 SCM
scheme_get_string_pref(SCM pref)2667 scheme_get_string_pref (SCM pref)
2668 {
2669 gchar *prefname = NULL;
2670 gchar *val;
2671 if (scm_is_string (pref))
2672 {
2673 prefname = scm_to_locale_string (pref);
2674 val = get_string_pref (prefname);
2675 free (prefname);
2676 if (val)
2677 return scm_from_locale_string (val);
2678 }
2679 return SCM_BOOL_F;
2680 }
2681
2682 SCM
scheme_attach_quit_callback(SCM callback)2683 scheme_attach_quit_callback (SCM callback)
2684 {
2685 DenemoProject *gui = Denemo.project;
2686 if (scm_is_string (callback))
2687 {
2688 char *scheme;
2689 scheme = scm_to_locale_string (callback);
2690 gui->callbacks = g_list_prepend (gui->callbacks, scheme);
2691 if (scheme)
2692 free (scheme);
2693 }
2694 return SCM_BOOL (TRUE);
2695 }
2696
2697 SCM
scheme_detach_quit_callback(void)2698 scheme_detach_quit_callback (void)
2699 {
2700 DenemoProject *gui = Denemo.project;
2701 if (gui->callbacks)
2702 {
2703 g_free (gui->callbacks->data);
2704 gui->callbacks = g_list_delete_link (gui->callbacks, gui->callbacks);
2705 return SCM_BOOL (TRUE);
2706 }
2707 else
2708 g_warning ("No callback registered");
2709 return SCM_BOOL (FALSE);
2710 }
2711
2712 SCM
scheme_get_input_source(void)2713 scheme_get_input_source (void)
2714 {
2715 return scm_from_int (Denemo.project->input_source);
2716 }
2717
2718
2719 SCM
scheme_chordize(SCM setting)2720 scheme_chordize (SCM setting)
2721 {
2722 DenemoProject *gui = Denemo.project;
2723 DenemoObject *curObj;
2724 chord *thechord;
2725 note *thenote;
2726 if (!Denemo.project || !(Denemo.project->movement) || !(Denemo.project->movement->currentobject) || !(curObj = Denemo.project->movement->currentobject->data) || (curObj->type != CHORD) || !(thechord = (chord *) curObj->object) || !(thechord->notes) || !(thenote = (note *) thechord->notes->data))
2727 return SCM_BOOL (FALSE);
2728 gboolean old = thechord->chordize;
2729 thechord->chordize = scm_is_true (setting);
2730 if (old != thechord->chordize)
2731 score_status (Denemo.project, TRUE);
2732 return SCM_BOOL (TRUE);
2733 }
2734
2735
2736 SCM
scheme_get_note_name(SCM optional)2737 scheme_get_note_name (SCM optional)
2738 {
2739 //char *str=NULL;
2740 //if(scm_is_string(optional)){
2741 //str = scm_to_locale_stringn(optional, &length);
2742 // }
2743 DenemoObject *curObj;
2744 chord *thechord;
2745 note *thenote;
2746 if (!Denemo.project || !(Denemo.project->movement) || !(Denemo.project->movement->currentobject) || !(curObj = Denemo.project->movement->currentobject->data) || (curObj->type != CHORD) || !(thechord = (chord *) curObj->object) || !(thechord->notes) || !(thenote = (note *) thechord->notes->data))
2747 return SCM_BOOL (FALSE);
2748 else
2749 {
2750 return scheme_mid_c_offsettoname (thenote->mid_c_offset);
2751 }
2752
2753 }
2754
2755
2756
2757 //Insert rests to the value of the timesig and return the number of rests inserted.
2758 SCM
scheme_put_whole_measure_rests(void)2759 scheme_put_whole_measure_rests (void)
2760 {
2761 DenemoProject *gui = Denemo.project;
2762 SCM scm;
2763 if (!Denemo.project || !(Denemo.project->movement))
2764 return scm_from_int (0);
2765 else
2766 {
2767 gint numerator = ((DenemoMeasure*)gui->movement->currentmeasure->data)->timesig->time1; // staff->timesig.time1;
2768 gint denominator = ((DenemoMeasure*)gui->movement->currentmeasure->data)->timesig->time2; //staff->timesig.time2;
2769 gboolean dot = TRUE;
2770 if (numerator % 3)
2771 dot = FALSE;
2772 else
2773 numerator = 2 * numerator / 3;
2774 gint length = (numerator * 4) / denominator;
2775 gchar *str = NULL;
2776 scm = scm_from_int (1);
2777 switch (length)
2778 {
2779 case 1: // e.g. 2/8 timesig
2780 str = g_strdup_printf ("(d-InsertRest2)(d-MoveCursorLeft)%s", dot ? "(d-AddDot)" : "");
2781 break;
2782 case 2:
2783 str = g_strdup_printf ("(d-InsertRest1)(d-MoveCursorLeft)%s", dot ? "(d-AddDot)" : "");
2784 break;
2785 case 3: // e.g. 9/8 timesig
2786 str = g_strdup_printf ("(d-InsertRest0)(d-InsertRest3)(d-MoveCursorLeft)(d-MoveCursorLeft)");
2787 scm = scm_from_int (2);
2788 break;
2789 case 4:
2790 str = g_strdup_printf ("(d-InsertRest0)(d-MoveCursorLeft)%s", dot ? "(d-AddDot)" : "");
2791 break;
2792 case 8:
2793 str = g_strdup_printf ("(d-InsertRest0)(d-InsertRest0)(d-MoveCursorLeft)%s", dot ? "(d-AddDot)" : "");
2794 scm = scm_from_int (2);
2795 break;
2796 default:
2797 g_warning ("Not implemented %d %s", length, dot ? "dotted" : "");
2798 scm = scm_from_int (0);
2799 break;
2800 }
2801 if (str)
2802 {
2803 call_out_to_guile (str);
2804 }
2805 g_free (str);
2806 return scm;
2807 }
2808 }
2809
2810 SCM
scheme_get_dots(void)2811 scheme_get_dots (void)
2812 {
2813 DenemoObject *curObj;
2814 chord *thechord;
2815 if (!Denemo.project || !(Denemo.project->movement) || !(Denemo.project->movement->currentobject) || !(curObj = Denemo.project->movement->currentobject->data) || (curObj->type != CHORD) || !(thechord = (chord *) curObj->object))
2816 return SCM_BOOL_F;
2817 return scm_from_int (thechord->numdots);
2818 }
2819
2820 SCM
scheme_get_note_base_duration(void)2821 scheme_get_note_base_duration (void)
2822 {
2823 DenemoObject *curObj;
2824 chord *thechord;
2825 if (!Denemo.project || !(Denemo.project->movement) || !(Denemo.project->movement->currentobject) || !(curObj = Denemo.project->movement->currentobject->data) || (curObj->type != CHORD) || !(thechord = (chord *) curObj->object))
2826 return SCM_BOOL_F;
2827 return scm_from_int (thechord->baseduration);
2828 }
2829
2830 SCM
scheme_get_note_duration(void)2831 scheme_get_note_duration (void)
2832 {
2833 DenemoObject *curObj;
2834 chord *thechord;
2835 gint duration;
2836 gint numdots = 0;
2837 gchar *str;
2838
2839 if (!Denemo.project || !(Denemo.project->movement) || !(Denemo.project->movement->currentobject) || !(curObj = Denemo.project->movement->currentobject->data) || (curObj->type != CHORD) || !(thechord = (chord *) curObj->object))
2840 return SCM_BOOL_F;
2841 if (thechord->baseduration >= 0)
2842 {
2843 duration = 1 << thechord->baseduration;
2844 str = g_strdup_printf ("%d", duration);
2845 if (thechord->numdots)
2846 {
2847 gchar *tmp = NULL;
2848 while (numdots++ < thechord->numdots)
2849 {
2850 tmp = g_strdup_printf ("%s" "%c", str, '.');
2851 g_free (str);
2852 str = tmp;
2853 }
2854 }
2855
2856 SCM scm = scm_from_locale_string (str);
2857 g_free (str);
2858 return scm;
2859 }
2860 return SCM_BOOL_F;
2861 }
2862
2863 SCM
scheme_set_duration_in_ticks(SCM duration)2864 scheme_set_duration_in_ticks (SCM duration)
2865 {
2866 DenemoObject *curObj;
2867 gint thedur = 0;
2868 if (scm_is_integer (duration))
2869 {
2870 thedur = scm_to_int (duration);
2871 }
2872 if (!Denemo.project || !(Denemo.project->movement) || !(Denemo.project->movement->currentobject) || !(curObj = Denemo.project->movement->currentobject->data))
2873 return SCM_BOOL_F;
2874 if (thedur > 0)
2875 {
2876 curObj->basic_durinticks = curObj->durinticks = thedur;
2877 if (curObj->type == CHORD)
2878 {
2879 ((chord *) curObj->object)->baseduration = -thedur;
2880 ((chord *) curObj->object)->numdots = 0;
2881 }
2882 objnode *prev = Denemo.project->movement->currentobject->prev;
2883 DenemoObject *prevObj = prev ? (DenemoObject *) prev->data : NULL;
2884 gint starttick = (prevObj ? prevObj->starttickofnextnote : 0);
2885 curObj->starttickofnextnote = starttick + thedur;
2886 return SCM_BOOL_T;
2887 }
2888 return SCM_BOOL_F;
2889 }
2890
2891
2892 SCM
scheme_get_recorded_midi_tempo(SCM index)2893 scheme_get_recorded_midi_tempo (SCM index)
2894 {
2895 SCM scm = scm_list_n (SCM_UNDEFINED);
2896 if(scm_is_integer(index)) {
2897 gint idx =scm_to_int (index);
2898 smf_tempo_t *tempo = get_recorded_midi_tempo (idx);
2899 if(tempo)
2900 {
2901 scm = scm_cons (scm_from_double (tempo->microseconds_per_quarter_note/1000000.0), scm);
2902 scm = scm_cons (scm_from_int (tempo->denominator), scm);
2903 scm = scm_cons (scm_from_int (tempo->numerator), scm);
2904 scm = scm_cons (scm_from_int (tempo->time_seconds), scm);
2905 return scm;
2906 }
2907 }
2908 return SCM_BOOL_F;
2909 }
2910
2911 SCM
scheme_get_imported_midi_track(SCM index)2912 scheme_get_imported_midi_track (SCM index)
2913 {
2914 if(scm_is_integer(index)) {
2915 gint idx = scm_to_int (index);
2916 if(get_imported_midi_track (idx))
2917 return SCM_BOOL_F;
2918 }
2919 return SCM_BOOL_F;
2920 }
2921
2922 SCM
scheme_delete_imported_midi(void)2923 scheme_delete_imported_midi (void)
2924 {
2925 return SCM_BOOL (delete_imported_midi ());
2926 }
2927
2928
2929 SCM
scheme_get_current_midi_track(void)2930 scheme_get_current_midi_track (void)
2931 {
2932 gint track = get_current_midi_track();
2933 if(track)
2934 return scm_from_int (track);
2935 return SCM_BOOL_F;
2936 }
2937
2938 SCM
scheme_get_imported_midi_tracks(void)2939 scheme_get_imported_midi_tracks (void)
2940 { gint num = get_imported_midi_tracks ();
2941 if(num < 1)
2942 return SCM_BOOL_F;
2943 else
2944 return scm_from_int (num);
2945 }
2946
2947 SCM
scheme_get_recorded_midi_duration(void)2948 scheme_get_recorded_midi_duration (void) {
2949 gdouble duration = get_recorded_midi_duration ();
2950 g_debug("Duration returned %f so %d\n", duration, duration>0.0);
2951 if (duration > 0.0)
2952 return scm_from_double (duration);
2953 return SCM_BOOL_F;
2954 }
2955
2956 SCM
scheme_get_duration_in_ticks(void)2957 scheme_get_duration_in_ticks (void)
2958 {
2959 DenemoObject *curObj;
2960 if (!Denemo.project || !(Denemo.project->movement) || !(Denemo.project->movement->currentobject) || !(curObj = Denemo.project->movement->currentobject->data))
2961 return SCM_BOOL (FALSE);
2962 return scm_from_int (curObj->durinticks);
2963 }
2964
2965 SCM
scheme_get_base_duration_in_ticks(void)2966 scheme_get_base_duration_in_ticks (void)
2967 {
2968 DenemoObject *curObj;
2969 if (!Denemo.project || !(Denemo.project->movement) || !(Denemo.project->movement->currentobject) || !(curObj = Denemo.project->movement->currentobject->data))
2970 return SCM_BOOL (FALSE);
2971 if (curObj->type == CHORD)
2972 return scm_from_int (((chord *) curObj->object)->baseduration >= 0 ? /* (* (expt 2 (- 8 number)) 6) */
2973 (int) pow (2.0, (8.0 - ((chord *) curObj->object)->baseduration)) * 6 : ((chord *) curObj->object)->baseduration);
2974 return SCM_BOOL (FALSE);
2975 }
2976
2977
2978 SCM
scheme_get_end_tick(void)2979 scheme_get_end_tick (void)
2980 {
2981 DenemoObject *curObj;
2982 if (!Denemo.project || !(Denemo.project->movement) || !(Denemo.project->movement->currentobject) || !(curObj = Denemo.project->movement->currentobject->data))
2983 return SCM_BOOL (FALSE);
2984 return scm_from_int (curObj->starttickofnextnote);
2985 }
2986
2987
2988 SCM
scheme_get_start_tick(void)2989 scheme_get_start_tick (void)
2990 {
2991 DenemoObject *curObj;
2992 if (!Denemo.project || !(Denemo.project->movement) || !(Denemo.project->movement->currentobject) || !(curObj = Denemo.project->movement->currentobject->data))
2993 return SCM_BOOL (FALSE);
2994 return scm_from_int (curObj->starttick);
2995 }
2996
2997
2998 SCM
scheme_get_measure_number(void)2999 scheme_get_measure_number (void)
3000 {
3001 return scm_from_int (Denemo.project->movement->currentmeasurenum);
3002 }
3003
3004 SCM
scheme_set_measure_number_offset(SCM val)3005 scheme_set_measure_number_offset (SCM val)
3006 {
3007 DenemoMeasure *themeasure;
3008 if (scm_is_integer (val))
3009 {
3010 gint offset = scm_to_int (val);
3011 DenemoPosition pos;
3012 get_position (Denemo.project->movement, &pos);
3013
3014 gint i=1;
3015
3016 while (goto_movement_staff_obj (NULL, -1, i++, pos.measure, 0, 0))
3017 {
3018 themeasure = (DenemoMeasure *)Denemo.project->movement->currentmeasure->data;
3019 themeasure->measure_numbering_offset = offset;
3020 }
3021 goto_movement_staff_obj (NULL, -1, pos.staff, pos.measure, pos.object, pos.leftmeasurenum);
3022 cache_all ();
3023 }
3024 else
3025 return SCM_BOOL_F;
3026 themeasure = Denemo.project->movement->currentmeasure->data;
3027 return scm_from_int (themeasure->measure_numbering_offset);
3028 }
3029
3030 SCM
scheme_get_measure_number_offset(void)3031 scheme_get_measure_number_offset (void)
3032 {
3033 DenemoMeasure *themeasure = Denemo.project->movement->currentmeasure->data;
3034 return scm_from_int (themeasure->measure_numbering_offset);
3035 }
3036
3037
3038 SCM
scheme_get_note(SCM count)3039 scheme_get_note (SCM count)
3040 {
3041 gint index = 0;
3042 DenemoObject *curObj;
3043 chord *thechord;
3044 note *thenote;
3045 if (scm_is_integer (count))
3046 {
3047 index = scm_to_int (count) - 1;
3048 if (index < 0)
3049 return SCM_BOOL_F;
3050 }
3051 if (!Denemo.project || !(Denemo.project->movement) || !(Denemo.project->movement->currentobject) || !(curObj = Denemo.project->movement->currentobject->data) || (curObj->type != CHORD) || !(thechord = (chord *) curObj->object) || !(thechord->notes) || !(thenote = (note *) g_list_nth_data (thechord->notes, index)))
3052 return SCM_BOOL_F;
3053 else
3054 {
3055 gchar *str = g_strdup_printf ("%s", mid_c_offsettolily (thenote->mid_c_offset, thenote->enshift));
3056 SCM scm = scm_from_locale_string (str);
3057 g_free (str);
3058 return scm;
3059 }
3060
3061 }
3062
3063 SCM
scheme_get_note_from_top(SCM count)3064 scheme_get_note_from_top (SCM count)
3065 {
3066 gint index = 1;
3067 DenemoObject *curObj;
3068 chord *thechord;
3069 note *thenote;
3070 if (scm_is_integer (count))
3071 {
3072 index = scm_to_int (count);
3073 if (index < 1)
3074 return SCM_BOOL_F;
3075 }
3076 if (!Denemo.project || !(Denemo.project->movement) || !(Denemo.project->movement->currentobject) || !(curObj = Denemo.project->movement->currentobject->data) || (curObj->type != CHORD) || !(thechord = (chord *) curObj->object) || !(thechord->notes))
3077 return SCM_BOOL_F;
3078 else
3079 {
3080 SCM scm;
3081 gint end = g_list_length (thechord->notes);
3082 index = end - index;
3083 if (index < 0)
3084 scm = SCM_BOOL_F;
3085 else
3086 {
3087 thenote = (note *) g_list_nth_data (thechord->notes, index);
3088 gchar *str = g_strdup_printf ("%s", mid_c_offsettolily (thenote->mid_c_offset, thenote->enshift));
3089 scm = scm_from_locale_string (str);
3090 g_free (str);
3091 }
3092 return scm;
3093 }
3094
3095 }
3096
3097 SCM
scheme_get_note_from_top_as_midi(SCM count)3098 scheme_get_note_from_top_as_midi (SCM count)
3099 {
3100 gint index = 1;
3101 DenemoObject *curObj;
3102 chord *thechord;
3103 note *thenote;
3104 if (scm_is_integer (count))
3105 {
3106 index = scm_to_int (count);
3107 if (index < 1)
3108 return SCM_BOOL_F;
3109 }
3110 if (!Denemo.project || !(Denemo.project->movement) || !(Denemo.project->movement->currentobject) || !(curObj = Denemo.project->movement->currentobject->data) || (curObj->type != CHORD) || !(thechord = (chord *) curObj->object) || !(thechord->notes))
3111 return SCM_BOOL_F;
3112 else
3113 {
3114 SCM scm;
3115 gint end = g_list_length (thechord->notes);
3116 index = end - index;
3117 if (index < 0)
3118 scm = SCM_BOOL_F;
3119 else
3120 {
3121 thenote = (note *) g_list_nth_data (thechord->notes, index);
3122 gint midi = dia_to_midinote (thenote->mid_c_offset) + thenote->enshift;
3123 scm = scm_from_int (midi);
3124 }
3125 return scm;
3126 }
3127
3128 }
3129
3130
3131 SCM
scheme_spell_check_midi_chord(SCM list)3132 scheme_spell_check_midi_chord (SCM list)
3133 {
3134 SCM scm;
3135 GList *notes = NULL;
3136 gboolean status;
3137 if (scm_is_list (list))
3138 {
3139 for (scm = list; !scm_is_null (scm); scm = scm_cdr (scm))
3140 {
3141 gint note = scm_to_int (scm_car (scm));
3142 notes = g_list_prepend (notes, GINT_TO_POINTER (note));
3143 }
3144 status = check_midi_intervals (notes);
3145 g_list_free (notes);
3146 return status ? SCM_BOOL_T : SCM_BOOL_F;
3147 }
3148 else
3149 {
3150 g_warning ("Bad pitch spell list");
3151 return SCM_BOOL_F;
3152 }
3153 }
3154
3155
3156 SCM
scheme_get_cursor_note_as_midi(SCM optional)3157 scheme_get_cursor_note_as_midi (SCM optional)
3158 {
3159
3160 DenemoProject *gui = Denemo.project;
3161 gint midi = dia_to_midinote (gui->movement->cursor_y);
3162 SCM scm = scm_from_int (midi);
3163 return scm;
3164 }
3165
3166
3167 SCM
scheme_get_note_as_midi(void)3168 scheme_get_note_as_midi (void)
3169 {
3170 DenemoObject *curObj;
3171 chord *thechord;
3172 note *thenote;
3173 if (!Denemo.project || !(Denemo.project->movement) || !(Denemo.project->movement->currentobject) || !(curObj = Denemo.project->movement->currentobject->data) || (curObj->type != CHORD) || !(thechord = (chord *) curObj->object) || !(thechord->notes) || !(thenote = (note *) thechord->notes->data))
3174 return scm_from_int (0);
3175 else
3176 {
3177 gint midi = dia_to_midinote (thenote->mid_c_offset) + thenote->enshift;
3178 SCM scm = scm_from_int (midi);
3179 return scm;
3180 }
3181 }
3182
3183
3184 SCM
scheme_get_notes(SCM optional)3185 scheme_get_notes (SCM optional)
3186 {
3187 DenemoObject *curObj;
3188 chord *thechord;
3189 note *thenote;
3190 GString *str = g_string_new ("");
3191 SCM scm;
3192
3193 if (!Denemo.project || !(Denemo.project->movement) || !(Denemo.project->movement->currentobject) || !(curObj = Denemo.project->movement->currentobject->data) || (curObj->type != CHORD) || !(thechord = (chord *) curObj->object) || !(thechord->notes) || !(thenote = (note *) thechord->notes->data))
3194 return SCM_BOOL (FALSE);
3195 else
3196 {
3197 GList *g;
3198 for (g = thechord->notes; g; g = g->next)
3199 {
3200 thenote = (note *) g->data;
3201 gchar *name = mid_c_offsettolily (thenote->mid_c_offset, thenote->enshift);
3202 str = g_string_append (str, name);
3203 if (g->next)
3204 str = g_string_append (str, " ");
3205 }
3206
3207 scm = scm_from_locale_string (g_string_free (str, FALSE));
3208 return scm;
3209 }
3210 }
3211 SCM
scheme_get_note_at_cursor(void)3212 scheme_get_note_at_cursor (void)
3213 {
3214 DenemoObject *curObj;
3215 chord *thechord;
3216 note *thenote;
3217 GString *str = g_string_new ("");
3218 SCM scm;
3219
3220 if (!Denemo.project || !(Denemo.project->movement) || !(Denemo.project->movement->currentobject) || !(curObj = Denemo.project->movement->currentobject->data) || (curObj->type != CHORD) || !(thechord = (chord *) curObj->object) || !(thechord->notes) || !(thenote = (note *) thechord->notes->data))
3221 return SCM_BOOL_F;
3222 GList *g;
3223 for (g = thechord->notes; g; g = g->next)
3224 {
3225 thenote = (note *) g->data;
3226 if(thenote->mid_c_offset == Denemo.project->movement->cursor_y)
3227 {
3228 gchar *name = mid_c_offsettolily (thenote->mid_c_offset, thenote->enshift);
3229 return scm_from_locale_string (name);
3230 }
3231 }
3232 return SCM_BOOL_F;
3233 }
3234 SCM
scheme_add_movement(SCM optional)3235 scheme_add_movement (SCM optional)
3236 {
3237 append_blank_movement ();
3238 return SCM_BOOL_T;
3239 }
3240
3241 SCM
scheme_get_prevailing_clef(SCM optional)3242 scheme_get_prevailing_clef (SCM optional)
3243 {
3244 gint theclef = find_prevailing_clef (Denemo.project->movement);
3245 //FIXME look at directives to see if it is overridden, e.g. drum clef
3246 const gchar *clefname = get_clef_name (theclef);
3247 if (clefname)
3248 return scm_from_locale_string (clefname);
3249 else
3250 return SCM_BOOL_F;
3251 }
3252
3253 SCM
scheme_get_prevailing_clef_as_lilypond(SCM optional)3254 scheme_get_prevailing_clef_as_lilypond (SCM optional)
3255 {
3256 const gchar *clefname = get_prevailing_clef_as_lilypond ();
3257 if (clefname)
3258 return scm_from_locale_string (clefname);
3259 else
3260 return SCM_BOOL_F;
3261 }
3262
3263 SCM
scheme_get_prevailing_keysig_as_lilypond(SCM optional)3264 scheme_get_prevailing_keysig_as_lilypond (SCM optional)
3265 {
3266 const gchar *keysigname = get_prevailing_keysig_as_lilypond ();
3267 if (keysigname)
3268 return scm_from_locale_string (keysigname);
3269 else
3270 return SCM_BOOL_F;
3271 }
3272
3273 SCM
scheme_get_prevailing_timesig_as_lilypond(SCM optional)3274 scheme_get_prevailing_timesig_as_lilypond (SCM optional)
3275 {
3276 const gchar *timesigname = get_prevailing_timesig_as_lilypond ();
3277 if (timesigname)
3278 return scm_from_locale_string (timesigname);
3279 else
3280 return SCM_BOOL_F;
3281 }
3282
3283 SCM
scheme_get_prevailing_duration(SCM optional)3284 scheme_get_prevailing_duration (SCM optional)
3285 {
3286 if (scm_is_integer (optional))
3287 {
3288 gint duration = scm_to_int (optional);
3289 if(duration >=0 && (duration < 8))
3290 {
3291 SetDur (duration);
3292 return SCM_BOOL_T;
3293 }
3294 return SCM_BOOL_F;
3295 } else
3296 return scm_from_int (get_prevailing_duration ());
3297 }
3298
3299 SCM
scheme_get_prevailing_timesig(SCM optional)3300 scheme_get_prevailing_timesig (SCM optional)
3301 {
3302 timesig *timesig = get_prevailing_context (TIMESIG);
3303 //FIXME look at directives to see if it is overridden, e.g. drum clef
3304 gchar *name = g_strdup_printf ("%d/%d", timesig->time1, timesig->time2);
3305 SCM ret = scm_from_locale_string (name);
3306 g_free (name);
3307
3308 return ret;
3309 }
3310
3311 SCM
scheme_get_prevailing_keysig(SCM optional)3312 scheme_get_prevailing_keysig (SCM optional)
3313 {
3314 GString *str = g_string_new (" ");
3315 keysig *keysig = get_prevailing_context (KEYSIG);
3316 gint i;
3317 for (i = 0; i < 7; i++)
3318 g_string_append_printf (str, "%d ", keysig->accs[i]);
3319 return scm_from_locale_string (g_string_free (str, FALSE));
3320 }
3321
3322 SCM
scheme_set_prevailing_keysig(SCM keyaccs)3323 scheme_set_prevailing_keysig (SCM keyaccs)
3324 {
3325 //keysigs have a field called "number" which determines how it is drawn, setting like this does not get a keysig drawn, nor does it affect lilypond output
3326 char *accs = NULL;
3327 if (scm_is_string (keyaccs))
3328 {
3329 accs = scm_to_locale_string (keyaccs);
3330 }
3331 if (!accs)
3332 {
3333 return SCM_BOOL_F;
3334 }
3335 keysig *keysig = get_prevailing_context (KEYSIG);
3336 sscanf (accs, "%d%d%d%d%d%d%d", keysig->accs + 0, keysig->accs + 1, keysig->accs + 2, keysig->accs + 3, keysig->accs + 4, keysig->accs + 5, keysig->accs + 6);
3337 staff_show_which_accidentals ((DenemoStaff *) Denemo.project->movement->currentstaff->data);
3338 free (accs);
3339 displayhelper (Denemo.project); //score_status(Denemo.project, TRUE);
3340 return SCM_BOOL_T;
3341 }
3342
3343 SCM
scheme_increment_initial_keysig(SCM amount)3344 scheme_increment_initial_keysig (SCM amount)
3345 {
3346 DenemoStaff *curstaff = Denemo.project->movement->currentstaff->data;
3347 SCM ret = SCM_BOOL_F;
3348 gint inc = 1;
3349 if (scm_is_integer (amount))
3350 inc = scm_to_int (amount);
3351 keysig *sig = &curstaff->keysig;
3352 inc += sig->number;
3353 if (inc < 8 && inc > -8)
3354 {
3355 dnm_setinitialkeysig (curstaff, inc, curstaff->keysig.isminor);
3356 score_status (Denemo.project, TRUE);
3357 ret = SCM_BOOL_T;
3358 }
3359 return ret;
3360 }
3361
3362 SCM
scheme_increment_keysig(SCM amount)3363 scheme_increment_keysig (SCM amount)
3364 {
3365 DenemoStaff *curstaff = Denemo.project->movement->currentstaff->data;
3366 DenemoObject *curObj = NULL;
3367 SCM ret = SCM_BOOL_F;
3368 gint inc = 1;
3369 if (scm_is_integer (amount))
3370 inc = scm_to_int (amount);
3371 keysig *sig = &curstaff->keysig;
3372 if ((Denemo.project->movement->currentobject) && (curObj = Denemo.project->movement->currentobject->data) && (curObj->type == KEYSIG))
3373 {
3374 sig = curObj->object;
3375 }
3376
3377 inc += sig->number;
3378 if (inc < 8 && inc > -8)
3379 {
3380 if (sig == &curstaff->keysig)
3381 {
3382 dnm_setinitialkeysig (curstaff, inc, curstaff->keysig.isminor);
3383 }
3384 else
3385 {
3386 sig->number = inc;
3387 initkeyaccs (sig->accs, inc);
3388 set_basic_numticks (curObj);
3389 setpixelmin (curObj);
3390 }
3391 score_status (Denemo.project, TRUE);
3392 displayhelper (Denemo.project);
3393 ret = SCM_BOOL_T;
3394 }
3395 return ret;
3396 }
3397
3398 SCM
scheme_cursor_to_nth_note_height(SCM number)3399 scheme_cursor_to_nth_note_height (SCM number)
3400 {
3401 return SCM_BOOL (cursor_to_nth_note_height (scm_to_int(number) - 1));
3402 }
3403 SCM
scheme_cursor_to_next_note_height(void)3404 scheme_cursor_to_next_note_height (void)
3405 {
3406 return SCM_BOOL (cursor_to_next_note_height ());
3407 }
3408
3409 SCM
scheme_cursor_to_note(SCM lilyname)3410 scheme_cursor_to_note (SCM lilyname)
3411 {
3412 DenemoProject *gui = Denemo.project;
3413 gint mid_c_offset;
3414 gint enshift;
3415 char *notename;
3416
3417 if (scm_is_string (lilyname))
3418 {
3419 notename = scm_to_locale_string (lilyname);
3420 interpret_lilypond_notename (notename, &mid_c_offset, &enshift);
3421 gui->movement->cursor_y = mid_c_offset;
3422 gui->movement->staffletter_y = offsettonumber (gui->movement->cursor_y);
3423 displayhelper (gui);
3424 if (notename)
3425 free (notename);
3426 return SCM_BOOL (TRUE);
3427 }
3428 else
3429 {
3430 return SCM_BOOL (FALSE);
3431 }
3432 }
3433
3434 SCM
scheme_change_chord_notes(SCM lilynotes)3435 scheme_change_chord_notes (SCM lilynotes)
3436 {
3437 DenemoProject *gui = Denemo.project;
3438 DenemoObject *curObj;
3439 chord *thechord;
3440 note *thenote;
3441 char *notename;
3442 gchar *chordnote;
3443 gint mid_c_offset;
3444 gint enshift;
3445 gint dclef;
3446 GList *g = NULL;
3447 GList *n = NULL;
3448 GList *directives = NULL;
3449
3450 if (scm_is_string (lilynotes))
3451 {
3452
3453 if (!Denemo.project || !(Denemo.project->movement) || !(Denemo.project->movement->currentobject) || !(curObj = Denemo.project->movement->currentobject->data) || (curObj->type != CHORD) || !(thechord = (chord *) curObj->object) || !(thechord->notes) || !(thenote = (note *) thechord->notes->data))
3454 return SCM_BOOL (FALSE);
3455
3456 else
3457 {
3458 /* delete all chord tones */
3459 while (thechord->notes)
3460 {
3461 thenote = thechord->notes->data;
3462 g = g_list_append (g, thenote->directives);
3463 thenote->directives = NULL;
3464 delete_chordnote (gui);
3465 }
3466 /* add changed tones */
3467 dclef = find_prevailing_clef (Denemo.project->movement);
3468 notename = scm_to_locale_string (lilynotes);
3469 chordnote = strtok (notename, " ");
3470 while (chordnote)
3471 {
3472 interpret_lilypond_notename (chordnote, &mid_c_offset, &enshift);
3473 dnm_addtone (curObj, mid_c_offset, enshift);
3474 chordnote = strtok (NULL, " ");
3475 }
3476 /* paste directives over */
3477 for (n = thechord->notes; n && g; n = n->next, g = g->next)
3478 {
3479 thenote = (note *) n->data;
3480 directives = (GList *) g->data;
3481
3482 if (directives)
3483 thenote->directives = directives;
3484
3485 }
3486 score_status (gui, TRUE);
3487 displayhelper (gui);
3488 if (notename)
3489 free (notename);
3490 return SCM_BOOL (TRUE);
3491 }
3492 }
3493 else
3494 return SCM_BOOL (FALSE);
3495 }
3496
3497 SCM
scheme_get_user_input(SCM label,SCM prompt,SCM init,SCM modal)3498 scheme_get_user_input (SCM label, SCM prompt, SCM init, SCM modal)
3499 {
3500 char *title, *instruction, *initial_value;
3501
3502 if (scm_is_string (label))
3503 {
3504 title = scm_to_locale_string (label);
3505 }
3506 else
3507 title = strdup ("Input Required");
3508 if (scm_is_string (prompt))
3509 {
3510 instruction = scm_to_locale_string (prompt);
3511 }
3512 else
3513 instruction = strdup ("Give input: ");
3514
3515 if (scm_is_string (init))
3516 {
3517 initial_value = scm_to_locale_string (init);
3518 }
3519 else
3520 initial_value = strdup (" ");
3521
3522 gchar *ret = string_dialog_entry_with_widget_opt (Denemo.project, title, instruction, initial_value, NULL, (modal == SCM_UNDEFINED) || scm_is_true (modal));
3523 SCM scm = ret ? scm_from_locale_string (ret) : SCM_BOOL_F;
3524
3525 if (title)
3526 free (title);
3527 if (instruction)
3528 free (instruction);
3529 if (initial_value)
3530 free (initial_value);
3531 if (ret)
3532 g_free (ret);
3533 return scm;
3534 }
3535
3536
3537 SCM
scheme_get_user_input_with_snippets(SCM label,SCM prompt,SCM init,SCM modal)3538 scheme_get_user_input_with_snippets (SCM label, SCM prompt, SCM init, SCM modal)
3539 {
3540 char *title, *instruction, *initial_value;
3541 SCM scm;
3542 gboolean ismodal=FALSE, format=FALSE;
3543 if (scm_is_string (modal))
3544 {
3545 char *arg = scm_to_locale_string (modal);
3546 if (!strcmp (arg, "format"))
3547 ismodal = format = TRUE;
3548 else if (!strcmp (arg, "modal"))
3549 ismodal = TRUE, format = FALSE;
3550 //g_print ("setting from %s %d %d\n", arg, ismodal, format);
3551 free (arg);
3552 }
3553 else
3554 {
3555 ismodal = !scm_is_false (modal), format = (!scm_is_false (modal)) && (modal != SCM_UNDEFINED);
3556 }
3557 if (scm_is_string (label))
3558 {
3559 title = scm_to_locale_string (label);
3560 }
3561 else
3562 title = strdup (_("Input Required"));
3563 if (scm_is_string (prompt))
3564 {
3565 instruction = scm_to_locale_string (prompt);
3566 }
3567 else
3568 instruction = strdup (_("Give input: "));
3569
3570 if (scm_is_string (init))
3571 {
3572 initial_value = scm_to_locale_string (init);
3573 }
3574 else
3575 initial_value = strdup (" ");
3576 GString *text = g_string_new(""), *lilypond=g_string_new(""); // g_print ("Called with %d %d\n", ismodal, format);
3577 gboolean ok = get_user_markup (text, lilypond, title, instruction, initial_value, ismodal, format);
3578
3579 if (ok)
3580 {
3581 scm = scm_cons (scm_from_locale_string (text->str), scm_from_locale_string (lilypond->str));
3582 }
3583 else
3584 scm = SCM_BOOL_F;
3585
3586 if (title)
3587 free (title);
3588 if (instruction)
3589 free (instruction);
3590 if (initial_value)
3591 free (initial_value);
3592 g_string_free (text, TRUE);
3593 g_string_free (lilypond, TRUE);
3594
3595 return scm;
3596 }
3597
select_font(gchar * title)3598 static gchar *select_font(gchar *title)
3599 {
3600 gchar *fontname = NULL;
3601 GtkResponseType result;
3602
3603 GtkWidget *dialog =
3604 #if GTK_MAJOR_VERSION == 2
3605 gtk_font_selection_dialog_new(title);
3606 #else
3607 gtk_font_chooser_dialog_new (title, NULL);
3608 #endif
3609 result = gtk_dialog_run(GTK_DIALOG(dialog));
3610
3611 if (result == GTK_RESPONSE_OK || result == GTK_RESPONSE_APPLY)
3612 #if GTK_MAJOR_VERSION == 2
3613 fontname = gtk_font_selection_dialog_get_font_name(
3614 GTK_FONT_SELECTION_DIALOG(dialog));
3615 fontname = string_dialog_entry (Denemo.project, title, _("Please delete the font size and bold/italic indications,\nleaving just the font family name."), fontname);
3616 #else
3617 fontname = g_strdup(pango_font_family_get_name (gtk_font_chooser_get_font_family (GTK_FONT_CHOOSER(dialog))));
3618
3619
3620 #endif
3621 gtk_widget_destroy(dialog);
3622 return fontname;
3623 }
3624
3625 SCM
scheme_select_font(SCM text)3626 scheme_select_font (SCM text)
3627 {
3628 SCM ret = SCM_BOOL_F;
3629 gchar *title, *choice;
3630 if (scm_is_string (text))
3631 {
3632 title = scm_to_locale_string (text);
3633 }
3634 else
3635 title = strdup (_("Choose Font"));
3636 choice = select_font (title);
3637 if(choice)
3638 ret = scm_from_locale_string (choice);
3639 g_free(choice);
3640 return ret;
3641 }
3642
3643 #define GDOUBLE_TO_POINTER(x) (GINT_TO_POINTER((gint)(10000*x)))
3644 #define GPOINTER_TO_DOUBLE(x) (GPOINTER_TO_INT(x)/10000.0)
3645
select_color(gchar * title)3646 static GList *select_color (gchar *title)
3647 {
3648 GtkResponseType result;
3649 GList *ret = NULL;
3650 GtkWidget *dialog =
3651 #if GTK_MAJOR_VERSION == 2
3652 gtk_color_selection_dialog_new(title);
3653 #else
3654 gtk_color_chooser_dialog_new (title, NULL);
3655 #endif
3656 result = gtk_dialog_run(GTK_DIALOG(dialog));
3657
3658 if (result == GTK_RESPONSE_OK || result == GTK_RESPONSE_APPLY)
3659 {
3660 #if GTK_MAJOR_VERSION == 2
3661 GdkColor color;
3662 GtkColorSelection *colorsel = gtk_color_selection_dialog_get_color_selection (dialog);
3663 gtk_color_selection_get_current_color (colorsel, &color);
3664 ret = g_list_append (ret, GDOUBLE_TO_POINTER (color.red/65535.0));
3665 ret = g_list_append (ret, GDOUBLE_TO_POINTER (color.green/65535.0));
3666 ret = g_list_append (ret, GDOUBLE_TO_POINTER (color.blue/65535.0));
3667
3668 #else
3669 GdkRGBA color;
3670 gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER(dialog), &color);
3671 ret = g_list_append (ret, GDOUBLE_TO_POINTER (color.red));
3672 ret = g_list_append (ret, GDOUBLE_TO_POINTER (color.green));
3673 ret = g_list_append (ret, GDOUBLE_TO_POINTER (color.blue));
3674 #endif
3675 }
3676 gtk_widget_destroy(dialog);
3677 return ret;
3678 }
3679
3680 SCM
scheme_select_color(SCM text)3681 scheme_select_color (SCM text)
3682 {
3683 SCM ret = SCM_BOOL_F;
3684 gchar *title;
3685 GList *list;
3686 if (scm_is_string (text))
3687 {
3688 title = scm_to_locale_string (text);
3689 }
3690 else
3691 title = strdup (_("Choose Font"));
3692 list = select_color (title);
3693 if(list)
3694 {
3695 ret = scm_list_n (scm_from_double (GPOINTER_TO_DOUBLE(list->data)), scm_from_double (GPOINTER_TO_DOUBLE(list->next->data)), scm_from_double (GPOINTER_TO_DOUBLE(list->next->next->data)), SCM_UNDEFINED);
3696 g_list_free(list);
3697 }
3698 return ret;
3699 }
3700
3701 SCM
scheme_warningdialog(SCM msg)3702 scheme_warningdialog (SCM msg)
3703 {
3704 char *title;
3705 if (scm_is_string (msg))
3706 {
3707 title = scm_to_locale_string (msg);
3708 }
3709 else
3710 title = strdup ("Script generated warning");
3711
3712 warningdialog (title);
3713 if (title)
3714 free (title);
3715 return msg;
3716 }
3717
3718
info_response(GtkWidget * dialog,gint reponse_id,gchar * script)3719 static void info_response (GtkWidget *dialog, gint reponse_id, gchar *script)
3720 {
3721 if (script)
3722 call_out_to_guile (script);
3723 gtk_widget_destroy (dialog);
3724 }
3725
3726
3727 SCM
scheme_info_with_hook(SCM title,SCM hook)3728 scheme_info_with_hook (SCM title, SCM hook)
3729 {
3730 GtkWidget *dialog;
3731 gchar *msg = NULL, *script = NULL;
3732 if (scm_is_string (hook))
3733 script = scm_to_locale_string (hook);
3734 if (scm_is_string (title))
3735 msg = scm_to_locale_string (title);
3736 if (msg)
3737 {
3738 dialog = gtk_message_dialog_new (GTK_WINDOW (Denemo.window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, "%s", msg);
3739 #ifdef G_OS_WIN32
3740 gtk_window_set_resizable (GTK_WINDOW (dialog), TRUE); //needed on windows because of a bug, not all text can be seen.
3741 #endif
3742 g_signal_connect (dialog, "response", G_CALLBACK (info_response), script);
3743 gtk_window_set_transient_for (GTK_WINDOW(dialog), GTK_WINDOW(Denemo.window));
3744 gtk_window_set_keep_above (GTK_WINDOW (dialog), TRUE);
3745 gtk_widget_show_all (dialog);
3746 return SCM_BOOL_T;
3747 }
3748 return SCM_BOOL_F;
3749 }
3750
3751
3752
3753 SCM
scheme_infodialog(SCM msg,SCM noblock)3754 scheme_infodialog (SCM msg, SCM noblock)
3755 {
3756 char *title;
3757 gboolean modal = FALSE;
3758 if (scm_is_false (noblock))
3759 modal = TRUE;
3760 if (scm_is_string (msg))
3761 {
3762 title = scm_to_locale_string (msg);
3763 msg = SCM_BOOL (TRUE);
3764 }
3765 else
3766 {
3767 title = strdup (_("Script error, wrong parameter type to d-InfoDialog"));
3768 msg = SCM_BOOL (FALSE);
3769 }
3770 if (modal)
3771 {
3772 infowarningdialog (title, FALSE);
3773 } else
3774 {
3775 static GtkWidget *dialog;
3776 if (dialog)
3777 {
3778 gtk_widget_show (dialog);
3779 gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog), title);
3780 }
3781 else
3782 {
3783 dialog = infodialog (title);
3784 g_signal_connect (dialog, "delete-event", G_CALLBACK (gtk_widget_hide_on_delete), NULL);
3785 }
3786 if (*title)
3787 {
3788 gtk_widget_show (dialog);
3789 }
3790 else
3791 {
3792 gtk_widget_hide (dialog);
3793 }
3794 }
3795 if (title)
3796 free (title);
3797 return msg;
3798 }
3799
3800 SCM
scheme_progressbar(SCM msg)3801 scheme_progressbar (SCM msg)
3802 {
3803 char *title = NULL;
3804 if (scm_is_string (msg))
3805 {
3806 title = scm_to_locale_string (msg);
3807 progressbar (title, NULL);
3808 msg = SCM_BOOL (TRUE);
3809 }
3810 else
3811 msg = SCM_BOOL (FALSE);
3812 if (title)
3813 free (title);
3814 return msg;
3815 }
3816
3817 SCM
scheme_progressbar_stop(void)3818 scheme_progressbar_stop (void)
3819 {
3820 progressbar_stop ();
3821 return SCM_BOOL (TRUE);
3822 }
3823
3824 SCM
scheme_typeset_for_script(SCM thescript)3825 scheme_typeset_for_script (SCM thescript)
3826 {
3827 SCM ret = SCM_BOOL_F;
3828 #ifndef USE_EVINCE
3829 g_debug("This feature requires denemo to be built with evince");
3830 #else
3831 if (scm_is_string (thescript))
3832 {
3833 gchar *script = scm_to_locale_string (thescript);
3834 if (typeset_for_script (script))
3835 ret = SCM_BOOL_T;
3836 }
3837 #endif
3838 return ret;
3839 }
3840
3841 SCM
scheme_print_typeset_pdf(void)3842 scheme_print_typeset_pdf (void)
3843 {
3844 #ifndef USE_EVINCE
3845 g_debug("This feature requires denemo to be built with evince");
3846 return SCM_BOOL_F;
3847 #else
3848 return print_typeset_pdf ()? SCM_BOOL_F : SCM_BOOL_T;
3849 #endif
3850 }
scheme_continous_typsetting(void)3851 SCM scheme_continous_typsetting (void)
3852 {
3853 return SCM_BOOL (continuous_typesetting());
3854
3855 }
scheme_display_typeset_svg(SCM scaling,SCM part)3856 SCM scheme_display_typeset_svg (SCM scaling, SCM part)
3857 {
3858 if (!continuous_typesetting())
3859 {
3860 gdouble scale = 1.0;
3861 if (scm_is_real (scaling))
3862 scale = scm_to_double (scaling);
3863 display_svg (scale, scm_is_true (part));
3864 return SCM_BOOL_T;
3865 } else
3866 return SCM_BOOL_F;
3867 }
3868
3869 SCM
scheme_get_char(void)3870 scheme_get_char (void)
3871 {
3872
3873 GdkEventKey event;
3874 gboolean success = intercept_scorearea_keypress (&event);
3875 if (success)
3876 {
3877 gchar *str = g_strdup_printf ("%c", success ? event.keyval : 0);
3878 SCM scm = scm_from_locale_string (str);
3879 g_free (str);
3880 return scm;
3881 }
3882 else
3883 return SCM_BOOL (FALSE);
3884 }
3885
3886 SCM
scheme_get_keypress(void)3887 scheme_get_keypress (void)
3888 {
3889 GdkEventKey event;
3890 gboolean success = intercept_scorearea_keypress (&event);
3891 if (success)
3892 {
3893 gchar *str = dnm_accelerator_name (event.keyval, event.state);
3894 SCM scm = scm_from_locale_string (str);
3895 g_free (str);
3896 return scm;
3897 }
3898 else
3899 return SCM_BOOL (FALSE);
3900 }
3901
3902 /* get last keypress that successfully invoked a command */
3903 SCM
scheme_get_command_keypress(void)3904 scheme_get_command_keypress (void)
3905 {
3906 gchar *str = dnm_accelerator_name (Denemo.last_keyval, Denemo.last_keystate);
3907 SCM scm = scm_from_locale_string (str);
3908 g_free (str);
3909 return scm;
3910 }
3911
3912
3913
3914 SCM
scheme_get_command(void)3915 scheme_get_command (void)
3916 {
3917 GdkEventKey event;
3918 GString *name = g_string_new ("");
3919 gboolean success = intercept_scorearea_keypress (&event);
3920 if (success)
3921 {
3922 gint cmd = lookup_command_for_keyevent (&event);
3923 //g_debug("command %d for %x %x\n", cmd, event.keyval, event.state);
3924 if (cmd != -1)
3925 name = g_string_append (name, lookup_name_from_idx (Denemo.map, cmd)); //FIXME NULL?, memory leaks
3926 name = g_string_prepend (name, DENEMO_SCHEME_PREFIX);
3927 }
3928 SCM scm = success ? scm_from_locale_string (name->str) : SCM_BOOL (FALSE);
3929 g_string_free (name, TRUE);
3930 return scm;
3931 }
3932
3933
3934 gchar *
return_command(gchar * name,GdkEvent * event)3935 return_command (gchar * name, GdkEvent * event)
3936 {
3937 return name;
3938 }
3939
3940 /* listens for a shortcut and returns a command, or if keypresses are not shortcut returns #f */
3941 SCM
scheme_get_command_from_user(void)3942 scheme_get_command_from_user (void)
3943 {
3944
3945 GdkEventKey event;
3946
3947 if (intercept_scorearea_keypress (&event))
3948 {
3949 gchar *command = process_key_event (&event, &return_command);
3950 if (command == NULL)
3951 return SCM_BOOL_F;
3952 if (*command == 0)
3953 { //can be two-key shortcut
3954 if (intercept_scorearea_keypress (&event))
3955 {
3956 command = process_key_event (&event, &return_command);
3957 if (command == NULL)
3958 return SCM_BOOL_F;
3959 }
3960 else
3961 return SCM_BOOL_F;
3962 }
3963 write_status (Denemo.project);
3964 SCM scm = scm_from_locale_string (command); //command is from lookup_name_from... functions, do not free.
3965 return scm;
3966 }
3967 return SCM_BOOL_F;
3968 }
3969
3970
3971 /*UNUSED
3972 static void
3973 get_drag_offset (GtkWidget * dialog, gint response_id, GtkLabel * label)
3974 {
3975 g_object_set_data (G_OBJECT (dialog), "offset-response", (gpointer) (intptr_t) response_id);
3976 if (response_id < 0)
3977 gtk_main_quit ();
3978 gint offsetx, offsety;
3979 offsetx = (intptr_t) g_object_get_data (G_OBJECT (Denemo.printarea), "offsetx");
3980 offsety = (intptr_t) g_object_get_data (G_OBJECT (Denemo.printarea), "offsety");
3981 gchar *text = g_strdup_printf ("Offset now %d %d. Drag again in the print window to change\nOr click OK to apply the position shift", offsetx, offsety);
3982 gtk_label_set_text (label, text);
3983 g_free (text);
3984 }*/
3985
3986 static void
get_drag_pad(GtkWidget * dialog,gint response_id,GtkLabel * label)3987 get_drag_pad (GtkWidget * dialog, gint response_id, GtkLabel * label)
3988 {
3989 g_object_set_data (G_OBJECT (dialog), "pad-response", (gpointer) (intptr_t) response_id);
3990 if (response_id < 0)
3991 gtk_main_quit ();
3992 gint padding;
3993 padding = (intptr_t) g_object_get_data (G_OBJECT (Denemo.printarea), "padding");
3994 gchar *text = g_strdup_printf ("Padding now %d. Drag again in the print window to change\nOr click OK to apply the padding to the graphical object belonging to the directive", padding);
3995 gtk_label_set_text (label, text);
3996 g_free (text);
3997 }
3998
3999
4000
4001 /* return a string representing the relative font size the user wishes to use*/
4002 SCM
scheme_get_relative_font_size(void)4003 scheme_get_relative_font_size (void)
4004 {
4005 if (Denemo.printarea == NULL)
4006 return SCM_BOOL (FALSE);
4007 gchar *value = g_object_get_data (G_OBJECT (Denemo.printarea), "font-size");
4008 if (value)
4009 g_free (value);
4010 value = string_dialog_entry (Denemo.project, "Font Size", "Give a value (+/-) to adjust font size by", "0");
4011 if (!value)
4012 value = g_strdup ("0");
4013 gchar *clean = g_strdup_printf ("%d", atoi (value));
4014 g_free (value);
4015 g_object_set_data (G_OBJECT (Denemo.printarea), "font-size", (gpointer) clean);
4016 return scm_from_locale_stringn (clean, strlen (clean));
4017 }
4018
4019 void get_clipboard (GtkAction * action, DenemoScriptParam * param);
4020 /* return a string from the X selection */
4021 SCM
scheme_get_text_selection(void)4022 scheme_get_text_selection (void)
4023 {
4024 SCM ret;
4025 DenemoScriptParam param;
4026 get_clipboard (NULL, ¶m);
4027 if (param.status)
4028 {
4029 ret = scm_from_locale_stringn (param.string->str, param.string->len);
4030 g_string_free (param.string, TRUE);
4031 }
4032 else
4033 ret = SCM_BOOL (FALSE);
4034 return ret;
4035 }
4036
4037
4038
4039
4040
4041
4042 /* return a string representing the padding desired for some lilypond graphic
4043 or #f if no printarea or user cancels*/
4044 SCM
scheme_get_padding(void)4045 scheme_get_padding (void)
4046 {
4047 SCM ret;
4048 if (Denemo.printarea == NULL)
4049 return SCM_BOOL (FALSE);
4050 if (g_object_get_data (G_OBJECT (Denemo.printarea), "pad-dialog"))
4051 {
4052 warningdialog (_("Already in a padding dialog"));
4053 return SCM_BOOL_F;
4054 }
4055
4056 gint padding = (intptr_t) g_object_get_data (G_OBJECT (Denemo.printarea), "padding");
4057
4058 GtkWidget *dialog = gtk_dialog_new_with_buttons ("Select Padding in Print Window",
4059 GTK_WINDOW (Denemo.window),
4060 (GtkDialogFlags) (GTK_DIALOG_DESTROY_WITH_PARENT),
4061 _("_OK"), GTK_RESPONSE_ACCEPT,
4062 _("_Cancel"), GTK_RESPONSE_REJECT,
4063 NULL);
4064 g_object_set_data (G_OBJECT (Denemo.printarea), "pad-dialog", (gpointer) dialog);
4065 GtkWidget *vbox = gtk_vbox_new (FALSE, 8);
4066
4067 GtkWidget *content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
4068 gtk_container_add (GTK_CONTAINER (content_area), vbox);
4069
4070 gchar *text = g_strdup_printf ("Current padding is %d\nUse right click in print window to change this\nClick OK to apply the padding to the music item drawn by the directive", padding);
4071 GtkWidget *label = gtk_label_new (text);
4072 g_free (text);
4073 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, TRUE, 0);
4074 gtk_widget_show_all (dialog);
4075
4076 gint val;
4077
4078 g_signal_connect (dialog, "response", G_CALLBACK (get_drag_pad), label);
4079 gtk_widget_show_all (dialog);
4080 gtk_main ();
4081 padding = (intptr_t) g_object_get_data (G_OBJECT (Denemo.printarea), "padding");
4082 val = (intptr_t) g_object_get_data (G_OBJECT (dialog), "pad-response");
4083 g_object_set_data (G_OBJECT (Denemo.printarea), "pad-dialog", NULL);
4084 gtk_widget_destroy (dialog);
4085 if (val == GTK_RESPONSE_ACCEPT)
4086 {
4087 gchar *pad = g_strdup_printf ("%d", padding / 10);
4088 ret = scm_from_locale_string (pad);
4089 g_free (pad);
4090 }
4091 else
4092 ret = SCM_BOOL (FALSE);
4093 return ret;
4094 }
4095
4096
4097
4098 /* create a dialog with the options & return the one chosen, of #f if
4099 the user cancels
4100 */
4101 SCM
scheme_get_option(SCM options,SCM title)4102 scheme_get_option (SCM options, SCM title)
4103 {
4104 gchar *response = NULL;
4105 size_t length;
4106 gchar *thetitle = NULL;
4107 //gchar *str=NULL;
4108 if (scm_is_string (title))
4109 thetitle = scm_to_locale_string (title);
4110
4111 if (scm_is_string (options))
4112 {
4113 char *str_unterm;
4114 str_unterm = scm_to_locale_stringn (options, &length);
4115 response = get_option (thetitle, str_unterm, length); //returns NULL or a pointer to a location in str_unterm
4116 //g_debug("Got %p holding %s\n", response, response);
4117 if (response)
4118 response = g_strdup (response);
4119 if (str_unterm)
4120 free (str_unterm);
4121 }
4122 if (response)
4123 {
4124 SCM ret = scm_from_locale_stringn (response, strlen (response));
4125 //g_debug("Freeing %p holding %s\n", response, response);
4126 g_free (response); //FIXME the g_strdup above is not needed?
4127 return ret;
4128 //return scm_from_locale_stringn (response, strlen(response));
4129 }
4130 else
4131 {
4132 return SCM_BOOL_F;
4133 }
4134 }
4135
4136
4137 /* Scheme interface to DenemoDirectives (formerly LilyPond directives attached to notes/chords) */
4138
4139
4140 SCM
scheme_lock_directive(SCM lock)4141 scheme_lock_directive (SCM lock)
4142 {
4143 DenemoObject *curObj;
4144 DenemoDirective *directive;
4145 if (!Denemo.project || !(Denemo.project->movement) || !(Denemo.project->movement->currentobject) || !(curObj = Denemo.project->movement->currentobject->data) || (curObj->type != LILYDIRECTIVE) || !(directive = (DenemoDirective *) curObj->object))
4146 return SCM_BOOL (FALSE);
4147 directive->locked = scm_is_true (lock);
4148 return SCM_BOOL_T;
4149 }
4150
4151
4152 /* store the script to be invoked as an action for a directive tagged with tag */
4153 SCM
scheme_set_action_script_for_tag(SCM tag,SCM script)4154 scheme_set_action_script_for_tag (SCM tag, SCM script)
4155 {
4156 if (scm_is_string (tag))
4157 {
4158 char *the_tag;
4159 the_tag = scm_to_locale_string (tag);
4160 if (scm_is_string (script))
4161 {
4162 char *the_script;
4163 the_script = scm_to_locale_string (script);
4164 gchar *stored_script = g_strdup (the_script); //FIXME
4165 free (the_script);
4166 set_action_script_for_tag (the_tag, stored_script);
4167 if (the_tag)
4168 free (the_tag);
4169 return SCM_BOOL (TRUE);
4170 }
4171 if (the_tag)
4172 free (the_tag);
4173 }
4174 return SCM_BOOL (FALSE);
4175 }
4176
4177 SCM
scheme_put_standalone_directive(SCM tag,SCM width)4178 scheme_put_standalone_directive (SCM tag, SCM width)
4179 {
4180 if (scm_is_string (tag))
4181 {
4182 char *the_tag;
4183 gint pixelwidth = 40;
4184 if(scm_is_integer (width))
4185 pixelwidth = scm_to_int (width);
4186 the_tag = scm_to_locale_string (tag);
4187 put_standalone_directive (the_tag, pixelwidth);
4188 if (the_tag)
4189 free (the_tag);
4190 return SCM_BOOL_T;
4191 }
4192 return SCM_BOOL_F;
4193 }
4194
4195 SCM
scheme_choose_tag_at_cursor(void)4196 scheme_choose_tag_at_cursor (void)
4197 {
4198 DenemoObject *curObj;
4199 if (!Denemo.project || !(Denemo.project->movement) || !(Denemo.project->movement->currentobject) || !(curObj = Denemo.project->movement->currentobject->data))
4200 return SCM_BOOL_F;
4201 gchar *tag;
4202 gboolean is_note = choose_tag_at_cursor (&tag);
4203 if (tag)
4204 {
4205 if (curObj->type == CHORD)
4206 return scm_cons (scm_from_locale_string (tag), scm_from_bool (is_note));
4207 else
4208 return scm_from_locale_string (tag);
4209 }
4210 return SCM_BOOL_F;
4211 }
4212
4213
4214 SCM
scheme_directive_change_tag(SCM tag)4215 scheme_directive_change_tag (SCM tag)
4216 { DenemoObject *curObj;
4217 if(scm_is_string (tag)) {
4218 gchar *thetag = scm_to_locale_string (tag);
4219 DenemoDirective *directive;
4220 if (!Denemo.project || !(Denemo.project->movement) || !(Denemo.project->movement->currentobject) || !(curObj = Denemo.project->movement->currentobject->data) || (curObj->type != LILYDIRECTIVE) || !(directive = (DenemoDirective *) curObj->object))
4221 return SCM_BOOL (FALSE);
4222 if(directive->tag==NULL) directive->tag = g_string_new("");
4223 g_string_assign (directive->tag, thetag);
4224 g_free(thetag);
4225 return SCM_BOOL_T;
4226 }
4227 return SCM_BOOL_F;
4228 }
4229 #define GET_NTH_TAG(what)\
4230 SCM scheme_##what##_directive_get_nth_tag(SCM index) {\
4231 gint n;\
4232 if(!scm_is_integer(index))\
4233 return SCM_BOOL_F;\
4234 n = scm_to_int(index);\
4235 extern gchar *get_nth_##what##_tag (gint n);\
4236 gchar *val = get_nth_##what##_tag (n);\
4237 if(val) return scm_from_locale_stringn (val, strlen(val));\
4238 return SCM_BOOL_F;\
4239 }
4240 GET_NTH_TAG (chord);
4241 GET_NTH_TAG (note);
4242 GET_NTH_TAG (staff);
4243 GET_NTH_TAG (voice);
4244 GET_NTH_TAG (score);
4245 GET_NTH_TAG (clef);
4246 GET_NTH_TAG (timesig);
4247 GET_NTH_TAG (tuplet);
4248 GET_NTH_TAG (stemdirective);
4249 GET_NTH_TAG (keysig);
4250 GET_NTH_TAG (scoreheader);
4251 GET_NTH_TAG (header);
4252 GET_NTH_TAG (paper);
4253 GET_NTH_TAG (layout);
4254 GET_NTH_TAG (movementcontrol);
4255 #undef GET_NTH_TAG
4256
4257 #define PRIORITIZE_TAG(what)\
4258 SCM scheme_##what##_directive_prioritize_tag(SCM name) {\
4259 gchar *tag;\
4260 if(!scm_is_string(name))\
4261 return SCM_BOOL_F;\
4262 tag = scm_to_locale_string (name);\
4263 extern gboolean prioritize_##what##_tag (gchar *name);\
4264 gboolean val = prioritize_##what##_tag (tag);\
4265 if(val) return name;\
4266 return SCM_BOOL_F;\
4267 }
4268 PRIORITIZE_TAG (chord);
4269 PRIORITIZE_TAG (note);
4270 PRIORITIZE_TAG (staff);
4271 PRIORITIZE_TAG (voice);
4272 PRIORITIZE_TAG (score);
4273 PRIORITIZE_TAG (clef);
4274 PRIORITIZE_TAG (timesig);
4275 PRIORITIZE_TAG (tuplet);
4276 PRIORITIZE_TAG (stemdirective);
4277 PRIORITIZE_TAG (keysig);
4278 PRIORITIZE_TAG (scoreheader);
4279 PRIORITIZE_TAG (header);
4280 PRIORITIZE_TAG (paper);
4281 PRIORITIZE_TAG (layout);
4282 PRIORITIZE_TAG (movementcontrol);
4283 #undef PRIORITIZE_TAG
4284
4285
scheme_edit_system_directive(void)4286 SCM scheme_edit_system_directive (void)
4287 {
4288 edit_system_directive ();
4289 return SCM_BOOL_T;
4290 }
4291
scheme_display_directive_text_editor(SCM type,SCM tagname)4292 SCM scheme_display_directive_text_editor (SCM type, SCM tagname) {
4293 if(scm_is_string (type) && scm_is_string (tagname))
4294 {
4295 gchar *what = scm_to_locale_string (type);
4296 gchar *tag = scm_to_locale_string (tagname);
4297 DenemoDirective *directive;
4298 if (!strcmp (what, "score"))
4299 directive = get_score_directive (tag);
4300 else
4301 directive = get_movementcontrol_directive (tag); //others - note, chord ...
4302
4303 if (directive && directive->override & DENEMO_OVERRIDE_EDITOR)
4304 {
4305 GtkWidget *texteditor = (GtkWidget *) g_object_get_data (G_OBJECT (directive->widget), DENEMO_TEXTEDITOR_TAG);
4306 if (texteditor)
4307 {
4308 gtk_widget_show_all (gtk_widget_get_toplevel (texteditor));
4309 gtk_window_present (GTK_WINDOW (gtk_widget_get_toplevel (texteditor)));
4310 }
4311 return SCM_BOOL_T;
4312 }
4313 }
4314 return SCM_BOOL_F;
4315 }
4316
4317 //only retrieve directives when cursor is actually on the note
scheme_directive_get_nth_tag_strict_note(SCM index)4318 SCM scheme_directive_get_nth_tag_strict_note(SCM index) {
4319 gint n;
4320 if(!scm_is_integer(index))
4321 return SCM_BOOL_F;
4322 n = scm_to_int(index);
4323 gchar *val = get_nth_strict_note_tag (n);
4324 if(val) return scm_from_locale_stringn (val, strlen(val));
4325 return SCM_BOOL_F;
4326 }
4327
scheme_directive_get_for_tag_strict_note(SCM tagname)4328 SCM scheme_directive_get_for_tag_strict_note (SCM tagname)
4329 {
4330 SCM ret = SCM_BOOL_F;
4331 const gchar *tag = NULL;
4332 if( scm_is_string (tagname))
4333 tag = scm_to_locale_string (tagname);
4334 tag = strict_note_directive_get_tag ((gchar *)tag);
4335 if (tag)
4336 ret = scm_from_locale_string (tag);
4337 return ret;
4338 }
4339 #define GET_TAG_FN_DEF(what)\
4340 SCM scheme_##what##_directive_get_tag(SCM tag) {\
4341 char *tagname;\
4342 if(!scm_is_string(tag))\
4343 tagname = NULL;\
4344 else { \
4345 tagname = scm_to_locale_string(tag);\
4346 } \
4347 extern gchar *what##_directive_get_tag (gchar *tagname);\
4348 gchar *val = (gchar*)what##_directive_get_tag ((gchar*)tagname);\
4349 if(val){\
4350 SCM ret = scm_from_locale_stringn (val, strlen(val));\
4351 if(tagname) free(tagname);\
4352 return ret;\
4353 }\
4354 if(tagname) free(tagname);\
4355 return SCM_BOOL(FALSE);\
4356 }
4357
4358 GET_TAG_FN_DEF (object);
4359 GET_TAG_FN_DEF (standalone);
4360 GET_TAG_FN_DEF (chord);
4361 GET_TAG_FN_DEF (note);
4362 GET_TAG_FN_DEF (staff);
4363 GET_TAG_FN_DEF (voice);
4364 GET_TAG_FN_DEF (score);
4365 GET_TAG_FN_DEF (clef);
4366 GET_TAG_FN_DEF (timesig);
4367 GET_TAG_FN_DEF (tuplet);
4368 GET_TAG_FN_DEF (stemdirective);
4369 GET_TAG_FN_DEF (keysig);
4370 GET_TAG_FN_DEF (scoreheader);
4371 GET_TAG_FN_DEF (header);
4372 GET_TAG_FN_DEF (paper);
4373 GET_TAG_FN_DEF (layout);
4374 GET_TAG_FN_DEF (movementcontrol);
4375 #undef GET_TAG_FN_DEF
4376 #define ACTIVATE_FN_DEF(what)\
4377 SCM scheme_activate_##what##_directive(SCM tag) {\
4378 if(!scm_is_string(tag)){\
4379 return SCM_BOOL(FALSE);\
4380 }\
4381 char *tagname;\
4382 tagname = scm_to_locale_string(tag);\
4383 extern gboolean activate_##what##_directive (gchar *tagname);\
4384 gboolean ret = activate_##what##_directive (tagname);\
4385 if(tagname) g_free(tagname);\
4386 return SCM_BOOL(ret);\
4387 }
4388
4389 #define EDIT_FN_DEF(what)\
4390 SCM scheme_text_edit_##what##_directive(SCM tag) {\
4391 if(!scm_is_string(tag)){\
4392 return SCM_BOOL(text_edit_##what##_directive (NULL));\
4393 }\
4394 char *tagname;\
4395 tagname = scm_to_locale_string(tag);\
4396 extern gboolean text_edit_##what##_directive (gchar *tagname);\
4397 gboolean ret = text_edit_##what##_directive (tagname);\
4398 if(tagname) g_free(tagname);\
4399 return SCM_BOOL(ret);\
4400 }
4401 #define DELETE_FN_DEF(what)\
4402 SCM scheme_delete_##what##_directive(SCM tag) {\
4403 if(!scm_is_string(tag)){\
4404 return SCM_BOOL(FALSE);\
4405 }\
4406 char *tagname;\
4407 tagname = scm_to_locale_string(tag);\
4408 extern gboolean delete_##what##_directive (gchar *tagname);\
4409 gboolean ret = delete_##what##_directive (tagname);\
4410 if(tagname) free(tagname);\
4411 return SCM_BOOL(ret);\
4412 }
4413 #define EDIT_DELETE_FN_DEF(what)\
4414 EDIT_FN_DEF(what)\
4415 DELETE_FN_DEF(what)\
4416 ACTIVATE_FN_DEF(what)
4417
4418 EDIT_FN_DEF (standalone) EDIT_DELETE_FN_DEF (note) EDIT_DELETE_FN_DEF (chord) EDIT_DELETE_FN_DEF (staff) EDIT_DELETE_FN_DEF (voice) EDIT_DELETE_FN_DEF (score)
4419 #define GETFUNC_DEF(what, field)\
4420 SCM scheme_##what##_directive_get_##field(SCM tag) {\
4421 if(!scm_is_string(tag)){\
4422 return SCM_BOOL(FALSE);\
4423 }\
4424 char *tagname;\
4425 tagname = scm_to_locale_string(tag);\
4426 extern gchar* what##_directive_get_##field(gchar *tagname);\
4427 gchar *value = (gchar*)what##_directive_get_##field((gchar*)tagname);\
4428 if(tagname) free(tagname);\
4429 if(value && *value){\
4430 return scm_from_locale_string(value);\
4431 }\
4432 return SCM_BOOL(FALSE);\
4433 }
4434 #define PUTFUNC_DEF(what, field)\
4435 SCM scheme_##what##_directive_put_##field(SCM tag, SCM value) {\
4436 if((!scm_is_string(tag))||(!scm_is_string(value)))\
4437 return SCM_BOOL(FALSE);\
4438 char *tagname;\
4439 tagname = scm_to_locale_string(tag);\
4440 char *valuename;\
4441 valuename = scm_to_locale_string(value);\
4442 extern gboolean what##_directive_put_##field (gchar *tagname, gchar *valuename);\
4443 gboolean ret = what##_directive_put_##field ((gchar*)tagname, (gchar*)valuename);\
4444 if(tagname) free(tagname);\
4445 if(valuename) free(valuename);\
4446 return SCM_BOOL(ret);\
4447 }
4448 //block to clone for new GString entries in DenemoDirective
4449 GETFUNC_DEF (note, display);
4450 GETFUNC_DEF (chord, display);
4451 GETFUNC_DEF (standalone, display);
4452 GETFUNC_DEF (staff, display);
4453 GETFUNC_DEF (voice, display);
4454 GETFUNC_DEF (score, display);
4455 GETFUNC_DEF (movementcontrol, display);
4456 PUTFUNC_DEF (note, display);
4457 PUTFUNC_DEF (chord, display);
4458 PUTFUNC_DEF (standalone, display);
4459 PUTFUNC_DEF (staff, display);
4460 PUTFUNC_DEF (voice, display);
4461 PUTFUNC_DEF (score, display);
4462 PUTFUNC_DEF (movementcontrol, display);
4463 // end of block to clone ??? there are now stem tuplet and keysigs as well - see grob
4464 GETFUNC_DEF (note, grob);
4465 GETFUNC_DEF (chord, grob);
4466 GETFUNC_DEF (standalone, grob);
4467 GETFUNC_DEF (staff, grob);
4468 GETFUNC_DEF (voice, grob);
4469 GETFUNC_DEF (score, grob);
4470 /*UNUSED
4471 GETFUNC_DEF (movementcontrol, grob);
4472 */
4473 GETFUNC_DEF (clef, grob);
4474 GETFUNC_DEF (timesig, grob);
4475 GETFUNC_DEF (tuplet, grob);
4476 GETFUNC_DEF (stemdirective, grob);
4477 GETFUNC_DEF (keysig, grob);
4478 PUTFUNC_DEF (note, grob);
4479 PUTFUNC_DEF (chord, grob);
4480 PUTFUNC_DEF (standalone, grob);
4481 //PUTFUNC_DEF(staff, grob)
4482 //PUTFUNC_DEF(voice, grob)
4483 PUTFUNC_DEF (score, grob)
4484 //PUTFUNC_DEF(movementcontrol, grob)
4485 PUTFUNC_DEF (clef, grob)
4486 PUTFUNC_DEF (timesig, grob)
4487 PUTFUNC_DEF (tuplet, grob)
4488 PUTFUNC_DEF (stemdirective, grob)
4489 PUTFUNC_DEF (keysig, grob)
4490
4491
4492
4493 GETFUNC_DEF (note, data);
4494 GETFUNC_DEF (chord, data);
4495 GETFUNC_DEF (standalone, data);
4496 GETFUNC_DEF (staff, data);
4497 GETFUNC_DEF (voice, data);
4498 GETFUNC_DEF (score, data);
4499 GETFUNC_DEF (scoreheader, data);
4500 GETFUNC_DEF (header, data);
4501 GETFUNC_DEF (paper, data);
4502 GETFUNC_DEF (layout, data);
4503 GETFUNC_DEF (movementcontrol, data);
4504 GETFUNC_DEF (clef, data);
4505 GETFUNC_DEF (timesig, data);
4506 GETFUNC_DEF (tuplet, data);
4507 GETFUNC_DEF (stemdirective, data);
4508 GETFUNC_DEF (keysig, data);
4509 PUTFUNC_DEF (note, data);
4510 PUTFUNC_DEF (chord, data);
4511 PUTFUNC_DEF (standalone, data);
4512 PUTFUNC_DEF(staff, data)
4513 PUTFUNC_DEF(voice, data)
4514 PUTFUNC_DEF (score, data)
4515 PUTFUNC_DEF (scoreheader, data)
4516 PUTFUNC_DEF (header, data)
4517 PUTFUNC_DEF (paper, data)
4518 PUTFUNC_DEF (layout, data)
4519 PUTFUNC_DEF(movementcontrol, data)
4520 PUTFUNC_DEF (clef, data)
4521 PUTFUNC_DEF (timesig, data)
4522 PUTFUNC_DEF (tuplet, data)
4523 PUTFUNC_DEF (stemdirective, data)
4524 PUTFUNC_DEF (keysig, data)
4525
4526
4527 GETFUNC_DEF (note, midibytes)
4528 GETFUNC_DEF (chord, midibytes)
4529 GETFUNC_DEF (standalone, midibytes)
4530 GETFUNC_DEF (staff, midibytes)
4531 GETFUNC_DEF (voice, midibytes)
4532 GETFUNC_DEF (score, midibytes)
4533 GETFUNC_DEF (movementcontrol, midibytes)
4534 PUTFUNC_DEF (note, midibytes)
4535 PUTFUNC_DEF (chord, midibytes)
4536 PUTFUNC_DEF (standalone, midibytes)
4537 PUTFUNC_DEF (staff, midibytes)
4538 PUTFUNC_DEF (voice, midibytes)
4539 PUTFUNC_DEF (score, midibytes)
4540 PUTFUNC_DEF (movementcontrol, midibytes)
4541 GETFUNC_DEF (note, prefix)
4542 GETFUNC_DEF (note, postfix)
4543 PUTFUNC_DEF (note, prefix)
4544 //PUTFUNC_DEF(clef, prefix)
4545 PUTFUNC_DEF (note, postfix)
4546 GETFUNC_DEF (score, prefix)
4547 GETFUNC_DEF (score, postfix)
4548 PUTFUNC_DEF (score, prefix)
4549 PUTFUNC_DEF (score, postfix)
4550 PUTFUNC_DEF (staff, prefix)
4551 PUTFUNC_DEF (voice, prefix)
4552 GETFUNC_DEF (staff, prefix)
4553 GETFUNC_DEF (voice, prefix)
4554 PUTFUNC_DEF (staff, postfix)
4555 PUTFUNC_DEF (voice, postfix)
4556 GETFUNC_DEF (staff, postfix)
4557 GETFUNC_DEF (voice, postfix)
4558 GETFUNC_DEF (chord, prefix)
4559 GETFUNC_DEF (chord, postfix)
4560 PUTFUNC_DEF (chord, prefix)
4561 PUTFUNC_DEF (chord, postfix)
4562 GETFUNC_DEF (standalone, prefix)
4563 GETFUNC_DEF (standalone, postfix)
4564 PUTFUNC_DEF (standalone, prefix)
4565 PUTFUNC_DEF (standalone, postfix)
4566 #define INT_PUTFUNC_DEF(what, field)\
4567 SCM scheme_##what##_directive_put_##field(SCM tag, SCM value) {\
4568 if((!scm_is_string(tag))||(!scm_is_integer(value))){\
4569 return SCM_BOOL(FALSE);\
4570 }\
4571 char *tagname;\
4572 tagname = scm_to_locale_string(tag);\
4573 gint valuename = scm_to_int(value);\
4574 extern gboolean what##_directive_put_##field (gchar *tag, gint value);\
4575 gboolean ret = what##_directive_put_##field ((gchar*)tagname, valuename);\
4576 if(tagname) free(tagname);\
4577 return SCM_BOOL(ret);\
4578 }
4579 #define INT_GETFUNC_DEF(what, field)\
4580 SCM scheme_##what##_directive_get_##field(SCM tag) {\
4581 if(!scm_is_string(tag)){\
4582 return SCM_BOOL(FALSE);\
4583 }\
4584 char *tagname;\
4585 tagname = scm_to_locale_string(tag);\
4586 extern gint what##_directive_get_##field (gchar *tag);\
4587 gint ret = what##_directive_get_##field ((gchar*)tagname);\
4588 if(tagname) free(tagname);\
4589 return scm_from_int(ret);\
4590 }
4591 #define PUTGRAPHICFUNC_DEF(what)\
4592 SCM scheme_##what##_directive_put_graphic(SCM tag, SCM value) {\
4593 if((!scm_is_string(tag))||(!scm_is_string(value))){\
4594 return SCM_BOOL(FALSE);\
4595 }\
4596 char *tagname;\
4597 tagname = scm_to_locale_string(tag);\
4598 char *valuename;\
4599 valuename = scm_to_locale_string(value);\
4600 gboolean ret = what##_directive_put_graphic ((gchar*)tagname, (gchar*)valuename);\
4601 if(tagname) free(tagname);\
4602 if(valuename) free(valuename);\
4603 return SCM_BOOL(ret);\
4604 }
4605 PUTGRAPHICFUNC_DEF (note);
4606 PUTGRAPHICFUNC_DEF (chord);
4607 PUTGRAPHICFUNC_DEF (standalone);
4608 PUTGRAPHICFUNC_DEF (staff);
4609 PUTGRAPHICFUNC_DEF (voice);
4610 PUTGRAPHICFUNC_DEF (score);
4611
4612
4613 //block to copy for new int field in directive
4614 INT_PUTFUNC_DEF (note, minpixels)
4615 INT_PUTFUNC_DEF (chord, minpixels)
4616 INT_PUTFUNC_DEF (standalone, minpixels)
4617 INT_PUTFUNC_DEF (staff, minpixels)
4618 INT_PUTFUNC_DEF (voice, minpixels)
4619 INT_PUTFUNC_DEF (score, minpixels)
4620 INT_PUTFUNC_DEF (clef, minpixels)
4621 INT_PUTFUNC_DEF (timesig, minpixels)
4622 INT_PUTFUNC_DEF (tuplet, minpixels)
4623 INT_PUTFUNC_DEF (stemdirective, minpixels)
4624 INT_PUTFUNC_DEF (keysig, minpixels)
4625 INT_PUTFUNC_DEF (scoreheader, minpixels)
4626 INT_PUTFUNC_DEF (header, minpixels)
4627 INT_PUTFUNC_DEF (paper, minpixels)
4628 INT_PUTFUNC_DEF (layout, minpixels)
4629 INT_PUTFUNC_DEF (movementcontrol, minpixels)
4630 INT_GETFUNC_DEF (note, minpixels)
4631 INT_GETFUNC_DEF (chord, minpixels)
4632 INT_GETFUNC_DEF (standalone, minpixels)
4633 INT_GETFUNC_DEF (staff, minpixels) INT_GETFUNC_DEF (voice, minpixels) INT_GETFUNC_DEF (score, minpixels) INT_GETFUNC_DEF (clef, minpixels) INT_GETFUNC_DEF (timesig, minpixels) INT_GETFUNC_DEF (tuplet, minpixels) INT_GETFUNC_DEF (stemdirective, minpixels) INT_GETFUNC_DEF (keysig, minpixels) INT_GETFUNC_DEF (scoreheader, minpixels) INT_GETFUNC_DEF (header, minpixels) INT_GETFUNC_DEF (paper, minpixels) INT_GETFUNC_DEF (layout, minpixels) INT_GETFUNC_DEF (movementcontrol, minpixels)
4634 //end block to ocpy for new int field in directive
4635 INT_PUTFUNC_DEF (note, override)
4636 INT_PUTFUNC_DEF (chord, override)
4637 INT_PUTFUNC_DEF (standalone, override)
4638 INT_PUTFUNC_DEF (staff, override)
4639 INT_PUTFUNC_DEF (voice, override)
4640 INT_PUTFUNC_DEF (score, override)
4641 INT_GETFUNC_DEF (note, override)
4642 INT_GETFUNC_DEF (chord, override)
4643 INT_GETFUNC_DEF (standalone, override)
4644 INT_GETFUNC_DEF (staff, override)
4645 INT_GETFUNC_DEF (voice, override)
4646 INT_GETFUNC_DEF (score, override)
4647 INT_PUTFUNC_DEF (note, y)
4648 INT_PUTFUNC_DEF (chord, y)
4649 INT_PUTFUNC_DEF (standalone, y)
4650 INT_GETFUNC_DEF (note, y)
4651 INT_GETFUNC_DEF (chord, y)
4652 INT_GETFUNC_DEF (standalone, y)
4653 INT_PUTFUNC_DEF (note, x)
4654 INT_PUTFUNC_DEF (chord, x)
4655 INT_PUTFUNC_DEF (standalone, x)
4656 INT_GETFUNC_DEF (note, x)
4657 INT_GETFUNC_DEF (chord, x)
4658 INT_GETFUNC_DEF (standalone, x)
4659 INT_PUTFUNC_DEF (note, ty)
4660 INT_PUTFUNC_DEF (chord, ty)
4661 INT_PUTFUNC_DEF (standalone, ty)
4662 INT_GETFUNC_DEF (note, ty)
4663 INT_GETFUNC_DEF (chord, ty)
4664 INT_GETFUNC_DEF (standalone, ty)
4665 INT_PUTFUNC_DEF (note, tx)
4666 INT_PUTFUNC_DEF (chord, tx)
4667 INT_PUTFUNC_DEF (standalone, tx)
4668 INT_GETFUNC_DEF (note, tx)
4669 INT_GETFUNC_DEF (chord, tx)
4670 INT_GETFUNC_DEF (standalone, tx)
4671 INT_PUTFUNC_DEF (note, gy)
4672 INT_PUTFUNC_DEF (chord, gy)
4673 INT_PUTFUNC_DEF (standalone, gy)
4674 INT_GETFUNC_DEF (note, gy)
4675 INT_GETFUNC_DEF (chord, gy)
4676 INT_GETFUNC_DEF (standalone, gy)
4677 INT_PUTFUNC_DEF (note, gx)
4678 INT_PUTFUNC_DEF (chord, gx)
4679 INT_PUTFUNC_DEF (standalone, gx)
4680 INT_GETFUNC_DEF (note, gx)
4681 INT_GETFUNC_DEF (chord, gx)
4682 INT_GETFUNC_DEF (standalone, gx)
4683 INT_GETFUNC_DEF (note, width)
4684 INT_GETFUNC_DEF (chord, width)
4685 INT_GETFUNC_DEF (standalone, width)
4686 INT_GETFUNC_DEF (note, height)
4687 INT_GETFUNC_DEF (chord, height)
4688 INT_GETFUNC_DEF (standalone, height)
4689 INT_GETFUNC_DEF (score, x) INT_GETFUNC_DEF (score, y) INT_GETFUNC_DEF (score, tx) INT_GETFUNC_DEF (score, ty) INT_GETFUNC_DEF (score, gx) INT_GETFUNC_DEF (score, gy) INT_GETFUNC_DEF (score, width) INT_GETFUNC_DEF (score, height) INT_PUTFUNC_DEF (score, x) INT_PUTFUNC_DEF (score, y) INT_PUTFUNC_DEF (score, tx) INT_PUTFUNC_DEF (score, ty) INT_PUTFUNC_DEF (score, gx) INT_PUTFUNC_DEF (score, gy) INT_GETFUNC_DEF (object, minpixels) INT_PUTFUNC_DEF (object, minpixels) DELETE_FN_DEF (object)
4690 // block to copy for new type of directive, !!minpixels is done in block to copy for new fields!!
4691 GETFUNC_DEF (clef, prefix) GETFUNC_DEF (clef, postfix) GETFUNC_DEF (clef, display) PUTFUNC_DEF (clef, prefix) PUTFUNC_DEF (clef, postfix) PUTFUNC_DEF (clef, display) PUTGRAPHICFUNC_DEF (clef);
4692
4693 INT_PUTFUNC_DEF (clef, x) INT_PUTFUNC_DEF (clef, y) INT_PUTFUNC_DEF (clef, tx) INT_PUTFUNC_DEF (clef, ty) INT_PUTFUNC_DEF (clef, gx) INT_PUTFUNC_DEF (clef, gy) INT_PUTFUNC_DEF (clef, override) INT_GETFUNC_DEF (clef, x) INT_GETFUNC_DEF (clef, y) INT_GETFUNC_DEF (clef, tx) INT_GETFUNC_DEF (clef, ty) INT_GETFUNC_DEF (clef, gx) INT_GETFUNC_DEF (clef, gy) INT_GETFUNC_DEF (clef, override) INT_GETFUNC_DEF (clef, width) INT_GETFUNC_DEF (clef, height) EDIT_DELETE_FN_DEF (clef)
4694 // end block
4695 GETFUNC_DEF (timesig, prefix) GETFUNC_DEF (timesig, postfix) GETFUNC_DEF (timesig, display) PUTFUNC_DEF (timesig, prefix) PUTFUNC_DEF (timesig, postfix) PUTFUNC_DEF (timesig, display) PUTGRAPHICFUNC_DEF (timesig);
4696
4697 INT_PUTFUNC_DEF (timesig, x)
4698 INT_PUTFUNC_DEF (timesig, y)
4699 INT_PUTFUNC_DEF (timesig, tx)
4700 INT_PUTFUNC_DEF (timesig, ty)
4701 INT_PUTFUNC_DEF (timesig, gx)
4702 INT_PUTFUNC_DEF (timesig, gy)
4703 INT_PUTFUNC_DEF (timesig, override)
4704 INT_GETFUNC_DEF (timesig, x)
4705 INT_GETFUNC_DEF (timesig, y) INT_GETFUNC_DEF (timesig, tx) INT_GETFUNC_DEF (timesig, ty) INT_GETFUNC_DEF (timesig, gx) INT_GETFUNC_DEF (timesig, gy) INT_GETFUNC_DEF (timesig, override) INT_GETFUNC_DEF (timesig, width) INT_GETFUNC_DEF (timesig, height) EDIT_DELETE_FN_DEF (timesig) GETFUNC_DEF (tuplet, prefix) GETFUNC_DEF (tuplet, postfix) GETFUNC_DEF (tuplet, display) PUTFUNC_DEF (tuplet, prefix) PUTFUNC_DEF (tuplet, postfix) PUTFUNC_DEF (tuplet, display) PUTGRAPHICFUNC_DEF (tuplet);
4706
4707 INT_PUTFUNC_DEF (tuplet, x)
4708 INT_PUTFUNC_DEF (tuplet, y)
4709 INT_PUTFUNC_DEF (tuplet, tx)
4710 INT_PUTFUNC_DEF (tuplet, ty)
4711 INT_PUTFUNC_DEF (tuplet, gx)
4712 INT_PUTFUNC_DEF (tuplet, gy)
4713 INT_PUTFUNC_DEF (tuplet, override)
4714 INT_GETFUNC_DEF (tuplet, x)
4715 INT_GETFUNC_DEF (tuplet, y)
4716 INT_GETFUNC_DEF (tuplet, tx) INT_GETFUNC_DEF (tuplet, ty) INT_GETFUNC_DEF (tuplet, gx) INT_GETFUNC_DEF (tuplet, gy) INT_GETFUNC_DEF (tuplet, override) INT_GETFUNC_DEF (tuplet, width) INT_GETFUNC_DEF (tuplet, height) EDIT_DELETE_FN_DEF (tuplet) GETFUNC_DEF (stemdirective, prefix) GETFUNC_DEF (stemdirective, postfix) GETFUNC_DEF (stemdirective, display) PUTFUNC_DEF (stemdirective, prefix) PUTFUNC_DEF (stemdirective, postfix) PUTFUNC_DEF (stemdirective, display) PUTGRAPHICFUNC_DEF (stemdirective);
4717
4718 INT_PUTFUNC_DEF (stemdirective, x)
4719 INT_PUTFUNC_DEF (stemdirective, y)
4720 INT_PUTFUNC_DEF (stemdirective, tx)
4721 INT_PUTFUNC_DEF (stemdirective, ty)
4722 INT_PUTFUNC_DEF (stemdirective, gx)
4723 INT_PUTFUNC_DEF (stemdirective, gy)
4724 INT_PUTFUNC_DEF (stemdirective, override)
4725 INT_GETFUNC_DEF (stemdirective, x)
4726 INT_GETFUNC_DEF (stemdirective, y)
4727 INT_GETFUNC_DEF (stemdirective, tx)
4728 INT_GETFUNC_DEF (stemdirective, ty) INT_GETFUNC_DEF (stemdirective, gx) INT_GETFUNC_DEF (stemdirective, gy) INT_GETFUNC_DEF (stemdirective, override) INT_GETFUNC_DEF (stemdirective, width) INT_GETFUNC_DEF (stemdirective, height) EDIT_DELETE_FN_DEF (stemdirective) GETFUNC_DEF (keysig, prefix) GETFUNC_DEF (keysig, postfix) GETFUNC_DEF (keysig, display) PUTFUNC_DEF (keysig, prefix) PUTFUNC_DEF (keysig, postfix) PUTFUNC_DEF (keysig, display) PUTGRAPHICFUNC_DEF (keysig);
4729
4730 INT_PUTFUNC_DEF (keysig, x)
4731 INT_PUTFUNC_DEF (keysig, y)
4732 INT_PUTFUNC_DEF (keysig, tx)
4733 INT_PUTFUNC_DEF (keysig, ty)
4734 INT_PUTFUNC_DEF (keysig, gx)
4735 INT_PUTFUNC_DEF (keysig, gy)
4736 INT_PUTFUNC_DEF (keysig, override)
4737 INT_GETFUNC_DEF (keysig, x)
4738 INT_GETFUNC_DEF (keysig, y)
4739 INT_GETFUNC_DEF (keysig, tx) INT_GETFUNC_DEF (keysig, ty) INT_GETFUNC_DEF (keysig, gx) INT_GETFUNC_DEF (keysig, gy) INT_GETFUNC_DEF (keysig, override) INT_GETFUNC_DEF (keysig, width) INT_GETFUNC_DEF (keysig, height) EDIT_DELETE_FN_DEF (keysig) GETFUNC_DEF (scoreheader, prefix) GETFUNC_DEF (scoreheader, postfix) GETFUNC_DEF (scoreheader, display) PUTFUNC_DEF (scoreheader, prefix) PUTFUNC_DEF (scoreheader, postfix) PUTFUNC_DEF (scoreheader, display) PUTGRAPHICFUNC_DEF (scoreheader);
4740
4741 INT_PUTFUNC_DEF (scoreheader, x)
4742 INT_PUTFUNC_DEF (scoreheader, y)
4743 INT_PUTFUNC_DEF (scoreheader, tx)
4744 INT_PUTFUNC_DEF (scoreheader, ty)
4745 INT_PUTFUNC_DEF (scoreheader, gx)
4746 INT_PUTFUNC_DEF (scoreheader, gy)
4747 INT_PUTFUNC_DEF (scoreheader, override)
4748 INT_GETFUNC_DEF (scoreheader, x)
4749 INT_GETFUNC_DEF (scoreheader, y)
4750 INT_GETFUNC_DEF (scoreheader, tx) INT_GETFUNC_DEF (scoreheader, ty) INT_GETFUNC_DEF (scoreheader, gx) INT_GETFUNC_DEF (scoreheader, gy) INT_GETFUNC_DEF (scoreheader, override) INT_GETFUNC_DEF (scoreheader, width) INT_GETFUNC_DEF (scoreheader, height) EDIT_DELETE_FN_DEF (scoreheader) GETFUNC_DEF (header, prefix) GETFUNC_DEF (header, postfix) GETFUNC_DEF (header, display) PUTFUNC_DEF (header, prefix) PUTFUNC_DEF (header, postfix) PUTFUNC_DEF (header, display) PUTGRAPHICFUNC_DEF (header);
4751
4752 INT_PUTFUNC_DEF (header, x)
4753 INT_PUTFUNC_DEF (header, y)
4754 INT_PUTFUNC_DEF (header, tx)
4755 INT_PUTFUNC_DEF (header, ty)
4756 INT_PUTFUNC_DEF (header, gx)
4757 INT_PUTFUNC_DEF (header, gy)
4758 INT_PUTFUNC_DEF (header, override)
4759 INT_GETFUNC_DEF (header, x)
4760 INT_GETFUNC_DEF (header, y)
4761 INT_GETFUNC_DEF (header, tx)
4762 INT_GETFUNC_DEF (header, ty)
4763 INT_GETFUNC_DEF (header, gx)
4764 INT_GETFUNC_DEF (header, gy)
4765 INT_GETFUNC_DEF (header, override)
4766 INT_GETFUNC_DEF (header, width)
4767 INT_GETFUNC_DEF (header, height)
4768 EDIT_DELETE_FN_DEF (header)
4769 GETFUNC_DEF (paper, prefix)
4770 GETFUNC_DEF (paper, postfix)
4771 GETFUNC_DEF (paper, display)
4772 PUTFUNC_DEF (paper, prefix)
4773 PUTFUNC_DEF (paper, postfix)
4774 PUTFUNC_DEF (paper, display)
4775 PUTGRAPHICFUNC_DEF (paper);
4776
4777 INT_PUTFUNC_DEF (paper, x)
4778 INT_PUTFUNC_DEF (paper, y)
4779 INT_PUTFUNC_DEF (paper, tx)
4780 INT_PUTFUNC_DEF (paper, ty)
4781 INT_PUTFUNC_DEF (paper, gx)
4782 INT_PUTFUNC_DEF (paper, gy)
4783 INT_PUTFUNC_DEF (paper, override)
4784 INT_GETFUNC_DEF (paper, x)
4785 INT_GETFUNC_DEF (paper, y)
4786 INT_GETFUNC_DEF (paper, tx)
4787 INT_GETFUNC_DEF (paper, ty)
4788 INT_GETFUNC_DEF (paper, gx)
4789 INT_GETFUNC_DEF (paper, gy)
4790 INT_GETFUNC_DEF (paper, override)
4791 INT_GETFUNC_DEF (paper, width)
4792 INT_GETFUNC_DEF (paper, height)
4793 EDIT_DELETE_FN_DEF (paper)
4794 GETFUNC_DEF (layout, prefix)
4795 GETFUNC_DEF (layout, postfix)
4796 GETFUNC_DEF (layout, display)
4797 PUTFUNC_DEF (layout, prefix)
4798 PUTFUNC_DEF (layout, postfix)
4799 PUTFUNC_DEF (layout, display)
4800 PUTGRAPHICFUNC_DEF (layout);
4801
4802 INT_PUTFUNC_DEF (layout, x)
4803 INT_PUTFUNC_DEF (layout, y)
4804 INT_PUTFUNC_DEF (layout, tx)
4805 INT_PUTFUNC_DEF (layout, ty)
4806 INT_PUTFUNC_DEF (layout, gx)
4807 INT_PUTFUNC_DEF (layout, gy)
4808 INT_PUTFUNC_DEF (layout, override)
4809 INT_GETFUNC_DEF (layout, x)
4810 INT_GETFUNC_DEF (layout, y)
4811 INT_GETFUNC_DEF (layout, tx)
4812 INT_GETFUNC_DEF (layout, ty)
4813 INT_GETFUNC_DEF (layout, gx)
4814 INT_GETFUNC_DEF (layout, gy)
4815 INT_GETFUNC_DEF (layout, override)
4816 INT_GETFUNC_DEF (layout, width)
4817 INT_GETFUNC_DEF (layout, height)
4818 EDIT_DELETE_FN_DEF (layout)
4819 GETFUNC_DEF (movementcontrol, prefix)
4820 GETFUNC_DEF (movementcontrol, postfix)
4821 PUTFUNC_DEF (movementcontrol, prefix)
4822 PUTFUNC_DEF (movementcontrol, postfix)
4823 PUTGRAPHICFUNC_DEF (movementcontrol);
4824
INT_PUTFUNC_DEF(movementcontrol,x)4825 INT_PUTFUNC_DEF (movementcontrol, x)
4826 INT_PUTFUNC_DEF (movementcontrol, y)
4827 INT_PUTFUNC_DEF (movementcontrol, tx)
4828 INT_PUTFUNC_DEF (movementcontrol, ty)
4829 INT_PUTFUNC_DEF (movementcontrol, gx)
4830 INT_PUTFUNC_DEF (movementcontrol, gy)
4831 INT_PUTFUNC_DEF (movementcontrol, override)
4832 INT_GETFUNC_DEF (movementcontrol, x)
4833 INT_GETFUNC_DEF (movementcontrol, y)
4834 INT_GETFUNC_DEF (movementcontrol, tx)
4835 INT_GETFUNC_DEF (movementcontrol, ty)
4836 INT_GETFUNC_DEF (movementcontrol, gx)
4837 INT_GETFUNC_DEF (movementcontrol, gy)
4838 INT_GETFUNC_DEF (movementcontrol, override)
4839 INT_GETFUNC_DEF (movementcontrol, width)
4840 INT_GETFUNC_DEF (movementcontrol, height)
4841 EDIT_DELETE_FN_DEF (movementcontrol)
4842
4843 SCM
4844 scheme_put_text_clipboard (SCM optional)
4845 {
4846 size_t length;
4847 char *str = NULL;
4848 if (scm_is_string (optional))
4849 {
4850 str = scm_to_locale_stringn (optional, &length);
4851 GtkClipboard *clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
4852 gtk_clipboard_set_text (clipboard, str, length);
4853 if (str)
4854 free (str);
4855 return SCM_BOOL (TRUE);
4856 }
4857 return SCM_BOOL (FALSE);
4858 }
4859
4860
4861
4862 SCM
scheme_get_username(void)4863 scheme_get_username (void)
4864 {
4865 return scm_from_locale_string (Denemo.prefs.username->str);
4866 }
4867
4868 SCM
scheme_get_password(void)4869 scheme_get_password (void)
4870 {
4871 return scm_from_locale_string (Denemo.prefs.password->str);
4872 }
4873
4874 SCM
scheme_set_midi_capture(SCM setting)4875 scheme_set_midi_capture (SCM setting)
4876 {
4877 gboolean prev;
4878 prev = set_midi_capture ((setting != SCM_BOOL_F));
4879 return prev ? SCM_BOOL_T : SCM_BOOL_F;
4880 }
4881
4882 SCM
scheme_get_keyboard_state(void)4883 scheme_get_keyboard_state (void)
4884 {
4885 return scm_from_int (Denemo.keyboard_state);
4886 }
4887
4888 SCM
scheme_set_midi_thru(SCM set)4889 scheme_set_midi_thru (SCM set) // see also d-MidiInListening this doesn't lock the state against keyboard changes
4890 {
4891 SCM ret = scm_from_int (Denemo.keyboard_state);
4892 if (scm_is_true (set))
4893 Denemo.keyboard_state = GDK_SHIFT_MASK;
4894 else
4895 Denemo.keyboard_state = 0;
4896 set_midi_in_status ();
4897 return ret;
4898 }
4899
4900 SCM
scheme_get_recorded_midi_on_tick(void)4901 scheme_get_recorded_midi_on_tick (void)
4902 {
4903 smf_track_t *track = Denemo.project->movement->recorded_midi_track;
4904 if (track)
4905 {
4906 #define MIDI_NOTEOFF 0x80
4907 #define MIDI_NOTEON 0x90
4908 smf_event_t *event = smf_track_get_next_event (track);
4909 if (event)
4910 switch (event->midi_buffer[0] & 0xF0)
4911 {
4912 case MIDI_NOTEON:
4913 return scm_from_int (event->time_pulses);
4914 case MIDI_NOTEOFF:
4915 return scm_from_int (-event->time_pulses);
4916 default:
4917 return SCM_BOOL_F;
4918 }
4919 }
4920 return SCM_BOOL_F;
4921 }
4922
4923 SCM
scheme_get_recorded_midi_note(void)4924 scheme_get_recorded_midi_note (void)
4925 {
4926 smf_track_t *track = Denemo.project->movement->recorded_midi_track;
4927 if (track)
4928 {
4929 smf_event_t *event = NULL;
4930 if (track->next_event_number > 0 && (track->next_event_number <= track->events_array->len))
4931 event = g_ptr_array_index (track->events_array, track->next_event_number - 1);
4932 if (event)
4933 switch (event->midi_buffer[0] & 0xF0)
4934 {
4935 case MIDI_NOTEON:
4936 case MIDI_NOTEOFF:
4937 return scm_from_int (event->midi_buffer[1]);
4938 default:
4939 return SCM_BOOL_F;
4940 }
4941 }
4942 return SCM_BOOL_F;
4943 }
4944
4945 SCM
scheme_rewind_recorded_midi(void)4946 scheme_rewind_recorded_midi (void)
4947 {
4948 smf_track_t *track = Denemo.project->movement->recorded_midi_track;
4949 if (track)
4950 {
4951 if (track->smf == NULL)
4952 {
4953 if (Denemo.project->movement->smf)
4954 {
4955 smf_add_track (Denemo.project->movement->smf, track);
4956 smf_rewind (Denemo.project->movement->smf);
4957 }
4958 else
4959 return SCM_BOOL_F;
4960 }
4961 smf_rewind (track->smf);
4962 return SCM_BOOL_T;
4963 }
4964 return SCM_BOOL_F;
4965 }
4966
4967 SCM
scheme_get_note_for_midi_key(SCM scm)4968 scheme_get_note_for_midi_key (SCM scm)
4969 {
4970 gint notenum = 0, offset, enshift, octave;
4971 if (scm_is_integer (scm))
4972 notenum = scm_to_int (scm);
4973 if (notenum > 0 && notenum < 256)
4974 {
4975 notenum2enharmonic (notenum, &offset, &enshift, &octave);
4976 gchar *name = mid_c_offsettolily (offset + 7 * octave, enshift);
4977 return scm_from_locale_string (name);
4978 }
4979 return SCM_BOOL_F;
4980 }
4981
4982 SCM
scheme_get_midi(SCM bytes)4983 scheme_get_midi (SCM bytes)
4984 {
4985 gint midi;
4986 SCM scm;
4987 gboolean success = intercept_midi_event (&midi);
4988 if (scm_is_false(bytes))
4989 {
4990 if (!success)
4991 scm = SCM_BOOL_F;
4992 else {
4993 Denemo.project->last_source = INPUTMIDI;
4994 scm = scm_list_n ( scm_from_int (midi&0xFF), scm_from_int ((midi>>8)&0xFF), scm_from_int ((midi>>16)&0xFF), scm_from_int (midi>>24), SCM_UNDEFINED);
4995 }
4996 } else {
4997 if (!success)
4998 midi = 0; /* scripts should detect this impossible value and take action */
4999 else
5000 Denemo.project->last_source = INPUTMIDI;
5001 gchar *buf = (gchar *) & midi;
5002 *buf &= 0xF0; //do not return channel info
5003
5004 scm = scm_from_int (midi);
5005 }
5006 return scm;
5007 }
5008
5009 //Simulates a midi event, with no capture by any calling scheme script unless midi==0
5010 SCM
scheme_put_midi(SCM scm)5011 scheme_put_midi (SCM scm)
5012 {
5013 gchar buf[3];
5014 gint midi;
5015 if (scm_is_list(scm))
5016 {
5017 buf[0] = scm_to_int (scm_list_ref (scm, scm_from_int(0)));
5018 buf[1] = scm_to_int (scm_list_ref (scm, scm_from_int(1)));
5019 buf[2] = scm_to_int (scm_list_ref (scm, scm_from_int(2)));
5020 midi = TRUE;
5021 } else
5022 {
5023 midi = scm_to_int (scm);
5024 buf[0] = midi & 0xFF;
5025 buf[1] = (midi >> 8) & 0xFF;
5026 buf[2] = (midi >> 16) & 0xFF;
5027 }
5028
5029 //g_debug("got %x\nbreaks as %x %x %x\n", midi&0xFFFFFF, buf[0], buf[1], buf[2]);
5030 if (midi)
5031 {
5032 gboolean capture = set_midi_capture (FALSE); //Turn off any capturing
5033 process_midi_event (buf);
5034 set_midi_capture (capture); //Restore any capturing that might be on
5035 }
5036 else
5037 process_midi_event (buf);
5038 return SCM_BOOL (TRUE);
5039 }
5040
5041 SCM
scheme_output_midi(SCM scm)5042 scheme_output_midi (SCM scm)
5043 {
5044 gchar buf[3];
5045 gint midi = scm_to_int (scm);
5046
5047 buf[0] = midi & 0xFF;
5048 buf[1] = (midi >> 8) & 0xFF;
5049 buf[2] = (midi >> 16) & 0xFF;
5050 play_adjusted_midi_event (buf);
5051 return SCM_BOOL_T;
5052 }
5053
5054
5055 /* outputs a midibytes string to MIDI out. Format of midibytes as in DenemoDirective->midibytes */
5056 SCM
scheme_output_midi_bytes(SCM input)5057 scheme_output_midi_bytes (SCM input)
5058 {
5059 char *next;
5060 gint i, numbytes;
5061 gint channel;
5062 gint volume;
5063 if (!scm_is_string (input))
5064 {
5065 return SCM_BOOL_F;
5066 }
5067 DenemoStaff *curstaffstruct = (DenemoStaff *) Denemo.project->movement->currentstaff->data;
5068 channel = get_midi_channel (curstaffstruct);
5069 volume = curstaffstruct->volume;
5070 char *string_input;
5071 string_input = scm_to_locale_string (input);
5072 gchar *bytes = substitute_midi_values (string_input, channel, volume);
5073 for (i = 0, next = bytes; *next; next++)
5074 {
5075 i++;
5076 if (*next == 0)
5077 break;
5078 }
5079 numbytes = i;
5080 unsigned char *buffer = (unsigned char *) g_malloc0 (numbytes);
5081 for (i = 0, next = bytes; i < numbytes; i++, next++)
5082 buffer[i] = (unsigned char) strtol (next, &next, 0);
5083 g_free (bytes);
5084 //g_debug("\nbuffer[0] = %x buffer[1] = %x buffer[2] = %x\n", buffer[0], buffer[1], buffer[2]);
5085
5086 play_midi_event (DEFAULT_BACKEND, curstaffstruct->midi_port, buffer);
5087
5088 if (string_input)
5089 free (string_input);
5090 return SCM_BOOL (TRUE);
5091 }
5092
5093 SCM
scheme_create_timebase(SCM optional)5094 scheme_create_timebase (SCM optional)
5095 {
5096 DenemoMovement *si = Denemo.project->movement;
5097 if (si->smfsync != si->changecount)
5098 {
5099 exportmidi (NULL, si);
5100 return SCM_BOOL_T;
5101 }
5102 return SCM_BOOL_F;
5103 }
5104
5105 SCM
scheme_pending_midi(SCM scm)5106 scheme_pending_midi (SCM scm)
5107 {
5108 if (scm_is_integer (scm))
5109 {
5110 guint key = scm_to_int (scm);
5111 g_queue_push_head (Denemo.project->pending_midi, GINT_TO_POINTER (key));
5112 return SCM_BOOL_T;
5113 }
5114 else
5115 return SCM_BOOL_F;
5116 }
5117
5118 SCM
scheme_play_midi_note(SCM note,SCM volume,SCM channel,SCM duration)5119 scheme_play_midi_note (SCM note, SCM volume, SCM channel, SCM duration)
5120 {
5121 guint vol = scm_to_int (volume);
5122 gint key = scm_to_int (note);
5123 gint chan = scm_to_int (channel);
5124 gint dur = scm_to_int (duration);
5125
5126 //g_debug("Playing %x at %f volume, %d channel for %dms\n", key, vol/255.0, channel, dur);
5127 play_note (DEFAULT_BACKEND, 0 /*port */ , chan, key, dur, vol);
5128 return SCM_BOOL (TRUE);
5129 }
5130
5131 SCM
scheme_play_midikey(SCM scm)5132 scheme_play_midikey (SCM scm)
5133 {
5134 guint midi = scm_to_int (scm);
5135 gint key = (midi >> 8) & 0xFF;
5136 gint channel = midi & 0xF;
5137 gint volume = ((midi >> 16) & 0x7F);
5138 //g_debug("Playing %x at %f volume, %d channel\n", key, (double)volume, channel);
5139 play_note (DEFAULT_BACKEND, 0 /*port */ , channel, key, 1000 /*duration */ , volume);
5140 //g_usleep(200000);
5141 return SCM_BOOL (TRUE);
5142 }
5143
5144 //Insert a rest without setting the prevailing duration
5145 SCM
scheme_put_rest(SCM optional_duration)5146 scheme_put_rest (SCM optional_duration)
5147 {
5148 gint duration;
5149 if (scm_is_integer (optional_duration))
5150 {
5151 duration = scm_to_int (optional_duration);
5152 }
5153 else
5154 {
5155 duration = get_prevailing_duration ();
5156 }
5157 if ((duration < 0) || (duration > 7))
5158 return SCM_BOOL_F;
5159 //FIXME should not allow spillover?
5160 dnm_insertchord (Denemo.project, duration, 0, TRUE);
5161 displayhelper (Denemo.project); //without this a call to d-AddVoice causes a crash as the chord length info has not been updated
5162 return SCM_BOOL_T;
5163 }
5164 //Insert a note without setting the prevailing duration
5165 SCM
scheme_put_note(SCM optional_duration)5166 scheme_put_note (SCM optional_duration)
5167 {
5168 gint duration;
5169 if (scm_is_integer (optional_duration))
5170 {
5171 duration = scm_to_int (optional_duration);
5172 }
5173 else
5174 {
5175 duration = get_prevailing_duration ();
5176 }
5177 if ((duration < 0) || (duration > 7))
5178 return SCM_BOOL_F;
5179 gboolean spill = Denemo.prefs.spillover;
5180 gint mode = Denemo.project->mode;
5181 Denemo.project->mode = 0;
5182 Denemo.prefs.spillover = 0;
5183
5184 if( scm_is_false (optional_duration))
5185 dnm_insertchord (Denemo.project, duration, INPUTNORMAL | INPUTBLANK, FALSE);//pass #f for nonprinting note
5186 else
5187 dnm_insertchord (Denemo.project, duration, INPUTNORMAL, FALSE);
5188 Denemo.project->mode = mode;
5189 Denemo.prefs.spillover = spill;
5190
5191 displayhelper (Denemo.project); //without this a call to d-AddVoice causes a crash as the chord length info has not been updated
5192 return SCM_BOOL_T;
5193 }
5194 //Insert a rest in the given (or prevailing duration) and set the prevailing duration
5195 SCM
scheme_insert_rest(SCM optional)5196 scheme_insert_rest (SCM optional)
5197 {
5198 SCM ret = scheme_put_rest (optional);
5199 if (scm_is_integer (optional))
5200 {
5201 gint duration = scm_to_int (optional);
5202 highlight_duration (Denemo.project, duration);
5203 }
5204 return ret;
5205 }
5206
5207
5208 SCM
scheme_toggle_playalong(void)5209 scheme_toggle_playalong (void)
5210 {
5211 pb_playalong (get_playalong_button ());
5212 return SCM_BOOL (Denemo.project->midi_destination | MIDIPLAYALONG);
5213 }
5214
5215 SCM
scheme_toggle_conduct(void)5216 scheme_toggle_conduct (void)
5217 {
5218 pb_conduct (get_conduct_button ());
5219 return SCM_BOOL (Denemo.project->midi_destination | MIDICONDUCT);
5220 }
5221
5222 SCM
scheme_midi_record(SCM script)5223 scheme_midi_record (SCM script)
5224 {
5225 if(is_playing())
5226 return SCM_BOOL_F;
5227 if (scm_is_string (script))
5228 {
5229 gchar *text = scm_to_locale_string (script);
5230 pb_record (text);
5231 free (text);
5232 } else
5233 pb_record (NULL);
5234 return SCM_BOOL (Denemo.project->midi_destination | MIDIRECORD);
5235 }
5236 SCM
scheme_compute_midi_note_durations(void)5237 scheme_compute_midi_note_durations (void)
5238 {
5239 return SCM_BOOL (compute_midi_note_durations ());
5240 }
5241
5242 SCM
scheme_get_marked_midi_note(void)5243 scheme_get_marked_midi_note (void)
5244 {
5245 SCM scm = SCM_BOOL_F;
5246 DenemoProject *gui = Denemo.project;
5247 DenemoMovement *si = gui->movement;
5248 if(si->recording && (si->recording->type == DENEMO_RECORDING_MIDI) && si->marked_onset) {
5249 GList *marked = si->marked_onset;
5250 DenemoRecordedNote *thenote = (DenemoRecordedNote*)marked->data;
5251 gchar *name = mid_c_offsettolily (thenote->mid_c_offset, thenote->enshift);
5252 gchar *str = g_strdup_printf ("%s", mid_c_offsettolily (thenote->mid_c_offset + 7*thenote->octave, thenote->enshift));
5253 scm = scm_from_locale_string (str);
5254 }
5255 return scm;
5256 }
5257 SCM
scheme_get_marked_midi_note_seconds(void)5258 scheme_get_marked_midi_note_seconds (void)
5259 {
5260 SCM scm = SCM_BOOL_F;
5261 DenemoProject *gui = Denemo.project;
5262 DenemoMovement *si = gui->movement;
5263 if(si->recording && (si->recording->type == DENEMO_RECORDING_MIDI) && si->marked_onset) {
5264 GList *marked = si->marked_onset;
5265 DenemoRecordedNote *thenote = (DenemoRecordedNote*)marked->data;
5266 gdouble seconds = thenote->timing/((gdouble)si->recording->samplerate);
5267 scm = scm_from_double (seconds);
5268 }
5269 return scm;
5270 }
5271
5272 SCM
scheme_advance_marked_midi(SCM advance)5273 scheme_advance_marked_midi (SCM advance)
5274 {
5275 SCM scm = SCM_BOOL_F;
5276 DenemoProject *gui = Denemo.project;
5277 DenemoMovement *si = gui->movement;
5278 if(si->recording && (si->recording->type == DENEMO_RECORDING_MIDI))
5279 {
5280 if (SCM_UNBNDP(advance))
5281 {
5282 if(si->marked_onset)
5283 si->marked_onset = si->marked_onset->next;
5284 }
5285 else if (scm_is_integer (advance))
5286 {
5287 gint i = scm_to_int (advance);
5288 if(i>0)
5289 {
5290 while(i-- && si->marked_onset)
5291 si->marked_onset = si->marked_onset->next;
5292 }
5293 else if (i<0)
5294 {
5295 while(i++ && si->marked_onset)
5296 si->marked_onset = si->marked_onset->prev;
5297 }
5298 else
5299 si->marked_onset = si->recording->notes;
5300
5301 }
5302 else if (scm_is_false (advance))
5303 {
5304 si->marked_onset = NULL;
5305 return SCM_BOOL_T;
5306 }
5307 if(si->marked_onset)
5308 scm = SCM_BOOL_T;
5309 }
5310
5311 return scm;
5312 }
5313
scheme_insert_marked_midi_note(void)5314 SCM scheme_insert_marked_midi_note (void)
5315 {
5316 return SCM_BOOL (insert_marked_midi_note ());
5317 }
5318
5319 typedef struct cb_scheme_and_id
5320 {
5321 char *scheme_code;
5322 gint id;
5323 } cb_scheme_and_id;
5324
5325 static gboolean
scheme_callback_one_shot_timer(cb_scheme_and_id * scheme)5326 scheme_callback_one_shot_timer (cb_scheme_and_id * scheme)
5327 {
5328 char *scheme_code = scheme->scheme_code;
5329 if (scheme->id == Denemo.project->id)
5330 call_out_to_guile (scheme_code);
5331 else
5332 g_warning ("Timer missed for gui %d", scheme->id);
5333 g_free (scheme);
5334 free (scheme_code);
5335 return FALSE;
5336 }
5337
5338 SCM
scheme_one_shot_timer(SCM duration_amount,SCM callback)5339 scheme_one_shot_timer (SCM duration_amount, SCM callback)
5340 {
5341 char *scheme_code;
5342 scheme_code = scm_to_locale_string (callback);
5343 gint duration = scm_to_int (duration_amount);
5344 cb_scheme_and_id *scheme = g_malloc (sizeof (cb_scheme_and_id));
5345 scheme->scheme_code = scheme_code;
5346 scheme->id = Denemo.project->id;
5347 g_timeout_add (duration, (GSourceFunc) scheme_callback_one_shot_timer, GINT_TO_POINTER (scheme));
5348 return SCM_BOOL (TRUE);
5349 }
5350
5351 static gboolean
scheme_callback_timer(cb_scheme_and_id * scheme)5352 scheme_callback_timer (cb_scheme_and_id * scheme)
5353 {
5354 char *scheme_code = scheme->scheme_code;
5355 if (scheme->id == Denemo.project->id)
5356 call_out_to_guile (scheme_code);
5357 else
5358 g_warning ("Timer missed for gui %d", scheme->id);
5359
5360 return TRUE; //continue to call
5361 }
5362
5363
5364 SCM
scheme_timer(SCM duration_amount,SCM callback)5365 scheme_timer (SCM duration_amount, SCM callback)
5366 {
5367 char *scheme_code;
5368 if (scm_is_string (callback))
5369 {
5370 scheme_code = scm_to_locale_string (callback); //FIXME check that type of callback is tring
5371 gint duration = scm_to_int (duration_amount);
5372 //g_debug("setting timer for %s after %d ms", scheme_code, duration);
5373 cb_scheme_and_id *scheme = g_malloc (sizeof (cb_scheme_and_id));
5374 scheme->scheme_code = scheme_code;
5375 scheme->id = Denemo.project->id;
5376 g_timeout_add (duration, (GSourceFunc) scheme_callback_timer, GINT_TO_POINTER (scheme));
5377 //if(scheme_code) free(scheme_code);
5378 return scm_from_int (GPOINTER_TO_INT (scheme)); //FIXME pointer may not fit in int
5379 }
5380 else
5381 return SCM_BOOL_F;
5382 }
5383
5384 SCM
scheme_kill_timer(SCM id)5385 scheme_kill_timer (SCM id)
5386 {
5387 if (scm_is_integer (id))
5388 {
5389 //FIXME the int may not be large enough for a pointer
5390 cb_scheme_and_id *scheme = GINT_TO_POINTER (scm_to_int (id));
5391 if (scheme)
5392 {
5393 g_source_remove_by_user_data (scheme);
5394 free (scheme->scheme_code);
5395 g_free (scheme);
5396 return SCM_BOOL_T;
5397 }
5398 }
5399 return SCM_BOOL_F;
5400 }
5401
5402
5403
5404
5405 SCM
scheme_bass_figure(SCM bass,SCM harmony)5406 scheme_bass_figure (SCM bass, SCM harmony)
5407 {
5408 SCM ret = SCM_BOOL_F;
5409 gboolean status = FALSE;
5410 gint bassnum = scm_to_int (bass);
5411 gint harmonynum = scm_to_int (harmony);
5412 gchar *interval = determine_interval (bassnum, harmonynum, &status);
5413 if (interval)
5414 {
5415 ret = scm_cons (status ? SCM_BOOL_T : SCM_BOOL_F, scm_from_locale_string (interval));
5416 g_free (interval);
5417 }
5418 return ret;
5419 }
5420
5421 SCM
scheme_has_figures(SCM optional)5422 scheme_has_figures (SCM optional)
5423 {
5424 return SCM_BOOL (((DenemoStaff *) Denemo.project->movement->currentstaff->data)->hasfigures);
5425 }
5426
5427
5428
5429 //badly named:
5430 SCM
scheme_put_note_name(SCM optional)5431 scheme_put_note_name (SCM optional)
5432 {
5433 DenemoObject *curObj;
5434 chord *thechord;
5435 note *thenote;
5436 if (!Denemo.project || !(Denemo.project->movement) || !(Denemo.project->movement->currentobject) || !(curObj = Denemo.project->movement->currentobject->data) || (curObj->type != CHORD) || !(thechord = (chord *) curObj->object) || !(thechord->notes) || !(thenote = (note *) thechord->notes->data))
5437 return SCM_BOOL (FALSE);
5438 else
5439 {
5440 char *str = NULL;
5441 if (scm_is_string (optional))
5442 {
5443 str = scm_to_locale_string (optional);
5444 gint mid_c_offset;
5445 gint enshift;
5446 interpret_lilypond_notename (str, &mid_c_offset, &enshift);
5447 //g_debug("note %s gives %d and %d\n", str, mid_c_offset, enshift);
5448 modify_note (thechord, mid_c_offset, enshift, find_prevailing_clef (Denemo.project->movement));
5449 if (str)
5450 free (str);
5451 return SCM_BOOL (TRUE);
5452 }
5453 }
5454 return SCM_BOOL (FALSE);
5455 }
5456
5457 SCM
scheme_set_accidental(SCM optional)5458 scheme_set_accidental (SCM optional)
5459 {
5460 DenemoObject *curObj;
5461 chord *thechord;
5462 note *thenote;
5463 if (!Denemo.project || !(Denemo.project->movement) || !(Denemo.project->movement->currentobject) || !(curObj = Denemo.project->movement->currentobject->data) || (curObj->type != CHORD) || !(thechord = (chord *) curObj->object) || !(thechord->notes) || !(thenote = (note *) thechord->notes->data))
5464 return SCM_BOOL (FALSE);
5465 else
5466 {
5467 GList *g;
5468 for (g = thechord->notes; g; g = g->next)
5469 {
5470 thenote = (note *) g->data;
5471 if (thenote->mid_c_offset == Denemo.project->movement->cursor_y)
5472 break;
5473 }
5474 if (g == NULL)
5475 return SCM_BOOL_F;
5476 DenemoMovement *si = Denemo.project->movement;
5477 char *str = NULL;
5478
5479 if (scm_is_string (optional))
5480 {
5481 str = scm_to_locale_string (optional);
5482 thenote->enshift = lilypond_to_enshift (str);
5483 }
5484 else if (scm_is_integer (optional))
5485 thenote->enshift = scm_to_int (optional);
5486 else
5487 thenote->enshift = 0;
5488 if ((thenote->enshift < -2) || (thenote->enshift > 2))
5489 thenote->enshift = 0;
5490 showwhichaccidentals ((objnode *) ((DenemoMeasure*)si->currentmeasure->data)->objects);
5491 // find_xes_in_measure (si, si->currentmeasurenum, si->cursortime1,
5492 // si->cursortime2); causes a crash, si is not passed correctly, why???
5493 //thenote->mid_c_offset = interpret_lilypond_notename(str);
5494 displayhelper (Denemo.project);
5495 if (str)
5496 free (str);
5497 return SCM_BOOL (TRUE);
5498 }
5499 }
5500
5501
5502
5503
5504
5505 //create a putnote here that takes a duration and numdots and note name, inserts a chord and calls the scheme_put_note_name above - this can be done via script at present, e.g. (d-C) (d-Change3) (d-AddDot) (d-PutNoteName "eis''")
5506
5507
5508 //Puts a note into the chord at the cursor PARAM lily is a string representation of the note
5509 SCM
scheme_insert_note_in_chord(SCM lily)5510 scheme_insert_note_in_chord (SCM lily)
5511 {
5512 DenemoProject *gui = Denemo.project;
5513 DenemoObject *curObj;
5514 if (!Denemo.project || !(Denemo.project->movement) || !(Denemo.project->movement->currentobject) || !(curObj = Denemo.project->movement->currentobject->data) )
5515 return SCM_BOOL_F;
5516 #ifdef INSERT_NOTE_IN_CHORD_WORKS_ON_PREVIOUS_CHORD
5517 if(curObj->type != CHORD) {
5518 objnode *theobj = Denemo.project->movement->currentobject;
5519 while(theobj->prev)
5520 {
5521 theobj = theobj->prev;
5522 curObj = theobj->data;
5523 if(curObj->type ==CHORD)
5524 break;
5525 }
5526 if(curObj->type !=CHORD)
5527 return SCM_BOOL_F;
5528 }
5529 #else
5530 if(curObj->type !=CHORD)
5531 return SCM_BOOL_F;
5532 #endif
5533
5534 char *str = NULL;
5535 if (scm_is_string (lily))
5536 {
5537 str = scm_to_locale_string (lily);
5538 gint mid_c_offset;
5539 gint enshift;
5540 interpret_lilypond_notename (str, &mid_c_offset, &enshift);
5541
5542 //g_debug("note %s gives %d and %d\n", str, mid_c_offset, enshift);
5543 addtone (curObj, mid_c_offset, enshift);
5544 score_status (gui, TRUE);
5545 displayhelper (Denemo.project);
5546 if (str)
5547 free (str);
5548 return SCM_BOOL_T;
5549 }
5550 return SCM_BOOL (FALSE);
5551 }
5552
5553
5554 //return the number of objects in the copybuffer at staff m
5555 SCM
scheme_get_clip_objects(SCM m)5556 scheme_get_clip_objects (SCM m)
5557 {
5558 gint staff = scm_to_int (m);
5559 gint num = get_clip_objs (staff);
5560 if (num == -1)
5561 return SCM_BOOL_F;
5562 else
5563 return scm_from_int (num);
5564 }
5565
5566 //return the type of the nth object in the copybuffer
5567 SCM
scheme_get_clip_obj_type(SCM m,SCM n)5568 scheme_get_clip_obj_type (SCM m, SCM n)
5569 {
5570 gint value = scm_to_int (n);
5571 gint staff = scm_to_int (m);
5572 DenemoObjType type = get_clip_obj_type (staff, value);
5573 if (type == -1)
5574 return SCM_BOOL_F;
5575 else
5576 return scm_from_int (type);
5577 }
5578
5579
5580 //insert the nth object from the denemo copybuffer
5581 SCM
scheme_put_clip_obj(SCM m,SCM n)5582 scheme_put_clip_obj (SCM m, SCM n)
5583 {
5584 gint value = scm_to_int (n);
5585 gint staff = scm_to_int (m);
5586 return SCM_BOOL (insert_clip_obj (staff, value));
5587 }
5588
5589 SCM
scheme_adjust_xes(SCM optional)5590 scheme_adjust_xes (SCM optional)
5591 {
5592 find_xes_in_all_measures (Denemo.project->movement);
5593 return SCM_BOOL_T;
5594 }
5595
5596 static gint
flash_cursor(void)5597 flash_cursor (void)
5598 {
5599 draw_score_area();
5600 // draw_score (NULL); what was this for?????
5601 return TRUE;
5602 }
5603
5604 SCM
scheme_highlight_cursor(SCM optional)5605 scheme_highlight_cursor (SCM optional)
5606 {
5607 static gint id;
5608 SCM ret = SCM_BOOL_T;
5609 gboolean old_value = Denemo.prefs.cursor_highlight;
5610 if (scm_is_bool(optional))
5611 {
5612 Denemo.prefs.cursor_highlight = scm_is_true (optional);
5613 ret = old_value?SCM_BOOL_T:SCM_BOOL_F;
5614 } else
5615 {
5616 Denemo.prefs.cursor_highlight = !Denemo.prefs.cursor_highlight;
5617 }
5618 if (id && !Denemo.prefs.cursor_highlight)
5619 {
5620 g_source_remove (id);
5621 id = 0;
5622 }
5623 else if (Denemo.prefs.cursor_highlight)
5624 id = g_timeout_add (500, (GSourceFunc) flash_cursor, NULL);
5625 //g_debug("Cursor highlighting %d id %d", Denemo.prefs.cursor_highlight, id);
5626 return ret;
5627 }
5628
5629 SCM
scheme_get_type(SCM at_or_before)5630 scheme_get_type (SCM at_or_before)
5631 {
5632 DenemoObject *curObj;
5633 if (!Denemo.project || !(Denemo.project->movement) || !(Denemo.project->movement->currentobject) || !(curObj = Denemo.project->movement->currentobject->data) || !(DENEMO_OBJECT_TYPE_NAME (curObj)))
5634 return scm_from_locale_string ("None");
5635 if (scm_is_true (at_or_before) && Denemo.project->movement->cursor_appending)
5636 return scm_from_locale_string ("Appending");
5637 return scm_from_locale_string (DENEMO_OBJECT_TYPE_NAME (curObj));
5638 }
5639
5640 SCM
scheme_get_lilypond(SCM optional)5641 scheme_get_lilypond (SCM optional)
5642 {
5643 DenemoProject *gui = Denemo.project;
5644 DenemoObject *curObj;
5645 if (!Denemo.project || !(Denemo.project->movement) || !(Denemo.project->movement->currentobject) || !(curObj = Denemo.project->movement->currentobject->data) || !(DENEMO_OBJECT_TYPE_NAME (curObj)))
5646 return SCM_BOOL_F;
5647 //g_debug("Before %d %d\n", gui->lilysync, gui->changecount);
5648
5649 if (gui->lilysync != gui->changecount)
5650 refresh_lily_cb (NULL, Denemo.project);
5651 //g_debug("After %d %d\n", gui->lilysync, gui->changecount);
5652 if (curObj->lilypond)
5653 return scm_from_locale_string (curObj->lilypond);
5654 return SCM_BOOL_F;
5655 }
5656
5657 SCM
scheme_get_tuplet(SCM optional)5658 scheme_get_tuplet (SCM optional)
5659 {
5660 DenemoObject *curObj;
5661 if (!Denemo.project || !(Denemo.project->movement) || !(Denemo.project->movement->currentobject) || !(curObj = Denemo.project->movement->currentobject->data) || (curObj->type != TUPOPEN))
5662 return SCM_BOOL_F;
5663 GString *ratio = g_string_new ("");
5664 g_string_printf (ratio, "%d/%d", ((tupopen *) curObj->object)->numerator, ((tupopen *) curObj->object)->denominator);
5665 return scm_from_locale_string (g_string_free (ratio, FALSE));
5666 }
5667
5668 SCM
scheme_set_tuplet(SCM ratio)5669 scheme_set_tuplet (SCM ratio)
5670 {
5671 DenemoObject *curObj;
5672 if (!Denemo.project || !(Denemo.project->movement) || !(Denemo.project->movement->currentobject) || !(curObj = Denemo.project->movement->currentobject->data) || (curObj->type != TUPOPEN))
5673 {
5674 return SCM_BOOL_F;
5675 }
5676 char *theratio;
5677 theratio = scm_to_locale_string (ratio);
5678 sscanf (theratio, "%d/%d", &((tupopen *) curObj->object)->numerator, &((tupopen *) curObj->object)->denominator);
5679 //g_debug("Set %d/%d\n", (((tupopen*)curObj->object)->numerator), (((tupopen*)curObj->object)->denominator));
5680 free (theratio);
5681 if (((tupopen *) curObj->object)->denominator)
5682 {
5683 return SCM_BOOL_T;
5684 }
5685 ((tupopen *) curObj->object)->denominator = 1;
5686 return SCM_BOOL_F;
5687 }
5688
5689 SCM
scheme_set_background(SCM color)5690 scheme_set_background (SCM color)
5691 {
5692 if (scm_is_integer (color))
5693 {
5694 gint value = scm_to_int (color);
5695 Denemo.color = value;
5696 draw_score_area();
5697 if(!Denemo.non_interactive)
5698 draw_score (NULL);
5699 return SCM_BOOL_T;
5700 }
5701 return SCM_BOOL_F;
5702 }
5703
5704
5705 SCM
scheme_get_nonprinting(SCM optional)5706 scheme_get_nonprinting (SCM optional)
5707 {
5708 DenemoObject *curObj;
5709 if (!Denemo.project || !(Denemo.project->movement) || !(Denemo.project->movement->currentobject) || !(curObj = Denemo.project->movement->currentobject->data) || curObj->isinvisible)
5710 return SCM_BOOL_T;
5711 return SCM_BOOL_F;
5712 }
5713
5714 SCM
scheme_set_nonprinting(SCM optional)5715 scheme_set_nonprinting (SCM optional)
5716 {
5717 DenemoObject *curObj;
5718 if (!Denemo.project || !(Denemo.project->movement) || !(Denemo.project->movement->currentobject) || !(curObj = Denemo.project->movement->currentobject->data))
5719 return SCM_BOOL_F;
5720 if (scm_is_false (optional))
5721 curObj->isinvisible = FALSE;
5722 else
5723 curObj->isinvisible = TRUE;
5724 return SCM_BOOL_T;
5725 }
5726
5727 SCM
scheme_is_grace(SCM optional)5728 scheme_is_grace (SCM optional)
5729 {
5730 DenemoObject *curObj;
5731 chord *thechord;
5732 if (!Denemo.project || !(Denemo.project->movement) || !(Denemo.project->movement->currentobject) || !(curObj = Denemo.project->movement->currentobject->data) || (curObj->type != CHORD) || !(thechord = (chord *) curObj->object) || !(thechord->is_grace))
5733 return SCM_BOOL_F;
5734 return SCM_BOOL_T;
5735 }
5736
5737 SCM
scheme_is_tied(SCM optional)5738 scheme_is_tied (SCM optional)
5739 {
5740 DenemoObject *curObj;
5741 chord *thechord;
5742 if (!Denemo.project || !(Denemo.project->movement) || !(Denemo.project->movement->currentobject) || !(curObj = Denemo.project->movement->currentobject->data) || (curObj->type != CHORD) || !(thechord = (chord *) curObj->object) || !(thechord->is_tied))
5743 return SCM_BOOL_F;
5744 return SCM_BOOL_T;
5745 }
5746
5747
5748 SCM
scheme_is_slur_start(SCM optional)5749 scheme_is_slur_start (SCM optional)
5750 {
5751 DenemoObject *curObj;
5752 chord *thechord;
5753 if (!Denemo.project || !(Denemo.project->movement) || !(Denemo.project->movement->currentobject) || !(curObj = Denemo.project->movement->currentobject->data) || (curObj->type != CHORD) || !(thechord = (chord *) curObj->object) || !(thechord->slur_begin_p))
5754 return SCM_BOOL_F;
5755 return SCM_BOOL_T;
5756 }
5757
5758 SCM
scheme_is_slur_end(SCM optional)5759 scheme_is_slur_end (SCM optional)
5760 {
5761 DenemoObject *curObj;
5762 chord *thechord;
5763 if (!Denemo.project || !(Denemo.project->movement) || !(Denemo.project->movement->currentobject) || !(curObj = Denemo.project->movement->currentobject->data) || (curObj->type != CHORD) || !(thechord = (chord *) curObj->object) || !(thechord->slur_end_p))
5764 return SCM_BOOL_F;
5765 return SCM_BOOL_T;
5766 }
5767
5768 SCM
scheme_is_cresc_start(SCM optional)5769 scheme_is_cresc_start (SCM optional)
5770 {
5771 DenemoObject *curObj;
5772 chord *thechord;
5773 if (!Denemo.project || !(Denemo.project->movement) || !(Denemo.project->movement->currentobject) || !(curObj = Denemo.project->movement->currentobject->data) || (curObj->type != CHORD) || !(thechord = (chord *) curObj->object) || !(thechord->crescendo_begin_p))
5774 return SCM_BOOL_F;
5775 return SCM_BOOL_T;
5776 }
5777
5778 SCM
scheme_is_cresc_end(SCM optional)5779 scheme_is_cresc_end (SCM optional)
5780 {
5781 DenemoObject *curObj;
5782 chord *thechord;
5783 if (!Denemo.project || !(Denemo.project->movement) || !(Denemo.project->movement->currentobject) || !(curObj = Denemo.project->movement->currentobject->data) || (curObj->type != CHORD) || !(thechord = (chord *) curObj->object) || !(thechord->crescendo_end_p))
5784 return SCM_BOOL_F;
5785 return SCM_BOOL_T;
5786 }
5787
5788 SCM
scheme_is_dim_start(SCM optional)5789 scheme_is_dim_start (SCM optional)
5790 {
5791 DenemoObject *curObj;
5792 chord *thechord;
5793 if (!Denemo.project || !(Denemo.project->movement) || !(Denemo.project->movement->currentobject) || !(curObj = Denemo.project->movement->currentobject->data) || (curObj->type != CHORD) || !(thechord = (chord *) curObj->object) || !(thechord->diminuendo_begin_p))
5794 return SCM_BOOL_F;
5795 return SCM_BOOL_T;
5796 }
5797
5798 SCM
scheme_is_dim_end(SCM optional)5799 scheme_is_dim_end (SCM optional)
5800 {
5801 DenemoObject *curObj;
5802 chord *thechord;
5803 if (!Denemo.project || !(Denemo.project->movement) || !(Denemo.project->movement->currentobject) || !(curObj = Denemo.project->movement->currentobject->data) || (curObj->type != CHORD) || !(thechord = (chord *) curObj->object) || !(thechord->diminuendo_end_p))
5804 return SCM_BOOL_F;
5805 return SCM_BOOL_T;
5806 }
5807
5808 SCM
scheme_is_in_selection(void)5809 scheme_is_in_selection (void)
5810 {
5811 return SCM_BOOL (in_selection (Denemo.project->movement));
5812 }
5813 SCM
scheme_has_selection(void)5814 scheme_has_selection (void)
5815 {
5816 return SCM_BOOL (Denemo.project->movement->markstaffnum != 0);
5817 }
5818 SCM
scheme_is_appending(void)5819 scheme_is_appending (void)
5820 {
5821 return SCM_BOOL (Denemo.project->movement->cursor_appending);
5822 }
5823
5824
5825
5826
5827 SCM
scheme_clear_clipboard(SCM optional)5828 scheme_clear_clipboard (SCM optional)
5829 {
5830 clearbuffer ();
5831 return SCM_BOOL (TRUE);
5832 }
5833
5834 SCM
scheme_get_staffs_in_clipboard(SCM optional)5835 scheme_get_staffs_in_clipboard (SCM optional)
5836 {
5837 gint num = get_staffs_in_clipboard ();
5838 if (num)
5839 return scm_from_int (num);
5840 return SCM_BOOL_F;
5841 }
5842
5843
5844 SCM
scheme_get_measures_in_staff(SCM optional)5845 scheme_get_measures_in_staff (SCM optional)
5846 {
5847 gint num = g_list_length (((DenemoStaff *) Denemo.project->movement->currentstaff->data)->themeasures);
5848 return scm_from_int (num);
5849 }
5850 SCM
scheme_get_staffs_in_movement(SCM optional)5851 scheme_get_staffs_in_movement (SCM optional)
5852 {
5853 gint num = g_list_length (Denemo.project->movement->thescore);
5854 return scm_from_int (num);
5855 }
5856
5857 SCM
scheme_set_lines_in_staff(SCM lines)5858 scheme_set_lines_in_staff (SCM lines)
5859 {
5860 DenemoStaff *thestaff = (DenemoStaff *) Denemo.project->movement->currentstaff->data;
5861 if (scm_is_integer (lines))
5862 {
5863 gint value = scm_to_int (lines);
5864 thestaff->no_of_lines = value;
5865 displayhelper (Denemo.project);
5866 }
5867
5868 return scm_from_int (thestaff->no_of_lines);
5869 }
5870 static SCM
set_staff_range(SCM setting,gboolean hi)5871 set_staff_range (SCM setting, gboolean hi)
5872 {
5873 DenemoStaff *thestaff = (DenemoStaff *) Denemo.project->movement->currentstaff->data;
5874 if (scm_is_integer (setting))
5875 {
5876 gint value = scm_to_int (setting);
5877 *(hi?&thestaff->range_hi:&thestaff->range_lo) = value;
5878 thestaff->range = TRUE;
5879 }
5880 if(thestaff->range)
5881 return scm_from_int (hi?thestaff->range_hi:thestaff->range_lo);
5882 return SCM_BOOL_F;
5883 }
5884 SCM
scheme_set_staff_range_hi(SCM hi)5885 scheme_set_staff_range_hi (SCM hi)
5886 {
5887 return set_staff_range (hi, TRUE);
5888 }
5889 SCM
scheme_set_staff_range_lo(SCM lo)5890 scheme_set_staff_range_lo (SCM lo)
5891 {
5892 return set_staff_range (lo, FALSE);
5893 }
5894 SCM
scheme_set_staff_range(void)5895 scheme_set_staff_range (void)
5896 {
5897 DenemoStaff *thestaff = (DenemoStaff *) Denemo.project->movement->currentstaff->data;
5898 if(Denemo.project->movement->currentobject)
5899 {
5900 DenemoObject *curobj = Denemo.project->movement->currentobject->data;
5901 if(curobj->type==CHORD)
5902 {
5903 chord *thechord = ((chord *) curobj->object);
5904 thestaff->range_hi = thechord->highestpitch;
5905 thestaff->range_lo = thechord->lowestpitch;
5906 thestaff->range = TRUE;
5907 return SCM_BOOL_T;
5908 }
5909 }
5910 return SCM_BOOL_F;
5911 }
5912 SCM
scheme_shorten_staff_height(SCM shorten)5913 scheme_shorten_staff_height (SCM shorten)
5914 {
5915 DenemoStaff *thestaff = (DenemoStaff *) Denemo.project->movement->currentstaff->data;
5916
5917 if (scm_is_integer (shorten))
5918 {
5919 gint value = scm_to_int (shorten);
5920 thestaff->space_shorten = value;
5921 displayhelper (Denemo.project);
5922 }
5923 return scm_from_int (thestaff->space_shorten);
5924 }
5925
5926 SCM
scheme_set_color_of_staff(SCM color)5927 scheme_set_color_of_staff (SCM color)
5928 {
5929 DenemoStaff *thestaff = (DenemoStaff *) Denemo.project->movement->currentstaff->data;
5930 gint current = thestaff->color;
5931 if (scm_is_integer (color))
5932 {
5933 gint value = scm_to_ulong (color);
5934 thestaff->color = value;
5935 displayhelper (Denemo.project);
5936 }
5937
5938 return scm_from_ulong (thestaff->color);
5939 }
5940 SCM
scheme_staff_to_voice(SCM optional)5941 scheme_staff_to_voice (SCM optional)
5942 {
5943 SCM ret = SCM_BOOL_F;
5944 DenemoStaff *current = ((DenemoStaff *) Denemo.project->movement->currentstaff->data);
5945 if (Denemo.project->movement->currentstaff->prev && (current->voicecontrol == DENEMO_PRIMARY))
5946 {
5947 current->voicecontrol |= DENEMO_SECONDARY;
5948 staff_set_current_primary (Denemo.project->movement);
5949 DenemoStaff *primary = (DenemoStaff *) Denemo.project->movement->currentprimarystaff->data;
5950 if ((current->timesig.time1 != primary->timesig.time1)
5951 || (current->timesig.time2 != primary->timesig.time2))
5952 {
5953 warningdialog (_("Time Signatures do not match, will not make voice"));
5954 current->voicecontrol = DENEMO_PRIMARY;
5955 staff_set_current_primary (Denemo.project->movement);
5956 return SCM_BOOL_F;
5957 }
5958 if ((current->keysig.number != primary->keysig.number)
5959 || (current->keysig.isminor != primary->keysig.isminor)
5960 || (current->keysig.mode != primary->keysig.mode))
5961 {
5962 warningdialog (_("Key Signatures do not match, will not make voice"));
5963 current->voicecontrol = DENEMO_PRIMARY;
5964 staff_set_current_primary (Denemo.project->movement);
5965 return SCM_BOOL_F;
5966 }
5967
5968 if (current->clef.type != primary->clef.type)
5969 {
5970 warningdialog (_("This voice has a different clef from the staff it will be typeset on. This clef will be used for the display only."));
5971 }
5972 ret = SCM_BOOL_T;
5973 draw_score_area();
5974 score_status (Denemo.project, TRUE);
5975 if(!Denemo.non_interactive)
5976 draw_score (NULL);
5977 }
5978 return ret;
5979 }
5980
5981 SCM
scheme_voice_to_staff(SCM optional)5982 scheme_voice_to_staff (SCM optional)
5983 {
5984 SCM ret = SCM_BOOL_F;
5985 if (((DenemoStaff *) Denemo.project->movement->currentstaff->data)->voicecontrol & DENEMO_SECONDARY)
5986 {
5987 ((DenemoStaff *) Denemo.project->movement->currentstaff->data)->voicecontrol = DENEMO_PRIMARY;
5988 staff_set_current_primary (Denemo.project->movement);
5989 ret = SCM_BOOL_T;
5990 score_status (Denemo.project, TRUE);
5991 draw_score_area();
5992 }
5993 return ret;
5994 }
5995
5996 SCM
scheme_is_voice(void)5997 scheme_is_voice (void)
5998 {
5999 return SCM_BOOL ((((DenemoStaff *) Denemo.project->movement->currentstaff->data)->voicecontrol & DENEMO_SECONDARY));
6000 }
6001 /* shifts the note at the cursor by the number of diatonic steps passed in */
6002 SCM
scheme_diatonic_shift(SCM optional)6003 scheme_diatonic_shift (SCM optional)
6004 {
6005 DenemoProject *gui = Denemo.project;
6006 DenemoObject *curObj;
6007 chord *thechord;
6008 note *thenote;
6009 if (!Denemo.project || !(Denemo.project->movement) || !(Denemo.project->movement->currentobject) || !(curObj = Denemo.project->movement->currentobject->data) || (curObj->type != CHORD) || !(thechord = (chord *) curObj->object) || !(thechord->notes) || !(thenote = (note *) thechord->notes->data))
6010 {
6011 return SCM_BOOL (FALSE);
6012 }
6013 else
6014 {
6015 char *str = NULL;
6016 if (scm_is_string (optional))
6017 {
6018 str = scm_to_locale_string (optional);
6019 gint shift;
6020 sscanf (str, "%d", &shift);
6021 // g_debug("note shift %s ie %d\n", str, shift);
6022 modify_note (thechord, thenote->mid_c_offset + shift, curObj->keysig->accs[offsettonumber (thenote->mid_c_offset + shift)], find_prevailing_clef (Denemo.project->movement));
6023 free (str);
6024 }
6025 }
6026 return SCM_BOOL (FALSE);
6027 }
6028
6029 /* moves currentobject to next object by calling cursorright.
6030 Steps over barlines (i.e. cursor_appending).
6031 returns TRUE if currentobject is different after than before doing the call
6032 */
6033 SCM
scheme_next_object(void)6034 scheme_next_object (void)
6035 {
6036 return SCM_BOOL (cursor_to_next_object (FALSE, FALSE));
6037 }
6038
6039 /* moves currentobject to prev object by calling cursorleft.
6040 Steps over barlines (i.e. cursor_appending).
6041 returns TRUE if currentobject is different after than before doing the call
6042 */
6043 SCM
scheme_prev_object(void)6044 scheme_prev_object (void)
6045 {
6046 return SCM_BOOL (cursor_to_prev_object (FALSE, FALSE));
6047 }
6048
6049
6050 /* moves currentobject to next object in measure, if any
6051 returns TRUE if currentobject is different after than before doing the call
6052 */
6053 SCM
scheme_next_object_in_measure(void)6054 scheme_next_object_in_measure (void)
6055 {
6056 return SCM_BOOL (cursor_to_next_object (TRUE, FALSE));
6057 }
6058
6059 /* moves currentobject to previous object in measure, if any
6060 returns TRUE if currentobject is different after than before doing the call
6061 */
6062 SCM
scheme_prev_object_in_measure(void)6063 scheme_prev_object_in_measure (void)
6064 {
6065 return SCM_BOOL (cursor_to_prev_object (TRUE, FALSE));
6066 }
6067
6068
6069 SCM
scheme_refresh_display(SCM optional)6070 scheme_refresh_display (SCM optional)
6071 {
6072 displayhelper (Denemo.project);
6073 //done in displayhelper write_status(Denemo.project);
6074 return SCM_BOOL (TRUE);
6075 }
6076
6077 SCM
scheme_refresh_cache(void)6078 scheme_refresh_cache (void)
6079 {
6080 draw_score (NULL);
6081 return SCM_BOOL (TRUE);
6082 }
6083
6084
6085
6086 SCM
scheme_set_saved(SCM optional)6087 scheme_set_saved (SCM optional)
6088 {
6089 if (scm_is_false (optional))
6090 score_status (Denemo.project, TRUE);
6091 else
6092 score_status (Denemo.project, FALSE);
6093 return SCM_BOOL (TRUE);
6094 }
6095
6096 SCM
scheme_get_saved(SCM optional)6097 scheme_get_saved (SCM optional)
6098 {
6099 return SCM_BOOL (!Denemo.project->notsaved);
6100 }
6101
6102 SCM
scheme_changecount(SCM count)6103 scheme_changecount (SCM count)
6104 {
6105 if(scm_is_integer (count))
6106 {
6107 Denemo.project->changecount = scm_to_int (count);
6108 }
6109 return scm_from_int (Denemo.project->changecount);
6110
6111 }
6112
6113 SCM
scheme_mark_status(SCM optional)6114 scheme_mark_status (SCM optional)
6115 {
6116 return SCM_BOOL (mark_status ());
6117
6118 }
6119
6120 /* moves currentobject to next object in the selection.
6121 Steps over barlines (i.e. cursor_appending).
6122 returns TRUE if currentobject is different after than before the call
6123 */
6124 SCM
scheme_next_selected_object(SCM optional)6125 scheme_next_selected_object (SCM optional)
6126 {
6127 return SCM_BOOL (cursor_to_next_selected_object ());
6128 }
6129
6130 /* moves currentobject to previous object in the selection.
6131 Steps over barlines (i.e. cursor_appending).
6132 returns TRUE if currentobject is different after than before the call
6133 */
6134 SCM
scheme_prev_selected_object(SCM optional)6135 scheme_prev_selected_object (SCM optional)
6136 {
6137 return SCM_BOOL (cursor_to_prev_selected_object ());
6138 }
6139
6140
6141
6142
6143 SCM
scheme_next_standalone_directive(SCM optional)6144 scheme_next_standalone_directive (SCM optional)
6145 {
6146 return SCM_BOOL (cursor_to_next_standalone_directive ());
6147 }
6148
6149 SCM
scheme_prev_standalone_directive(SCM optional)6150 scheme_prev_standalone_directive (SCM optional)
6151 {
6152 return SCM_BOOL (cursor_to_prev_standalone_directive ());
6153 }
6154
6155 SCM
scheme_next_standalone_directive_in_measure(SCM optional)6156 scheme_next_standalone_directive_in_measure (SCM optional)
6157 {
6158 return SCM_BOOL (cursor_to_next_standalone_in_measure ());
6159 }
6160
6161 SCM
scheme_prev_standalone_directive_in_measure(SCM optional)6162 scheme_prev_standalone_directive_in_measure (SCM optional)
6163 {
6164 return SCM_BOOL (cursor_to_prev_standalone_in_measure ());
6165 }
6166
6167
6168 SCM
scheme_next_chord(SCM optional)6169 scheme_next_chord (SCM optional)
6170 {
6171 DenemoPosition pos;
6172 get_position (Denemo.project->movement, &pos);
6173 gboolean ret = cursor_to_next_chord ();
6174 if (!ret)
6175 goto_movement_staff_obj (NULL, -1, pos.staff, pos.measure, pos.object, pos.leftmeasurenum);
6176 return SCM_BOOL (ret);
6177 }
6178
6179 SCM
scheme_prev_chord(SCM optional)6180 scheme_prev_chord (SCM optional)
6181 {
6182 DenemoPosition pos;
6183 get_position (Denemo.project->movement, &pos);
6184 gboolean ret = cursor_to_prev_chord ();
6185 if (!ret)
6186 goto_movement_staff_obj (NULL, -1, pos.staff, pos.measure, pos.object, pos.leftmeasurenum);
6187 return SCM_BOOL (ret);
6188 }
6189
6190
6191 SCM
scheme_next_chord_in_measure(SCM optional)6192 scheme_next_chord_in_measure (SCM optional)
6193 {
6194 return SCM_BOOL (cursor_to_next_chord_in_measure ());
6195 }
6196
6197 SCM
scheme_prev_chord_in_measure(SCM optional)6198 scheme_prev_chord_in_measure (SCM optional)
6199 {
6200 return SCM_BOOL (cursor_to_prev_chord_in_measure ());
6201 }
6202
6203
6204
6205
6206 SCM
scheme_next_note(SCM optional)6207 scheme_next_note (SCM optional)
6208 {
6209 return SCM_BOOL (cursor_to_next_note ());
6210 }
6211
6212 SCM
scheme_prev_note(SCM optional)6213 scheme_prev_note (SCM optional)
6214 {
6215 return SCM_BOOL (cursor_to_prev_note ());
6216 }
6217
6218 void
update_scheme_snippet_ids(void)6219 update_scheme_snippet_ids (void)
6220 {
6221 DenemoProject *gui = Denemo.project;
6222 GList *g;
6223 gint i;
6224 for (g = gui->rhythms, i = 1; g; g = g->next, i++)
6225 {
6226 RhythmPattern *r = (RhythmPattern *) g->data;
6227 if (r->name)
6228 {
6229 gchar *command = g_strdup_printf ("(define Snippet::%s %d)", r->name, i);
6230 call_out_to_guile (command);
6231 g_free (command);
6232 }
6233 }
6234 }
6235
6236 SCM
scheme_create_snippet_from_object(SCM name)6237 scheme_create_snippet_from_object (SCM name)
6238 {
6239 if (scm_is_string (name))
6240 {
6241 char *str;
6242 str = scm_to_locale_string (name);
6243 if (Denemo.project->movement->currentobject)
6244 {
6245 DenemoObject *clonedobj = dnm_clone_object (Denemo.project->movement->currentobject->data);
6246 RhythmPattern *r = (RhythmPattern *) g_malloc0 (sizeof (RhythmPattern));
6247 install_button_for_pattern (r, str);
6248 r->clipboard = g_list_append (NULL, g_list_append (NULL, clonedobj));
6249 append_rhythm (r, NULL);
6250 RhythmElement *relement = (RhythmElement *) g_malloc0 (sizeof (RhythmElement));
6251 //relement->icon = str; was wrong, must be NULL for a singleton.
6252 r->name = str;
6253 r->nickname = g_string_new (str);
6254 r->rsteps = g_list_append (NULL, relement);
6255 r->rsteps->prev = r->rsteps->next = r->rsteps; //make list circular
6256 SCM ret = scm_from_int (insert_pattern_in_toolbar (r, TRUE));
6257 update_scheme_snippet_ids ();
6258 if (str)
6259 free (str);
6260 return ret;
6261 }
6262 if (str)
6263 free (str);
6264 }
6265 return SCM_BOOL_F;
6266 }
6267
6268 SCM
scheme_select_snippet(SCM number)6269 scheme_select_snippet (SCM number)
6270 {
6271 if (scm_is_integer (number))
6272 {
6273 gint position = scm_to_int (number);
6274 GList *g = g_list_nth (Denemo.project->rhythms, position - 1);
6275 if (g)
6276 {
6277 RhythmPattern *r = g->data;
6278 if (r)
6279 {
6280
6281 select_rhythm_pattern (r);
6282
6283 return SCM_BOOL_T;
6284 }
6285 }
6286 }
6287
6288 return SCM_BOOL_F;
6289 }
6290
6291 SCM
scheme_insert_snippet(SCM number,SCM select)6292 scheme_insert_snippet (SCM number, SCM select)
6293 {
6294 if (scm_is_integer (number))
6295 {
6296 gint position = scm_to_int (number);
6297 GList *g = g_list_nth (Denemo.project->rhythms, position - 1);
6298 if (g)
6299 {
6300 RhythmPattern *r = g->data;
6301 if (r)
6302 {
6303 if(scm_is_true(select)) {
6304 select_rhythm_pattern (r);
6305 insert_note_following_pattern (Denemo.project);
6306 } else {
6307 insert_nth_rhythm (position-1);
6308 }
6309
6310 return SCM_BOOL_T;
6311 }
6312 }
6313 }
6314 return SCM_BOOL_F;
6315 }
6316
6317
6318
6319 SCM
scheme_locate_dotdenemo(SCM optional)6320 scheme_locate_dotdenemo (SCM optional)
6321 {
6322 const gchar *dotdenemo = get_user_data_dir (TRUE);
6323 if (!dotdenemo)
6324 return SCM_BOOL (FALSE);
6325 SCM scm = scm_from_locale_string (dotdenemo);
6326 return scm;
6327 }
6328
6329
scheme_log_debug(SCM message)6330 SCM scheme_log_debug(SCM message){
6331 if(scm_is_string(message)){
6332 const gchar* msg = scm_to_locale_string(message);
6333 g_debug("%s", msg);
6334 }
6335 return SCM_BOOL_T;
6336 }
6337
scheme_log_info(SCM message)6338 SCM scheme_log_info(SCM message){
6339 if(scm_is_string(message)){
6340 const gchar* msg = scm_to_locale_string(message);
6341 g_info("%s", msg);
6342 }
6343 return SCM_BOOL_T;
6344 }
6345
scheme_log_message(SCM message)6346 SCM scheme_log_message(SCM message){
6347 if(scm_is_string(message)){
6348 const gchar* msg = scm_to_locale_string(message);
6349 g_message("%s", msg);
6350 }
6351 return SCM_BOOL_T;
6352 }
6353
scheme_log_warning(SCM message)6354 SCM scheme_log_warning(SCM message){
6355 if(scm_is_string(message)){
6356 const gchar* msg = scm_to_locale_string(message);
6357 g_warning("%s", msg);
6358 }
6359 return SCM_BOOL_T;
6360 }
6361
scheme_log_critical(SCM message)6362 SCM scheme_log_critical(SCM message){
6363 if(scm_is_string(message)){
6364 const gchar* msg = scm_to_locale_string(message);
6365 g_critical("%s", msg);
6366 }
6367 return SCM_BOOL_T;
6368 }
6369
scheme_log_error(SCM message)6370 SCM scheme_log_error(SCM message){
6371 if(scm_is_string(message)){
6372 const gchar* msg = scm_to_locale_string(message);
6373 g_error("%s", msg);
6374 }
6375 return SCM_BOOL_T;
6376 }
6377
6378