1 #ifndef MUSED_H
2 #define MUSED_H
3 
4 /*
5 Copyright (c) 2009-2010 Tero Lindeman (kometbomb)
6 
7 Permission is hereby granted, free of charge, to any person
8 obtaining a copy of this software and associated documentation
9 files (the "Software"), to deal in the Software without
10 restriction, including without limitation the rights to use,
11 copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the
13 Software is furnished to do so, subject to the following
14 conditions:
15 
16 The above copyright notice and this permission notice shall be
17 included in all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 OTHER DEALINGS IN THE SOFTWARE.
27 */
28 
29 #include "snd/music.h"
30 #include "gfx/font.h"
31 #include "console.h"
32 #include "gui/slider.h"
33 #include "edit.h"
34 
35 enum
36 {
37 	EDITPATTERN,
38 	EDITSEQUENCE,
39 	EDITCLASSIC,
40 	EDITINSTRUMENT,
41 	EDITFX,
42 	EDITWAVETABLE,
43 	/* Focuses */
44 	EDITPROG,
45 	EDITSONGINFO,
46 	/* Virtual modes, i.e. what are not modes itself but should be considered happening "inside" prev_mode */
47 	EDITBUFFER,
48 	MENU
49 };
50 
51 #define N_VIEWS EDITPROG
52 #define VIRTUAL_MODE EDITBUFFER
53 
54 #include "clipboard.h"
55 #include "copypaste.h"
56 #include "gui/menu.h"
57 #include "undo.h"
58 #include <stdbool.h>
59 #include "wavegen.h"
60 #include "diskop.h"
61 
62 #define SCREEN_WIDTH 320
63 #define SCREEN_HEIGHT 240
64 
65 
66 enum
67 {
68 	COMPACT_VIEW = 1,
69 	SONG_PLAYING = 2,
70 	FULLSCREEN = 4,
71 	MULTICHANNEL_PREVIEW = 8,
72 	SHOW_PATTERN_POS_OFFSET = 16,
73 	FOLLOW_PLAY_POSITION = 32,
74 	ANIMATE_CURSOR = 64,
75 	HIDE_ZEROS = 128,
76 	DELETE_EMPTIES = 256,
77 	EDIT_MODE = 512,
78 	SHOW_ANALYZER = 2048,
79 #ifdef MIDI
80 	MIDI_SYNC = 4096,
81 #endif
82 	SHOW_LOGO = 8192,
83 	SHOW_DECIMALS = 16384,
84 	LOOP_POSITION = 32768,
85 	LOCK_SEQUENCE_STEP_AND_PATTERN_LENGTH = 65536,
86 	SHOW_DELAY_IN_TICKS = 65536 << 1,
87 	EDIT_SEQUENCE_DIGITS = 65536 << 2,
88 	EXPAND_ONLY_CURRENT_TRACK = 65536 << 3,
89 	DISABLE_NOSTALGY = 65536 << 4,
90 	TOGGLE_EDIT_ON_STOP = 65536 << 5,
91 	STOP_EDIT_ON_PLAY = 65536 << 6,
92 	MULTIKEY_JAMMING = 65536 << 7,
93 	DISABLE_VU_METERS = 65536 << 8,
94 	WINDOW_MAXIMIZED = 65536 << 9,
95 	SHOW_WAVEGEN = 65536 << 10,
96 	DISABLE_RENDER_TO_TEXTURE = 65536 << 11,
97 	DISABLE_BACKUPS = 65536 << 12,
98 	START_WITH_TEMPLATE = 65536 << 13,
99 	USE_SYSTEM_CURSOR = 65536 << 14,
100 };
101 
102 enum
103 {
104 	VC_INSTRUMENT = 1,
105 	VC_VOLUME = 2,
106 	VC_CTRL = 4,
107 	VC_COMMAND = 8
108 };
109 
110 enum
111 {
112 	VIS_SPECTRUM = 0,
113 	VIS_CATOMETER = 1,
114 	VIS_NUM_TOTAL
115 };
116 
117 typedef struct
118 {
119 	Uint32 flags, visible_columns;
120 	int done;
121 	Console *console;
122 	MusSong song;
123 	CydEngine cyd;
124 	MusEngine mus;
125 	int octave, instrument_page, current_instrument, default_pattern_length, selected_param, editpos, mode, focus,
126 		current_patternx, current_patternpos, current_sequencepos, sequenceview_steps, single_pattern_edit,
127 		prev_mode, current_sequenceparam, instrument_list_position,
128 		pattern_position, sequence_position, pattern_horiz_position, sequence_horiz_position,
129 		program_position, current_program_step,
130 		edit_reverb_param, selected_wavetable, wavetable_param, songinfo_param,
131 		loop_store_length, loop_store_loop, note_jump, wavetable_list_position, wavetable_preview_idx, sequence_digit;
132 	int current_sequencetrack;
133 	Uint16 time_signature;
134 	Clipboard cp;
135 	char * edit_buffer;
136 	int edit_buffer_size;
137 	SliderParam sequence_slider_param, pattern_slider_param, program_slider_param, instrument_list_slider_param,
138 		pattern_horiz_slider_param, sequence_horiz_slider_param, wavetable_list_slider_param;
139 	char previous_song_filename[1000], previous_export_filename[1000], previous_filebox_path[OD_T_N_TYPES][1000];
140 	/*---*/
141 	char * edit_backup_buffer;
142 	Selection selection;
143 	/* -- stat -- */
144 	int stat_song_position;
145 	int stat_pattern_position[MUS_MAX_CHANNELS];
146 	MusPattern *stat_pattern[MUS_MAX_CHANNELS];
147 	MusChannel *channel;
148 	int stat_pattern_number[MUS_MAX_CHANNELS], stat_note[MUS_MAX_CHANNELS];
149 	Uint64 time_played, play_start_at;
150 	/* ---- */
151 	char info_message[256];
152 	SDL_TimerID info_message_timer;
153 	GfxSurface *slider_bevel, *vu_meter, *analyzer, *logo, *catometer;
154 	Font smallfont, largefont, tinyfont, tinyfont_sequence_counter, tinyfont_sequence_normal;
155 	SDL_Cursor *mouse_cursor;
156 	GfxSurface *mouse_cursor_surface;
157 	GfxSurface *icon_surface;
158 
159 	/* for menu */
160 	Font menufont, menufont_selected, headerfont, headerfont_selected, shortcutfont, shortcutfont_selected, buttonfont;
161 
162 	char themename[100], keymapname[100];
163 	int pixel_scale;
164 	int mix_rate, mix_buffer;
165 	int window_w, window_h;
166 	int fx_bus, fx_room_size, fx_room_vol, fx_room_dec, fx_tap, fx_axis, fx_room_ticks, fx_room_prev_x, fx_room_prev_y;
167 	/*---vis---*/
168 	int current_visualizer;
169 	struct
170 	{
171 		int cyd_env[MUS_MAX_CHANNELS];
172 		int spec_peak[96], spec_peak_decay[96];
173 		float prev_a;
174 	} vis;
175 
176 	/*---*/
177 	SDL_Rect cursor_target, cursor;
178 	/*----------*/
179 	UndoStack undo;
180 	UndoStack redo;
181 	SHType last_snapshot;
182 	int last_snapshot_a, last_snapshot_b;
183 	bool modified;
184 	/*------------*/
185 	GfxSurface *wavetable_preview;
186 	Uint16 wavetable_bits;
187 	int prev_wavetable_x, prev_wavetable_y;
188 
189 #ifdef MIDI
190 	Uint32 midi_device;
191 	Uint8 midi_channel;
192 	bool midi_start;
193 	Uint16 midi_rate;
194 	Uint32 midi_last_clock;
195 	Uint8 tick_ctr;
196 #endif
197 
198 	WgSettings wgset;
199 	int selected_wg_osc, selected_wg_preset;
200 
201 	int oversample;
202 } Mused;
203 
204 extern Mused mused;
205 extern GfxDomain *domain;
206 extern Uint32 pattern_color[16];
207 
208 #define NUM_PATTERNS 4096
209 #define NUM_INSTRUMENTS 128
210 #define NUM_SEQUENCES 2048
211 
212 void default_settings();
213 void change_mode(int newmode);
214 void clear_pattern(MusPattern *pat);
215 void clear_pattern_range(MusPattern *pat, int first, int last);
216 void init(MusInstrument *instrument, MusPattern *pattern, MusSeqPattern sequence[MUS_MAX_CHANNELS][NUM_SEQUENCES], MusChannel *channel);
217 void deinit();
218 void new_song();
219 void kt_default_instrument(MusInstrument *instrument);
220 void set_edit_buffer(char *buffer, size_t size);
221 void change_pixel_scale(void *a, void*b, void*c);
222 void mirror_flags();
223 void resize_pattern(MusPattern * pattern, Uint16 new_size);
224 void init_scrollbars();
225 void my_open_menu();
226 int viscol(int col);
227 void post_config_load();
228 void enable_callback(bool state);
229 int get_pattern(int abspos, int track);
230 int get_patternstep(int abspos, int track);
231 int current_pattern();
232 int current_pattern_for_channel(int channel);
233 int current_patternstep();
234 MusStep * get_current_step();
235 MusPattern * get_current_pattern();
236 void change_visualizer(int vis);
237 void set_info_message(const char *string, ...)  __attribute__ ((format (printf, 1, 2)));
238 void set_channels(int channels);
239 Uint32 get_playtime_at(int position);
240 
241 #endif
242