File: pattern_editor.h

package info (click to toggle)
zytrax 0%2Bgit20201215-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 2,488 kB
  • sloc: cpp: 41,800; ansic: 3,387; makefile: 8; sh: 3
file content (268 lines) | stat: -rw-r--r-- 6,742 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
#ifndef PATTERN_EDITOR_H
#define PATTERN_EDITOR_H

#include "engine/song.h"
#include "engine/undo_redo.h"
#include <gtkmm/cssprovider.h>
#include <gtkmm/styleproperty.h>
#include <gtkmm/widget.h>

#include "gui/color_theme.h"
#include "gui/key_bindings.h"

class PatternEditor : public Gtk::Widget {
public:
	enum BeatZoom {
		BEAT_ZOOM_1,
		BEAT_ZOOM_2,
		BEAT_ZOOM_3,
		BEAT_ZOOM_4,
		BEAT_ZOOM_6,
		BEAT_ZOOM_8,
		BEAT_ZOOM_12,
		BEAT_ZOOM_16,
		BEAT_ZOOM_24,
		BEAT_ZOOM_32,
		BEAT_ZOOM_48,
		BEAT_ZOOM_64,
		BEAT_ZOOM_MAX
	};

protected:
	//Overrides:
	Gtk::SizeRequestMode get_request_mode_vfunc() const override;
	void get_preferred_width_vfunc(int &minimum_width, int &natural_width) const override;
	void get_preferred_height_for_width_vfunc(int width, int &minimum_height, int &natural_height) const override;
	void get_preferred_height_vfunc(int &minimum_height, int &natural_height) const override;
	void get_preferred_width_for_height_vfunc(int height, int &minimum_width, int &natural_width) const override;
	void on_size_allocate(Gtk::Allocation &allocation) override;
	void on_map() override;
	void on_unmap() override;
	void on_realize() override;
	void on_unrealize() override;
	bool on_draw(const Cairo::RefPtr<Cairo::Context> &cr) override;

	//Signal handler:
	void on_parsing_error(const Glib::RefPtr<const Gtk::CssSection> &section, const Glib::Error &error);

	void _mouse_button_event(GdkEventButton *event, bool p_press);

	bool on_scroll_event(GdkEventScroll *scroll_event);
	bool on_button_press_event(GdkEventButton *event);
	bool on_button_release_event(GdkEventButton *event);
	bool on_motion_notify_event(GdkEventMotion *motion_event);
	bool on_key_press_event(GdkEventKey *key_event);
	bool on_key_release_event(GdkEventKey *key_event);

	Glib::RefPtr<Gdk::Window> m_refGdkWindow;
	UndoRedo *undo_redo;

	Song *song;

	int current_pattern;
	int current_octave;
	int cursor_advance;
	int volume_mask;
	bool volume_mask_active;
	int v_offset;
	BeatZoom beat_zoom;
	int h_offset;
	int visible_rows;

	int row_height_cache;
	int row_top_ofs;

	struct Cursor {
		int row;
		int column;
		int field;
		//int skip;
	} cursor;

	struct Selection {
		int begin_column;
		Tick begin_tick;

		int end_column;
		Tick end_tick;

		Tick row_tick_size;

		bool active;

		int shift_from_column;
		int shift_from_row;
		bool shift_active;

		int mouse_drag_from_column;
		int mouse_drag_from_row;
		bool mouse_drag_active;

	} selection;

	struct Clipboard {

		List<Track::PosEvent> events;
		int columns;
		Tick ticks;
		bool active;
	} clipboard;

	void _update_shift_selection();
	bool _is_in_selection(int p_column, Tick p_tick);

	struct ClickArea {

		int column;

		struct Field {
			int x;
			int width;
		};

		Vector<Field> fields;

		Automation *automation;

		struct AutomationPoint {

			int index;
			int x, y;
			Tick tick;
		};

		List<AutomationPoint> automation_points;

		ClickArea() {
			automation = NULL;
		}
	};

	int fw_cache;
	int fh_cache;

	int get_column_offset(int p_column);

	List<ClickArea> click_areas;

	int grabbing_point;
	Tick grabbing_point_tick_from;
	uint8_t grabbing_point_value_from;
	Tick grabbing_point_tick;
	uint8_t grabbing_point_value;
	Automation *grabbing_automation;
	int grabbing_x, grabbing_width;
	int grabbing_mouse_pos_x;
	int grabbing_mouse_pos_y;

