LMMS
Loading...
Searching...
No Matches
ctl_keyboard.h
Go to the documentation of this file.
1/* Calf DSP Library
2 * Barely started keyboard widget. Planned to be usable as
3 * a ruler for curves, and possibly as input widget in future
4 * as well (that's what event sink interface is for, at least).
5 *
6 * Copyright (C) 2008 Krzysztof Foltman
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General
19 * Public License along with this program; if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301 USA
22 */
23#ifndef CALF_CTL_KEYBOARD_H
24#define CALF_CTL_KEYBOARD_H
25
26#include <gtk/gtk.h>
27
28G_BEGIN_DECLS
29
30#define CALF_TYPE_KEYBOARD (calf_keyboard_get_type())
31#define CALF_KEYBOARD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CALF_TYPE_KEYBOARD, CalfKeyboard))
32#define CALF_IS_KEYBOARD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CALF_TYPE_KEYBOARD))
33#define CALF_KEYBOARD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CALF_TYPE_KEYBOARD, CalfKeyboardClass))
34#define CALF_IS_KEYBOARD_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((klass), CALF_TYPE_KEYBOARD))
35
38{
40 struct KeyInfo
41 {
42 double x;
43 double y;
44 double width;
45 double height;
46 int note;
47 bool black;
48 };
49
51 struct EventSink
52 {
54 virtual void set_instance(CalfKeyboard *kb)=0;
57 virtual bool pre_draw(cairo_t *c, KeyInfo &ki)=0;
60 virtual bool pre_draw_outline(cairo_t *c, KeyInfo &ki)=0;
62 virtual void post_draw(cairo_t *c, KeyInfo &ki)=0;
64 virtual void post_all(cairo_t *c)=0;
66 virtual void note_on(int note, int vel) = 0;
68 virtual void note_off(int note) = 0;
69
70 virtual ~EventSink() {}
71 };
72
74 struct EventAdapter: public EventSink
75 {
77 virtual void set_instance(CalfKeyboard *_kb) { kb = _kb; }
78 virtual bool pre_draw(cairo_t *c, KeyInfo &ki) { return false; }
79 virtual bool pre_draw_outline(cairo_t *c, KeyInfo &ki) { return false; }
80 virtual void post_draw(cairo_t *c, KeyInfo &ki) {}
81 virtual void post_all(cairo_t *c) {}
82 virtual void note_on(int note, int vel) {}
83 virtual void note_off(int note) {}
84 };
85
88 {
89 virtual bool pre_draw(cairo_t *c, KeyInfo &ki) { if (ki.note == 60) cairo_set_source_rgb(c, 1.0, 1.0, 0.5); return false; }
90 virtual void post_draw(cairo_t *c, KeyInfo &ki) {
91 if (ki.note % 12 != 0 && ki.note % 12 != 3 && ki.note % 12 != 7)
92 return;
93 cairo_rectangle(c, ki.x + ki.width / 2 - 2, ki.y + ki.height - 8, 4, 4);
94 if (ki.black)
95 cairo_set_source_rgb(c, 1.0, 1.0, 1.0);
96 else
97 cairo_set_source_rgb(c, 0.0, 0.0, 0.0);
98 cairo_fill(c);
99 }
100 virtual void note_on(int note, int vel) { g_message("note on %d %d", note, vel); }
101 virtual void note_off(int note) { g_message("note off %d", note); }
102 };
103
105 GtkWidget parent;
107 int nkeys;
113};
114
117{
119 GtkWidgetClass parent_class;
120};
121
123extern GtkWidget *calf_keyboard_new();
124
126extern GType calf_keyboard_get_type();
127
128G_END_DECLS
129
130#endif
131
GtkWidget * calf_keyboard_new()
Create new keyboard object;.
Definition ctl_keyboard.cpp:32
GType calf_keyboard_get_type()
Return a GType for CalfKeyboard.
Definition ctl_keyboard.cpp:273
Null implementation of CalfKeyboard::EventSink.
Definition ctl_keyboard.h:75
virtual void post_draw(cairo_t *c, KeyInfo &ki)
called after key is drawn using standard method (but not if drawing is skipped)
Definition ctl_keyboard.h:80
virtual void note_off(int note)
key was released
Definition ctl_keyboard.h:83
virtual void post_all(cairo_t *c)
called after key is drawn
Definition ctl_keyboard.h:81
virtual bool pre_draw(cairo_t *c, KeyInfo &ki)
Definition ctl_keyboard.h:78
virtual bool pre_draw_outline(cairo_t *c, KeyInfo &ki)
Definition ctl_keyboard.h:79
virtual void set_instance(CalfKeyboard *_kb)
(will be) called on attachment of sink to CalfKeyboard object
Definition ctl_keyboard.h:77
virtual void note_on(int note, int vel)
key was pressed
Definition ctl_keyboard.h:82
CalfKeyboard * kb
Definition ctl_keyboard.h:76
Set of user-defined callbacks for customizing display and operation of CalfKeyboard.
Definition ctl_keyboard.h:52
virtual void note_off(int note)=0
key was released
virtual void set_instance(CalfKeyboard *kb)=0
(will be) called on attachment of sink to CalfKeyboard object
virtual bool pre_draw(cairo_t *c, KeyInfo &ki)=0
virtual void post_all(cairo_t *c)=0
called after key is drawn
virtual void note_on(int note, int vel)=0
key was pressed
virtual ~EventSink()
Definition ctl_keyboard.h:70
virtual void post_draw(cairo_t *c, KeyInfo &ki)=0
called after key is drawn using standard method (but not if drawing is skipped)
virtual bool pre_draw_outline(cairo_t *c, KeyInfo &ki)=0
Debug/example implementation of CalfKeyboard::EventSink.
Definition ctl_keyboard.h:88
virtual void note_off(int note)
key was released
Definition ctl_keyboard.h:101
virtual void note_on(int note, int vel)
key was pressed
Definition ctl_keyboard.h:100
virtual void post_draw(cairo_t *c, KeyInfo &ki)
called after key is drawn using standard method (but not if drawing is skipped)
Definition ctl_keyboard.h:90
virtual bool pre_draw(cairo_t *c, KeyInfo &ki)
Definition ctl_keyboard.h:89
Structure with information needed for drawing a single key.
Definition ctl_keyboard.h:41
double width
key width
Definition ctl_keyboard.h:44
bool black
true if it's a black key, false if it's a white key
Definition ctl_keyboard.h:47
double height
key height
Definition ctl_keyboard.h:45
double x
X coordinate of the top-left point of the key.
Definition ctl_keyboard.h:42
double y
Y coordinate of the top-left point of the key.
Definition ctl_keyboard.h:43
int note
MIDI note number.
Definition ctl_keyboard.h:46
Class-specific data for CalfKeyboard.
Definition ctl_keyboard.h:117
GtkWidgetClass parent_class
Parent class members.
Definition ctl_keyboard.h:119
Instance-specific data for CalfKeyboard.
Definition ctl_keyboard.h:38
int last_key
The note currently pressed via mouse selection.
Definition ctl_keyboard.h:110
int nkeys
Range (number of white keys = number of octaves * 7 + 1).
Definition ctl_keyboard.h:107
EventSink * sink
Definition ctl_keyboard.h:108
bool interactive
If true, the keyboard accepts mouse clicks and keys.
Definition ctl_keyboard.h:112
GtkWidget parent
Parent instance members.
Definition ctl_keyboard.h:105
return c
Definition crypt.c:175