So far, just a few simple staff lines.
-scherzo: scherzo.c
- gcc -Wall -Wextra $$(pkg-config --cflags --libs gtk+-2.0) -o scherzo scherzo.c
+all: scherzo
+scherzo_srcs = \
+ scherzo.c \
+ score.c
+
+scherzo_modules = $(scherzo_srcs:.c=.o)
+
+WARN_CFLAGS = -Wall -Wextra
+
+SCHERZO_CFLAGS = $(CFLAGS) $(WARN_CFLAGS) $(CONFIGURE_CFLAGS) $(extra_cflags) `pkg-config --cflags gtk+-2.0`
+
+SCHERZO_LDFLAGS = $(LDFLAGS) `pkg-config --libs gtk+-2.0`
+
+# The user has not set any verbosity, default to quiet mode and inform the
+# user how to enable verbose compiles.
+ifeq ($(V),)
+quiet_DOC := "Use \"$(MAKE) V=1\" to see the verbose compile lines.\n"
+quiet = @printf $(quiet_DOC)$(eval quiet_DOC:=)"$1 $@\n"; $($(shell echo $1 | sed -e s'/ .*//'))
+endif
+# The user has explicitly enabled quiet compilation.
+ifeq ($(V),0)
+quiet = @printf "$1 $@\n"; $($(shell echo $1 | sed -e s'/ .*//'))
+endif
+# Otherwise, print the full command line.
+quiet ?= $($(shell echo $1 | sed -e s'/ .*//'))
+
+.deps/%.d: %.cpp $(global_deps)
+ @set -e; rm -f $@; mkdir -p $$(dirname $@) ; \
+ $(CXX) -M $(CPPFLAGS) $(FINAL_CXXFLAGS) $< > $@.$$$$ 2>/dev/null ; \
+ sed 's,'$$(basename $*)'\.o[ :]*,$*.o $@ : ,g' < $@.$$$$ > $@; \
+ rm -f $@.$$$$
+
+DEPS := $(DEPS:%.cpp=.deps/%.d)
+-include $(DEPS)
+
+%.o: %.c $(global_deps)
+ $(call quiet,CC $(CFLAGS)) -c $(SCHERZO_CFLAGS) $< -o $@
+
+scherzo: $(scherzo_modules)
+ $(call quiet,CC $(CFLAGS)) $^ $(SCHERZO_LDFLAGS) -o $@
+
+CLEAN := $(CLEAN) scherzo $(chorale_modules)
+
+.PHONY : clean
clean:
- rm -f scherzo
+ rm -f $(CLEAN); rm -rf .deps
#include <gtk/gtk.h>
+#include "score.h"
+
#define unused(foo) foo __attribute__((unused))
static int
static int
on_expose_event_draw (GtkWidget *widget,
unused (GdkEventExpose *event),
- unused (gpointer user_data))
+ void * user_data)
{
+ score_t *score = user_data;
cairo_t *cr;
GtkAllocation allocation;
+ static const int pad = 10;
+ int widget_width, staff_width;
gtk_widget_get_allocation (widget, &allocation);
+ widget_width = allocation.width;
cr = gdk_cairo_create (widget->window);
- /* Paint in medium sea green */
- cairo_set_source_rgb (cr, 60/255.0, 179/255.0, 113/255.0);
-
+ /* White background */
+ cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
cairo_paint (cr);
+
+ /* Add some padding on the left/right */
+ cairo_translate (cr, pad, pad);
+
+ score_set_width (score, widget_width - 2 * pad);
+
+ score_draw (score, cr);
return TRUE;
}
{
GtkWidget *window;
GtkWidget *drawing_area;
+ score_t score;
gtk_init (&argc, &argv);
+ score_init (&score);
+
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size (GTK_WINDOW (window), 600, 400);
gtk_container_add (GTK_CONTAINER (window), drawing_area);
g_signal_connect (drawing_area, "expose-event",
- G_CALLBACK (on_expose_event_draw), NULL);
-
+ G_CALLBACK (on_expose_event_draw),
+ &score);
gtk_widget_show_all (window);
--- /dev/null
+/* scherzo - Music notation training
+ *
+ * score - Utilities for drawing (simple) musical scores
+ *
+ * Copyright © 2010 Carl Worth
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see http://www.gnu.org/licenses/ .
+ */
+
+#include "score.h"
+
+void
+score_init (score_t *score)
+{
+ score->space_height = 6;
+}
+
+void
+_draw_staff (score_t *score, cairo_t *cr)
+{
+ int i;
+
+ cairo_save (cr);
+
+ for (i = 0; i < 5; i++) {
+ cairo_move_to (cr, 0, i * score->space_height + 0.5);
+ cairo_rel_line_to (cr, score->width, 0);
+ }
+
+ cairo_set_line_width (cr, 1.0);
+
+ cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
+ cairo_stroke (cr);
+
+ cairo_restore (cr);
+}
+
+void
+score_set_width (score_t *score, int width)
+{
+ score->width = width;
+}
+
+void
+score_draw (score_t *score, cairo_t *cr)
+{
+ _draw_staff (score, cr);
+}
--- /dev/null
+/* scherzo - Music notation training
+ *
+ * score - Utilities for drawing (simple) musical scores
+ *
+ * Copyright © 2010 Carl Worth
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see http://www.gnu.org/licenses/ .
+ */
+
+#ifndef SCORE_H
+#define SCORE_H
+
+#include <cairo.h>
+
+typedef struct score
+{
+ /* Height of each space on staff. */
+ int space_height;
+
+ /* Total width available to score. */
+ int width;
+} score_t;
+
+void
+score_init (score_t *score);
+
+void
+score_draw (score_t *score, cairo_t *cr);
+
+#endif