	int grabbing_mouse_prev_x;
	int grabbing_mouse_prev_y;

	int get_total_rows() const;
	int get_visible_rows() const;

	void _cursor_advance();

	void get_cursor_column_data(Track **r_track, int &r_command_column, int &r_automation, int &r_track_column);

	void _draw_text(const Cairo::RefPtr<Cairo::Context> &cr, int x, int y, const String &p_text, const Gdk::RGBA &p_color, bool p_down = false);
	void _draw_fill_rect(const Cairo::RefPtr<Cairo::Context> &cr, int x, int y, int w, int h, const Gdk::RGBA &p_color);
	void _draw_rect(const Cairo::RefPtr<Cairo::Context> &cr, int x, int y, int w, int h, const Gdk::RGBA &p_color);
	void _draw_arrow(const Cairo::RefPtr<Cairo::Context> &cr, int x, int y, int w, int h, const Gdk::RGBA &p_color);

	void _field_clear();
	void _validate_cursor();
	void _validate_selection();
	void _redraw();

	Theme *theme;
	KeyBindings *key_bindings;

	int _get_rows_per_beat() const;
	void _on_action_activated(KeyBindings::KeyBind p_bind);
	void _validate_menus();
	void _notify_track_layout_changed();

	bool drawing;
	int last_amplify_value;
	float last_scale_value;

	Glib::RefPtr<Gtk::Adjustment> h_scroll;
	Glib::RefPtr<Gtk::Adjustment> v_scroll;

	void _v_scroll_changed();
	void _h_scroll_changed();

	int playback_pattern;
	int playback_row;

	Glib::RefPtr<Gio::Menu> new_track_menu;
	Gtk::Menu new_track_popup;

	Glib::RefPtr<Gio::Menu> track_menu;
	Glib::RefPtr<Gio::Menu> track_menu_add;
	Glib::RefPtr<Gio::Menu> track_menu_column;
	Glib::RefPtr<Gio::Menu> track_menu_command;
	Glib::RefPtr<Gio::Menu> track_menu_solo;
	Glib::RefPtr<Gio::Menu> track_menu_edit;
	Glib::RefPtr<Gio::Menu> track_menu_remove;
	Gtk::Menu track_popup;

	Glib::RefPtr<Gio::Menu> automation_menu;
	Glib::RefPtr<Gio::MenuItem> automation_menu_item;
	Glib::RefPtr<Gio::Menu> automation_menu_mode;
	Glib::RefPtr<Gio::Menu> automation_menu_move;
	Glib::RefPtr<Gio::Menu> automation_menu_remove;
	Gtk::Menu automation_popup;

	int _cursor_get_track_begin_column();
	int _cursor_get_track_end_column();

public:
	sigc::signal1<void, int> track_edited;
	sigc::signal0<void> track_layout_changed;
	sigc::signal0<void> current_track_changed;

	sigc::signal0<void> volume_mask_changed;
	sigc::signal0<void> octave_changed;
	sigc::signal0<void> step_changed;
	sigc::signal0<void> zoom_changed;
	sigc::signal0<void> pattern_changed;

	sigc::signal1<void, AudioEffect *> erase_effect_editor_request;

	void set_current_pattern(int p_pattern);
	int get_current_pattern() const;

	void set_current_octave(int p_octave);
	int get_current_octave() const;

	void set_current_cursor_advance(int p_cursor_advance);
	int get_current_cursor_advance() const;

	void set_current_volume_mask(int p_volume_mask, bool p_active);
	int get_current_volume_mask() const;
	bool is_current_volume_mask_active() const;

	void set_beat_zoom(BeatZoom p_zoom);
	BeatZoom get_beat_zoom() const;

	int get_current_track() const;
	Tick get_cursor_tick() const;

	void set_hscroll(Glib::RefPtr<Gtk::Adjustment> p_h_scroll);
	void set_vscroll(Glib::RefPtr<Gtk::Adjustment> p_v_scroll);

	void set_playback_pos(int p_pattern, Tick p_tick);
	void set_playback_cursor(int p_pattern, Tick p_tick);

	void redraw_and_validate_cursor();

	void set_focus_on_track(int p_track);
	void initialize_menus();

	PatternEditor(Song *p_song, UndoRedo *p_undo_redo, Theme *p_theme, KeyBindings *p_bindings);
	~PatternEditor();
};

#endif // PATTERN_EDITOR_H