Subversion Repositories svn.mios32

Rev

Rev 2530 | Rev 2532 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
134 tk 1
// $Id: seq_ui.c 2531 2017-10-11 22:55:38Z tk $
2
/*
3
 * User Interface Routines
4
 *
5
 * ==========================================================================
6
 *
7
 *  Copyright (C) 2008 Thorsten Klose (tk@midibox.org)
8
 *  Licensed for personal non-commercial use only.
9
 *  All other rights reserved.
10
 *
11
 * ==========================================================================
12
 */
13
 
14
/////////////////////////////////////////////////////////////////////////////
15
// Include files
16
/////////////////////////////////////////////////////////////////////////////
17
 
18
#include <mios32.h>
299 tk 19
#include <string.h>
690 tk 20
#include <blm.h>
190 tk 21
#include <seq_midi_out.h>
22
#include <seq_bpm.h>
2263 tk 23
#include <blm_scalar_master.h>
2461 tk 24
#include <ws2812.h>
134 tk 25
 
290 tk 26
#include "tasks.h"
134 tk 27
#include "seq_ui.h"
728 tk 28
#include "seq_lcd.h"
29
#include "seq_lcd_logo.h"
492 tk 30
#include "seq_hwcfg.h"
134 tk 31
#include "seq_lcd.h"
32
#include "seq_led.h"
2531 tk 33
#include "seq_blm8x8.h"
186 tk 34
#include "seq_midply.h"
1527 tk 35
#include "seq_mixer.h"
2148 tk 36
#include "seq_live.h"
134 tk 37
#include "seq_core.h"
399 tk 38
#include "seq_song.h"
333 tk 39
#include "seq_par.h"
178 tk 40
#include "seq_layer.h"
184 tk 41
#include "seq_cc.h"
1313 tk 42
#include "seq_record.h"
785 tk 43
#include "seq_midi_sysex.h"
1336 tk 44
#include "seq_midi_port.h"
1794 tk 45
#include "seq_midi_in.h"
1020 tk 46
#include "seq_blm.h"
1261 tk 47
 
48
#include "file.h"
299 tk 49
#include "seq_file.h"
1281 tk 50
#include "seq_file_t.h"
690 tk 51
#include "seq_file_hw.h"
134 tk 52
 
53
 
54
/////////////////////////////////////////////////////////////////////////////
55
// Global variables
56
/////////////////////////////////////////////////////////////////////////////
57
 
159 tk 58
u8 seq_ui_display_update_req;
59
u8 seq_ui_display_init_req;
134 tk 60
 
167 tk 61
seq_ui_button_state_t seq_ui_button_state;
62
 
134 tk 63
u8 ui_selected_group;
484 tk 64
u16 ui_selected_tracks;
134 tk 65
u8 ui_selected_par_layer;
66
u8 ui_selected_trg_layer;
328 tk 67
u8 ui_selected_instrument;
134 tk 68
u8 ui_selected_step_view;
69
u8 ui_selected_step;
168 tk 70
u8 ui_selected_item;
1319 tk 71
u16 ui_selected_gp_buttons;
134 tk 72
 
168 tk 73
u8 ui_selected_item;
134 tk 74
 
240 tk 75
u16 ui_hold_msg_ctr;
2324 tk 76
u8  ui_hold_msg_ctr_drum_edit; // 1 if a drum parameter is edited or parameter layer selection button is pushed
240 tk 77
 
206 tk 78
seq_ui_page_t ui_page;
272 tk 79
seq_ui_page_t ui_selected_page;
600 tk 80
seq_ui_page_t ui_stepview_prev_page;
81
seq_ui_page_t ui_trglayer_prev_page;
82
seq_ui_page_t ui_parlayer_prev_page;
206 tk 83
 
173 tk 84
volatile u8 ui_cursor_flash;
740 tk 85
volatile u8 ui_cursor_flash_overrun_ctr;
173 tk 86
u16 ui_cursor_flash_ctr;
134 tk 87
 
316 tk 88
u8 ui_edit_name_cursor;
89
u8 ui_edit_preset_num_category;
90
u8 ui_edit_preset_num_label;
729 tk 91
u8 ui_edit_preset_num_drum;
316 tk 92
 
193 tk 93
u8 ui_seq_pause;
94
 
1421 tk 95
u8 ui_song_edit_pos;
96
 
2102 tk 97
u8 ui_store_file_required;
98
 
634 tk 99
u8 seq_ui_backup_req;
740 tk 100
u8 seq_ui_format_req;
974 tk 101
u8 seq_ui_saveall_req;
625 tk 102
 
1713 tk 103
u8 seq_ui_sent_cc_track;
104
 
2250 tk 105
seq_ui_options_t seq_ui_options;
106
 
744 tk 107
// to display directories via SEQ_UI_SelectListItem() and SEQ_LCD_PrintList() -- see seq_ui_sysex.c as example
746 tk 108
char ui_global_dir_list[80];
634 tk 109
 
1203 tk 110
seq_ui_bookmark_t seq_ui_bookmarks[SEQ_UI_BOOKMARKS_NUM];
744 tk 111
 
2250 tk 112
mios32_sys_time_t seq_play_timer;
1349 tk 113
 
2250 tk 114
 
134 tk 115
/////////////////////////////////////////////////////////////////////////////
2250 tk 116
// Local types
117
/////////////////////////////////////////////////////////////////////////////
118
 
119
typedef struct {
120
  u8 selected_instrument;
121
  u8 selected_par_layer;
122
  u8 selected_trg_layer;
123
  u8 selected_step_view;
124
} seq_ui_track_setup_t;
125
 
126
 
127
/////////////////////////////////////////////////////////////////////////////
134 tk 128
// Local variables
129
/////////////////////////////////////////////////////////////////////////////
130
 
168 tk 131
static s32 (*ui_button_callback)(seq_ui_button_t button, s32 depressed);
132
static s32 (*ui_encoder_callback)(seq_ui_encoder_t encoder, s32 incrementer);
173 tk 133
static s32 (*ui_led_callback)(u16 *gp_leds);
167 tk 134
static s32 (*ui_lcd_callback)(u8 high_prio);
352 tk 135
static s32 (*ui_exit_callback)(void);
2041 tk 136
static s32 (*ui_midi_in_callback)(mios32_midi_port_t port, mios32_midi_package_t p);
752 tk 137
static s32 (*ui_delayed_action_callback)(u32 parameter);
138
static u32 ui_delayed_action_parameter;
167 tk 139
 
168 tk 140
static u16 ui_gp_leds;
167 tk 141
 
2530 tk 142
static u16 ui_select_leds_green;
143
static u16 ui_select_leds_red;
144
 
1040 tk 145
#define UI_MSG_MAX_CHAR 31
596 tk 146
static char ui_msg[2][UI_MSG_MAX_CHAR];
147
static u16 ui_msg_ctr;
148
static seq_ui_msg_type_t ui_msg_type;
299 tk 149
 
740 tk 150
static u16 ui_delayed_action_ctr;
299 tk 151
 
1203 tk 152
static seq_ui_page_t ui_page_before_bookmark;
752 tk 153
 
2250 tk 154
static u8 seq_ui_track_setup_visible_track;
155
static seq_ui_track_setup_t seq_ui_track_setup[SEQ_CORE_NUM_TRACKS];
752 tk 156
 
1713 tk 157
 
134 tk 158
/////////////////////////////////////////////////////////////////////////////
1713 tk 159
// Prototypes
160
/////////////////////////////////////////////////////////////////////////////
161
static s32 SEQ_UI_Button_StepViewInc(s32 depressed);
162
static s32 SEQ_UI_Button_StepViewDec(s32 depressed);
163
 
164
 
165
/////////////////////////////////////////////////////////////////////////////
134 tk 166
// Initialisation
167
/////////////////////////////////////////////////////////////////////////////
168
s32 SEQ_UI_Init(u32 mode)
169
{
626 tk 170
  int i;
171
  // clear all LEDs
172
  for(i=0; i<SEQ_LED_NUM_SR; ++i)
173
    SEQ_LED_SRSet(i, 0x00);
174
 
134 tk 175
  // init selection variables
176
  ui_selected_group = 0;
177
  ui_selected_tracks = (1 << 0);
178
  ui_selected_par_layer = 0;
179
  ui_selected_trg_layer = 0;
328 tk 180
  ui_selected_instrument = 0;
134 tk 181
  ui_selected_step_view = 0;
182
  ui_selected_step = 0;
168 tk 183
  ui_selected_item = 0;
1319 tk 184
  ui_selected_gp_buttons = 0;
134 tk 185
 
2250 tk 186
  seq_ui_options.ALL = 0;
187
 
240 tk 188
  ui_hold_msg_ctr = 0;
596 tk 189
  ui_msg_ctr = 0;
740 tk 190
  ui_delayed_action_ctr = 0;
240 tk 191
 
740 tk 192
  ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0;
173 tk 193
  ui_cursor_flash = 0;
168 tk 194
 
167 tk 195
  seq_ui_button_state.ALL = 0;
196
 
193 tk 197
  ui_seq_pause = 0;
198
 
1421 tk 199
  ui_song_edit_pos = 0;
200
 
134 tk 201
  // visible GP pattern
202
  ui_gp_leds = 0x0000;
203
 
2530 tk 204
  // select LEDs
205
  ui_select_leds_green = 0x0000;
206
  ui_select_leds_red = 0x0000;
207
 
634 tk 208
  // misc
209
  seq_ui_backup_req = 0;
740 tk 210
  seq_ui_format_req = 0;
974 tk 211
  seq_ui_saveall_req = 0;
634 tk 212
 
1713 tk 213
  seq_ui_sent_cc_track = 0xff; // invalidate
214
 
167 tk 215
  // change to edit page
216
  ui_page = SEQ_UI_PAGE_NONE;
217
  SEQ_UI_PageSet(SEQ_UI_PAGE_EDIT);
134 tk 218
 
1203 tk 219
  // finally init bookmarks
220
  ui_page_before_bookmark = SEQ_UI_PAGE_EDIT;
221
  for(i=0; i<SEQ_UI_BOOKMARKS_NUM; ++i) {
222
    char buffer[10];
223
    seq_ui_bookmark_t *bm = (seq_ui_bookmark_t *)&seq_ui_bookmarks[i];
596 tk 224
 
1203 tk 225
    sprintf(buffer, "BM%2d ", i+1);
226
    memcpy((char *)bm->name, buffer, 6);
227
    bm->enable.ALL = ~0;
228
    bm->flags.LOCKED = 0;
229
    SEQ_UI_Bookmark_Store(i);
230
  }
231
 
134 tk 232
  return 0; // no error
233
}
234
 
235
 
236
/////////////////////////////////////////////////////////////////////////////
178 tk 237
// Inits the speed mode of all encoders
238
// Auto mode should be used whenever:
239
//    - the edit screen is entered
240
//    - the group is changed
241
//    - a track is changed
242
//    - a layer is changed
243
/////////////////////////////////////////////////////////////////////////////
244
s32 SEQ_UI_InitEncSpeed(u32 auto_config)
245
{
246
  mios32_enc_config_t enc_config;
247
 
248
  if( auto_config ) {
513 tk 249
 
250
    if( !seq_hwcfg_enc.auto_fast )
251
      return 0; // auto mode not enabled - ignore auto reconfiguration request
252
 
333 tk 253
    switch( SEQ_PAR_AssignmentGet(SEQ_UI_VisibleTrackGet(), ui_selected_par_layer) ) {
254
      case SEQ_PAR_Type_Velocity:
255
      case SEQ_PAR_Type_Length:
256
      case SEQ_PAR_Type_CC:
257
      case SEQ_PAR_Type_PitchBend:
258
      case SEQ_PAR_Type_Probability:
259
      case SEQ_PAR_Type_Delay:
1422 tk 260
      case SEQ_PAR_Type_ProgramChange:
1420 tk 261
        seq_ui_button_state.FAST_ENCODERS = 1;
262
        break;
178 tk 263
 
264
      default:
1420 tk 265
        seq_ui_button_state.FAST_ENCODERS = 0;
178 tk 266
    }
267
  }
268
 
269
  // change for datawheel and GP encoders
270
  int enc;
1341 tk 271
  for(enc=0; enc<SEQ_HWCFG_NUM_ENCODERS; ++enc) {
178 tk 272
    enc_config = MIOS32_ENC_ConfigGet(enc);
1121 tk 273
    enc_config.cfg.speed = (seq_ui_button_state.FAST_ENCODERS || seq_ui_button_state.FAST2_ENCODERS) ? FAST : NORMAL;
1341 tk 274
    enc_config.cfg.speed_par =
275
        (enc == 0)  ? seq_hwcfg_enc.datawheel_fast_speed
276
      : (enc == 17) ? seq_hwcfg_enc.bpm_fast_speed
277
      : seq_hwcfg_enc.gp_fast_speed;
178 tk 278
    MIOS32_ENC_ConfigSet(enc, enc_config);
279
  }
280
 
281
  return 0; // no error
282
}
283
 
284
 
285
/////////////////////////////////////////////////////////////////////////////
167 tk 286
// Various installation routines for menu page LCD handlers
287
/////////////////////////////////////////////////////////////////////////////
168 tk 288
s32 SEQ_UI_InstallButtonCallback(void *callback)
167 tk 289
{
168 tk 290
  ui_button_callback = callback;
167 tk 291
  return 0; // no error
292
}
293
 
168 tk 294
s32 SEQ_UI_InstallEncoderCallback(void *callback)
167 tk 295
{
168 tk 296
  ui_encoder_callback = callback;
167 tk 297
  return 0; // no error
298
}
299
 
168 tk 300
s32 SEQ_UI_InstallLEDCallback(void *callback)
167 tk 301
{
168 tk 302
  ui_led_callback = callback;
167 tk 303
  return 0; // no error
304
}
305
 
168 tk 306
s32 SEQ_UI_InstallLCDCallback(void *callback)
167 tk 307
{
308
  ui_lcd_callback = callback;
309
  return 0; // no error
310
}
311
 
352 tk 312
s32 SEQ_UI_InstallExitCallback(void *callback)
313
{
314
  ui_exit_callback = callback;
315
  return 0; // no error
316
}
167 tk 317
 
752 tk 318
s32 SEQ_UI_InstallDelayedActionCallback(void *callback, u16 delay_mS, u32 parameter)
740 tk 319
{
752 tk 320
  // must be atomic
321
  MIOS32_IRQ_Disable();
322
  ui_delayed_action_parameter = parameter;
740 tk 323
  ui_delayed_action_callback = callback;
752 tk 324
  ui_delayed_action_ctr = delay_mS;
325
  MIOS32_IRQ_Enable();
740 tk 326
 
327
  return 0; // no error
328
}
329
 
330
s32 SEQ_UI_UnInstallDelayedActionCallback(void *callback)
331
{
752 tk 332
  // must be atomic
333
  MIOS32_IRQ_Disable();
740 tk 334
  if( ui_delayed_action_callback == callback )
335
    ui_delayed_action_callback = 0;
752 tk 336
  MIOS32_IRQ_Enable();
337
 
740 tk 338
  return 0; // no error
339
}
340
 
341
 
2041 tk 342
s32 SEQ_UI_InstallMIDIINCallback(void *callback)
343
{
344
  ui_midi_in_callback = callback;
345
  return 0; // no error
346
}
347
 
348
s32 SEQ_UI_NotifyMIDIINCallback(mios32_midi_port_t port, mios32_midi_package_t p)
349
{
350
  if( ui_midi_in_callback != NULL )
351
    return ui_midi_in_callback(port, p);
352
 
353
  return -1; // no callback install
354
}
355
 
356
 
167 tk 357
/////////////////////////////////////////////////////////////////////////////
358
// Change the menu page
359
/////////////////////////////////////////////////////////////////////////////
360
s32 SEQ_UI_PageSet(seq_ui_page_t page)
361
{
362
  if( page != ui_page ) {
352 tk 363
 
364
    // call page exit callback
365
    if( ui_exit_callback != NULL )
366
      ui_exit_callback();
367
 
2102 tk 368
    // disable store file which was maybe used in page (usually serviced by exit callback)
369
    ui_store_file_required = 0;
370
 
167 tk 371
    // disable hooks of previous page and request re-initialisation
318 tk 372
    portENTER_CRITICAL();
167 tk 373
    ui_page = page;
168 tk 374
    ui_button_callback = NULL;
375
    ui_encoder_callback = NULL;
376
    ui_led_callback = NULL;
167 tk 377
    ui_lcd_callback = NULL;
352 tk 378
    ui_exit_callback = NULL;
2041 tk 379
    ui_midi_in_callback = NULL;
740 tk 380
    ui_delayed_action_callback = NULL;
318 tk 381
    portEXIT_CRITICAL();
167 tk 382
 
1420 tk 383
    // always disable ALL button when changing page
384
    seq_ui_button_state.CHANGE_ALL_STEPS_SAME_VALUE = 0;
385
    seq_ui_button_state.CHANGE_ALL_STEPS = 0;
386
 
167 tk 387
    // request display initialisation
388
    seq_ui_display_init_req = 1;
389
  }
173 tk 390
 
306 tk 391
  // for MENU button:
1024 tk 392
  if( seq_hwcfg_button_beh.menu )
393
    seq_ui_button_state.MENU_PRESSED = 0; // MENU page selection finished
1420 tk 394
 
306 tk 395
  // first page has been selected - display new screen
396
  seq_ui_button_state.MENU_FIRST_PAGE_SELECTED = 1;
397
 
272 tk 398
  // for SEQ_UI_MENU which is accessible with EXIT button
399
  // remember the current selectable page
400
  if( ui_page >= SEQ_UI_FIRST_MENU_SELECTION_PAGE )
401
    ui_selected_page = ui_page;
402
 
184 tk 403
  return 0; // no error
167 tk 404
}
405
 
406
 
407
/////////////////////////////////////////////////////////////////////////////
1527 tk 408
// Local help functions for copy/paste/clear/undo operations
409
/////////////////////////////////////////////////////////////////////////////
2217 tk 410
void SEQ_UI_Msg_Track(char *line2)
1527 tk 411
{
1877 tk 412
  char buffer[40];
1527 tk 413
  u8 visible_track = SEQ_UI_VisibleTrackGet();
414
  sprintf(buffer, "Track G%dT%d", 1 + (visible_track / 4), 1 + (visible_track % 4));
415
  SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, buffer, line2);
416
}
417
 
2448 tk 418
void SEQ_UI_Msg_Step(char *line2)
419
{
420
  char buffer[40];
421
  u8 visible_track = SEQ_UI_VisibleTrackGet();
422
  sprintf(buffer, "Step G%dT%d #%d", 1 + (visible_track / 4), 1 + (visible_track % 4), ui_selected_step + 1);
423
  SEQ_UI_Msg(((ui_selected_step % 16) < 8) ? SEQ_UI_MSG_USER_R : SEQ_UI_MSG_USER, 1000, buffer, line2);
424
}
425
 
2217 tk 426
void SEQ_UI_Msg_Layer(char *line2)
1877 tk 427
{
428
  char buffer[20];
429
  u8 visible_track = SEQ_UI_VisibleTrackGet();
430
  u8 event_mode = SEQ_CC_Get(SEQ_UI_VisibleTrackGet(), SEQ_CC_MIDI_EVENT_MODE);
431
  if( event_mode == SEQ_EVENT_MODE_Drum ) {
432
    sprintf(buffer, "Layer G%dT%d.I%d", 1 + (visible_track / 4), 1 + (visible_track % 4), ui_selected_instrument+1);
433
  } else {
434
    sprintf(buffer, "Layer G%dT%d.P%c", 1 + (visible_track / 4), 1 + (visible_track % 4), 'A'+ui_selected_par_layer);
435
  }
436
  SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, buffer, line2);
437
}
438
 
2217 tk 439
void SEQ_UI_Msg_MixerMap(char *line2)
1527 tk 440
{
441
  char buffer[20];
442
  sprintf(buffer, "Mixer Map #%d", SEQ_MIXER_NumGet()+1);
443
  SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, buffer, line2);
444
}
445
 
2524 tk 446
void SEQ_UI_Msg_Patterns(char *line2)
447
{
448
  char buffer[40];
449
  sprintf(buffer, "Patterns %d:%c%c %d:%c%c %d:%c%c %d:%c%c",
450
      seq_pattern[0].bank+1, 'A' + seq_pattern[0].group + (seq_pattern[0].lower ? 32 : 0), '1' + seq_pattern[0].num,
451
      seq_pattern[1].bank+1, 'A' + seq_pattern[1].group + (seq_pattern[1].lower ? 32 : 0), '1' + seq_pattern[1].num,
452
      seq_pattern[2].bank+1, 'A' + seq_pattern[2].group + (seq_pattern[2].lower ? 32 : 0), '1' + seq_pattern[2].num,
453
      seq_pattern[3].bank+1, 'A' + seq_pattern[3].group + (seq_pattern[3].lower ? 32 : 0), '1' + seq_pattern[3].num);
454
  SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, buffer, line2);
455
}
456
 
2217 tk 457
void SEQ_UI_Msg_SongPos(char *line2)
1527 tk 458
{
459
  char buffer[20];
460
  sprintf(buffer, "Song Position %c%d", 'A' + (ui_song_edit_pos >> 3), (ui_song_edit_pos&7)+1);
461
  SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, buffer, line2);
462
}
463
 
2217 tk 464
void SEQ_UI_Msg_LivePattern(char *line2)
2148 tk 465
{
466
  char buffer[20];
1527 tk 467
 
2154 tk 468
  seq_live_pattern_slot_t *slot = SEQ_LIVE_CurrentSlotGet();
2148 tk 469
  sprintf(buffer, "Live Pattern #%d", slot->pattern + 1);
470
  SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, buffer, line2);
471
}
472
 
473
 
1527 tk 474
/////////////////////////////////////////////////////////////////////////////
134 tk 475
// Dedicated button functions
476
// Mapped to physical buttons in SEQ_UI_Button_Handler()
477
// Will also be mapped to MIDI keys later (for MIDI remote function)
478
/////////////////////////////////////////////////////////////////////////////
479
static s32 SEQ_UI_Button_GP(s32 depressed, u32 gp)
480
{
1044 tk 481
  // in MENU page: overrule GP buttons as long as MENU button is pressed/active
1675 tk 482
  if( seq_ui_button_state.MENU_PRESSED || seq_hwcfg_blm.gp_always_select_menu_page ) {
306 tk 483
    if( depressed ) return -1;
2039 tk 484
    SEQ_UI_PageSet(SEQ_UI_PAGES_MenuShortcutPageGet(gp));
306 tk 485
  } else {
1319 tk 486
    if( depressed )
487
      ui_selected_gp_buttons &= ~(1 << gp);
488
    else
489
      ui_selected_gp_buttons |= (1 << gp);
490
 
306 tk 491
    // forward to menu page
740 tk 492
    if( ui_button_callback != NULL ) {
306 tk 493
      ui_button_callback(gp, depressed);
2502 tk 494
      ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0; // ensure that value is visible when it has been changed
740 tk 495
    }
306 tk 496
  }
134 tk 497
 
498
  return 0; // no error
499
}
500
 
501
static s32 SEQ_UI_Button_Left(s32 depressed)
502
{
168 tk 503
  // forward to menu page
740 tk 504
  if( !seq_ui_button_state.MENU_PRESSED && ui_button_callback != NULL ) {
168 tk 505
    ui_button_callback(SEQ_UI_BUTTON_Left, depressed);
740 tk 506
    ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0;
507
  }
134 tk 508
 
509
  return 0; // no error
510
}
511
 
512
static s32 SEQ_UI_Button_Right(s32 depressed)
513
{
168 tk 514
  // forward to menu page
740 tk 515
  if( !seq_ui_button_state.MENU_PRESSED && ui_button_callback != NULL ) {
168 tk 516
    ui_button_callback(SEQ_UI_BUTTON_Right, depressed);
740 tk 517
    ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0;
518
  }
134 tk 519
 
520
  return 0; // no error
521
}
522
 
168 tk 523
static s32 SEQ_UI_Button_Down(s32 depressed)
524
{
240 tk 525
  seq_ui_button_state.DOWN = depressed ? 0 : 1;
526
 
168 tk 527
  // forward to menu page
740 tk 528
  if( !seq_ui_button_state.MENU_PRESSED && ui_button_callback != NULL ) {
168 tk 529
    ui_button_callback(SEQ_UI_BUTTON_Down, depressed);
740 tk 530
    ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0;
531
  }
168 tk 532
 
533
  return 0; // no error
534
}
535
 
536
static s32 SEQ_UI_Button_Up(s32 depressed)
537
{
240 tk 538
  seq_ui_button_state.UP = depressed ? 0 : 1;
539
 
168 tk 540
  // forward to menu page
740 tk 541
  if( !seq_ui_button_state.MENU_PRESSED && ui_button_callback != NULL ) {
168 tk 542
    ui_button_callback(SEQ_UI_BUTTON_Up, depressed);
740 tk 543
    ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0;
544
  }
168 tk 545
 
546
  return 0; // no error
547
}
548
 
1068 tk 549
s32 SEQ_UI_Button_Stop(s32 depressed)
134 tk 550
{
551
  if( depressed ) return -1; // ignore when button depressed
552
 
159 tk 553
  // if sequencer running: stop it
554
  // if sequencer already stopped: reset song position
1206 tk 555
  if( SEQ_BPM_IsRunning() ) {
556
#if 0
557
    // TK: maybe to complicated to understand: STOP sequencer in slave mode if stop button pressed twice
558
    u8 enable_slaveclk_mute = !SEQ_BPM_IsMaster() && seq_core_slaveclk_mute != SEQ_CORE_SLAVECLK_MUTE_Enabled;
559
#else
560
    // always mute tracks, never stop sequencer (can only be done from external)
561
    u8 enable_slaveclk_mute = !SEQ_BPM_IsMaster();
562
#endif
563
    if( enable_slaveclk_mute ) {
564
      seq_core_slaveclk_mute = SEQ_CORE_SLAVECLK_MUTE_Enabled;
565
    } else {
566
      seq_core_slaveclk_mute = SEQ_CORE_SLAVECLK_MUTE_Off;
567
      SEQ_BPM_Stop();
568
    }
569
  } else {
570
    seq_core_slaveclk_mute = SEQ_CORE_SLAVECLK_MUTE_Off;
1145 tk 571
    SEQ_SONG_Reset(0);
572
    SEQ_CORE_Reset(0);
759 tk 573
    SEQ_MIDPLY_Reset();
574
  }
159 tk 575
 
2092 tk 576
  seq_play_timer.seconds = 0;
1454 midilab 577
 
134 tk 578
  return 0; // no error
579
}
580
 
581
static s32 SEQ_UI_Button_Pause(s32 depressed)
582
{
583
  if( depressed ) return -1; // ignore when button depressed
584
 
1206 tk 585
  // if in auto mode and BPM generator is not clocked in slave mode:
193 tk 586
  // change to master mode
587
  SEQ_BPM_CheckAutoMaster();
159 tk 588
 
1206 tk 589
  // toggle pause
193 tk 590
  ui_seq_pause ^= 1;
591
 
592
  // execute stop/continue depending on new mode
1206 tk 593
  MIOS32_IRQ_Disable();
594
  if( ui_seq_pause ) {
595
    if( !SEQ_BPM_IsMaster() ) {
596
      seq_core_slaveclk_mute = SEQ_CORE_SLAVECLK_MUTE_Enabled;
597
    } else {
598
      SEQ_BPM_Stop();
599
    }
600
  } else {
601
    if( !SEQ_BPM_IsMaster() ) {
602
      seq_core_slaveclk_mute = SEQ_CORE_SLAVECLK_MUTE_Off;
603
    }
193 tk 604
 
1206 tk 605
    if( !SEQ_BPM_IsRunning() )
606
      SEQ_BPM_Cont();
607
  }
608
  MIOS32_IRQ_Enable();
609
 
134 tk 610
  return 0; // no error
611
}
612
 
1068 tk 613
s32 SEQ_UI_Button_Play(s32 depressed)
134 tk 614
{
615
  if( depressed ) return -1; // ignore when button depressed
616
 
1090 tk 617
  // if MENU button pressed -> tap tempo
618
  if( seq_ui_button_state.MENU_PRESSED )
619
    return SEQ_UI_BPM_TapTempo();
620
 
1206 tk 621
  // if in auto mode and BPM generator is not clocked in slave mode:
186 tk 622
  // change to master mode
623
  SEQ_BPM_CheckAutoMaster();
624
 
1206 tk 625
  // slave mode and tracks muted: enable on next measure
626
  if( !SEQ_BPM_IsMaster() && SEQ_BPM_IsRunning() ) {
627
    if( seq_core_slaveclk_mute != SEQ_CORE_SLAVECLK_MUTE_Off )
628
      seq_core_slaveclk_mute = SEQ_CORE_SLAVECLK_MUTE_OffOnNextMeasure;
629
    // TK: note - in difference to master mode pressing PLAY twice won't reset the sequencer!
630
  } else {
2092 tk 631
    // send program change & bank selects
632
    MUTEX_MIDIOUT_TAKE;
633
    u8 track;
634
    for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track)
635
      SEQ_LAYER_SendPCBankValues(track, 0, 1);
636
    MUTEX_MIDIOUT_GIVE;
637
 
193 tk 638
#if 0
1206 tk 639
    // if sequencer running: restart it
640
    // if sequencer stopped: continue at last song position
641
    if( SEQ_BPM_IsRunning() )
642
      SEQ_BPM_Start();
643
    else
644
      SEQ_BPM_Cont();
645
#else
646
    // always restart sequencer
647
    seq_core_slaveclk_mute = SEQ_CORE_SLAVECLK_MUTE_Off;
193 tk 648
    SEQ_BPM_Start();
186 tk 649
#endif
1206 tk 650
  }
159 tk 651
 
2250 tk 652
  seq_play_timer = MIOS32_SYS_TimeGet();
1454 midilab 653
 
134 tk 654
  return 0; // no error
655
}
656
 
657
static s32 SEQ_UI_Button_Rew(s32 depressed)
658
{
240 tk 659
  seq_ui_button_state.REW = depressed ? 0 : 1;
660
 
134 tk 661
  if( depressed ) return -1; // ignore when button depressed
662
 
607 tk 663
  if( SEQ_SONG_ActiveGet() ) {
664
    portENTER_CRITICAL();
665
    SEQ_SONG_Rew();
666
    portEXIT_CRITICAL();
1713 tk 667
  } else {
668
    //SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "We are not", "in Song Mode!");
669
    SEQ_UI_Button_StepViewDec(depressed);
670
  }
607 tk 671
 
134 tk 672
  return 0; // no error
673
}
674
 
675
static s32 SEQ_UI_Button_Fwd(s32 depressed)
676
{
240 tk 677
  seq_ui_button_state.FWD = depressed ? 0 : 1;
678
 
134 tk 679
  if( depressed ) return -1; // ignore when button depressed
680
 
607 tk 681
  if( SEQ_SONG_ActiveGet() ) {
682
    portENTER_CRITICAL();
683
    SEQ_SONG_Fwd();
684
    portEXIT_CRITICAL();
1713 tk 685
  } else {
686
    //SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "We are not", "in Song Mode!");
687
    SEQ_UI_Button_StepViewInc(depressed);
688
  }
607 tk 689
 
134 tk 690
  return 0; // no error
691
}
692
 
596 tk 693
static s32 SEQ_UI_Button_Loop(s32 depressed)
694
{
695
  if( seq_hwcfg_button_beh.loop ) {
696
    // toggle mode
697
    if( depressed ) return -1; // ignore when button depressed
698
    // should be atomic
699
    portENTER_CRITICAL();
700
    seq_core_state.LOOP ^= 1;
701
  } else {
702
    // should be atomic
703
    portENTER_CRITICAL();
704
    // set mode
705
    seq_core_state.LOOP = depressed ? 0 : 1;
706
  }
707
  portEXIT_CRITICAL();
708
 
709
  SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Loop Mode", seq_core_state.LOOP ? "    on" : "   off");
710
 
711
  return 0; // no error
712
}
713
 
951 tk 714
static s32 SEQ_UI_Button_Follow(s32 depressed)
715
{
716
  if( seq_hwcfg_button_beh.follow ) {
717
    // toggle mode
718
    if( depressed ) return -1; // ignore when button depressed
719
    // should be atomic
720
    portENTER_CRITICAL();
721
    seq_core_state.FOLLOW ^= 1;
722
  } else {
723
    // should be atomic
724
    portENTER_CRITICAL();
725
    // set mode
726
    seq_core_state.FOLLOW = depressed ? 0 : 1;
727
  }
728
  portEXIT_CRITICAL();
729
 
730
  SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Follow Mode", seq_core_state.FOLLOW ? "    on" : "   off");
731
 
732
  return 0; // no error
733
}
734
 
596 tk 735
static s32 SEQ_UI_Button_Scrub(s32 depressed)
736
{
737
  // double function: -> Loop if menu button pressed
738
  if( seq_ui_button_state.MENU_PRESSED )
739
    return SEQ_UI_Button_Loop(depressed);
740
 
741
  if( seq_hwcfg_button_beh.scrub ) {
742
    // toggle mode
743
    if( depressed ) return -1; // ignore when button depressed
744
    seq_ui_button_state.SCRUB ^= 1;
745
  } else {
746
    // set mode
747
    seq_ui_button_state.SCRUB = depressed ? 0 : 1;
748
  }
749
 
750
  SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Scrub Mode", seq_ui_button_state.SCRUB ? "    on" : "   off");
751
 
752
  return 0; // no error
753
}
754
 
513 tk 755
static s32 SEQ_UI_Button_TempoPreset(s32 depressed)
134 tk 756
{
513 tk 757
  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
240 tk 758
 
513 tk 759
  if( seq_hwcfg_button_beh.tempo_preset ) {
760
    if( depressed ) return -1; // ignore when button depressed
678 tk 761
    if( !seq_ui_button_state.TEMPO_PRESET ) // due to page change: button going to be set, clear other toggle buttons
762
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 763
    seq_ui_button_state.TEMPO_PRESET ^= 1; // toggle TEMPO_PRESET pressed (will also be released once GP button has been pressed)
764
  } else {
765
    // set mode
766
    seq_ui_button_state.TEMPO_PRESET = depressed ? 0 : 1;
767
  }
134 tk 768
 
513 tk 769
  if( seq_ui_button_state.TEMPO_PRESET ) {
770
    prev_page = ui_page;
771
    SEQ_UI_PageSet(SEQ_UI_PAGE_BPM_PRESETS);
772
  } else {
524 tk 773
    if( ui_page == SEQ_UI_PAGE_BPM_PRESETS )
774
      SEQ_UI_PageSet(prev_page);
513 tk 775
  }
240 tk 776
 
134 tk 777
  return 0; // no error
778
}
779
 
513 tk 780
static s32 SEQ_UI_Button_TapTempo(s32 depressed)
134 tk 781
{
513 tk 782
  seq_ui_button_state.TAP_TEMPO = depressed ? 0 : 1;
240 tk 783
 
134 tk 784
  if( depressed ) return -1; // ignore when button depressed
785
 
1142 tk 786
  return SEQ_UI_BPM_TapTempo();
134 tk 787
}
788
 
524 tk 789
static s32 SEQ_UI_Button_ExtRestart(s32 depressed)
134 tk 790
{
791
  if( depressed ) return -1; // ignore when button depressed
792
 
596 tk 793
  // should be atomic
524 tk 794
  portENTER_CRITICAL();
795
  seq_core_state.EXT_RESTART_REQ = 1;
796
  portEXIT_CRITICAL();
797
 
596 tk 798
  SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "External Restart", "requested");
799
 
134 tk 800
  return 0; // no error
801
}
802
 
596 tk 803
static s32 SEQ_UI_Button_Metronome(s32 depressed)
804
{
805
  // double function: -> ExtRestart if menu button pressed
806
  if( seq_ui_button_state.MENU_PRESSED )
807
    return SEQ_UI_Button_ExtRestart(depressed);
808
 
809
  if( seq_hwcfg_button_beh.metronome ) {
810
    // toggle mode
811
    if( depressed ) return -1; // ignore when button depressed
812
    // should be atomic
813
    portENTER_CRITICAL();
814
    seq_core_state.METRONOME ^= 1;
815
  } else {
816
    // should be atomic
817
    portENTER_CRITICAL();
818
    // set mode
819
    seq_core_state.METRONOME = depressed ? 0 : 1;
820
  }
821
  portEXIT_CRITICAL();
822
 
823
  SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Metronome", seq_core_state.METRONOME ? "    on" : "   off");
824
 
599 tk 825
#if 0
826
  // metronome button can be used to trigger pattern file fixes
827
  if( !depressed )
828
    SEQ_PATTERN_FixAll();
829
#endif
830
 
596 tk 831
  return 0; // no error
832
}
833
 
2448 tk 834
s32 SEQ_UI_Button_Record(s32 depressed)
630 tk 835
{
836
  if( depressed ) return -1; // ignore when button depressed
837
 
2322 tk 838
  // enable/disable recording
839
  SEQ_RECORD_Enable(seq_record_state.ENABLED ? 0 : 1, 1);
840
 
2324 tk 841
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R,
842
         1000,
843
         seq_record_options.STEP_RECORD ? "Step Recording" : "Live Recording",
844
         seq_record_state.ENABLED ? "      on" : "     off");
845
 
2322 tk 846
  return 0; // no error
847
}
848
 
849
static s32 SEQ_UI_Button_JamLive(s32 depressed)
850
{
851
  if( depressed ) return -1; // ignore when button depressed
852
 
853
  // enable live recording
2324 tk 854
  SEQ_UI_TRKJAM_RecordModeSet(0);
2322 tk 855
 
2166 tk 856
  // change to record page
857
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKJAM);
630 tk 858
 
859
  return 0; // no error
860
}
861
 
2322 tk 862
static s32 SEQ_UI_Button_JamStep(s32 depressed)
863
{
864
  if( depressed ) return -1; // ignore when button depressed
865
 
866
  // enable step recording
2324 tk 867
  SEQ_UI_TRKJAM_RecordModeSet(1);
2322 tk 868
 
869
  // change to record page
870
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKJAM);
871
 
872
  return 0; // no error
873
}
874
 
1219 tk 875
static s32 SEQ_UI_Button_Live(s32 depressed)
876
{
877
  if( depressed ) return -1; // ignore when button depressed
878
 
2322 tk 879
  // switch live mode
880
  seq_record_options.FWD_MIDI = seq_record_options.FWD_MIDI ? 0 : 1;
1219 tk 881
 
2324 tk 882
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R,
883
         1000,
884
         "Live Forwarding",
885
         seq_record_options.FWD_MIDI ? "      on" : "     off");
886
 
1219 tk 887
  return 0; // no error
888
}
889
 
134 tk 890
static s32 SEQ_UI_Button_Utility(s32 depressed)
891
{
892
  if( depressed ) return -1; // ignore when button depressed
893
 
240 tk 894
  // change to utility page
895
  SEQ_UI_PageSet(SEQ_UI_PAGE_UTIL);
896
 
134 tk 897
  return 0; // no error
898
}
899
 
900
static s32 SEQ_UI_Button_Copy(s32 depressed)
901
{
240 tk 902
  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
134 tk 903
 
240 tk 904
  seq_ui_button_state.COPY = depressed ? 0 : 1;
905
 
280 tk 906
  if( ui_page == SEQ_UI_PAGE_MIXER ) {
907
    if( depressed ) return -1;
908
    SEQ_UI_MIXER_Copy();
1527 tk 909
    SEQ_UI_Msg_MixerMap("copied");
280 tk 910
    return 1;
2524 tk 911
  } else if( ui_page == SEQ_UI_PAGE_PATTERN || ui_page == SEQ_UI_PAGE_PATTERN_RMX ) {
912
    if( depressed ) return -1;
913
    if( SEQ_UI_PATTERN_MultiCopy(0) >= 0 )
914
      SEQ_UI_Msg_Patterns("copied");
915
    return 1;
729 tk 916
  } else if( ui_page == SEQ_UI_PAGE_SONG ) {
917
    if( depressed ) return -1;
918
    SEQ_UI_SONG_Copy();
1527 tk 919
    SEQ_UI_Msg_SongPos("copied");
729 tk 920
    return 1;
2164 tk 921
  } else if( SEQ_UI_TRKJAM_PatternRecordSelected() ) {
2148 tk 922
    if( depressed ) return -1;
923
    SEQ_UI_UTIL_CopyLivePattern();
924
    SEQ_UI_Msg_LivePattern("copied");
925
    return 1;
280 tk 926
  } else {
2525 tk 927
    if( seq_ui_button_state.MENU_PRESSED ) {
2524 tk 928
      if( depressed ) return 1;
929
      SEQ_UI_PATTERN_MultiCopy(1);
930
      return 1;
1877 tk 931
    }
932
 
280 tk 933
    if( !depressed ) {
934
      prev_page = ui_page;
935
      SEQ_UI_PageSet(SEQ_UI_PAGE_UTIL);
936
    }
2197 tk 937
 
938
    s32 status = 1;
939
    status = SEQ_UI_UTIL_CopyButton(depressed);
240 tk 940
 
596 tk 941
    if( depressed ) {
942
      if( prev_page != SEQ_UI_PAGE_UTIL )
943
    SEQ_UI_PageSet(prev_page);
2197 tk 944
 
1527 tk 945
      SEQ_UI_Msg_Track("copied");
596 tk 946
    }
947
 
280 tk 948
    return status;
949
  }
134 tk 950
}
951
 
952
static s32 SEQ_UI_Button_Paste(s32 depressed)
953
{
240 tk 954
  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
134 tk 955
 
240 tk 956
  seq_ui_button_state.PASTE = depressed ? 0 : 1;
957
 
280 tk 958
  if( ui_page == SEQ_UI_PAGE_MIXER ) {
959
    if( depressed ) return -1;
960
    SEQ_UI_MIXER_Paste();
1527 tk 961
    SEQ_UI_Msg_MixerMap("pasted");
280 tk 962
    return 1;
2524 tk 963
  } else if( ui_page == SEQ_UI_PAGE_PATTERN || ui_page == SEQ_UI_PAGE_PATTERN_RMX ) {
964
    if( depressed ) return -1;
965
    if( seq_ui_button_state.COPY ) {
966
      // copy+paste pressed: paste to next pattern position
967
      portENTER_CRITICAL();
968
      int group;
969
      for(group=0; group<SEQ_CORE_NUM_GROUPS; ++group) {
970
    if( seq_pattern[group].pattern < 63 )
971
      ++seq_pattern[group].pattern;
972
    seq_pattern[group].REQ = 0;
973
    seq_pattern_req[group] = seq_pattern[group];
974
      }
975
      portEXIT_CRITICAL();
976
    }
977
 
978
    if( SEQ_UI_PATTERN_MultiPaste(0) >= 0 )
979
      SEQ_UI_Msg_Patterns("pasted");
980
    return 1;
729 tk 981
  } else if( ui_page == SEQ_UI_PAGE_SONG ) {
982
    if( depressed ) return -1;
983
    SEQ_UI_SONG_Paste();
1527 tk 984
    SEQ_UI_Msg_SongPos("pasted");
729 tk 985
    return 1;
2164 tk 986
  } else if( SEQ_UI_TRKJAM_PatternRecordSelected() ) {
2148 tk 987
    if( depressed ) return -1;
988
    SEQ_UI_UTIL_PasteLivePattern();
989
    SEQ_UI_Msg_LivePattern("pasted");
990
    return 1;
280 tk 991
  } else {
2525 tk 992
    if( seq_ui_button_state.MENU_PRESSED ) {
2524 tk 993
      if( depressed ) return 1;
994
      SEQ_UI_PATTERN_MultiPaste(1);
995
      return 1;
1877 tk 996
    }
997
 
2197 tk 998
    if( seq_ui_button_state.COPY ) {
999
      // copy+paste pressed: duplicate steps
1000
      if( !depressed ) {
1001
    u8 visible_track = SEQ_UI_VisibleTrackGet();
1002
    if( SEQ_UI_UTIL_PasteDuplicateSteps(visible_track) >= 1 ) {
1003
      SEQ_UI_Msg_Track("steps duplicated");
1004
    } else {
1005
      SEQ_UI_Msg_Track("full - no duplication!");
1006
    }
1007
      }
1008
 
1009
      return 1;
1010
    }
1011
 
280 tk 1012
    if( !depressed ) {
1013
      prev_page = ui_page;
1014
      SEQ_UI_PageSet(SEQ_UI_PAGE_UTIL);
1015
    }
240 tk 1016
 
280 tk 1017
    s32 status = SEQ_UI_UTIL_PasteButton(depressed);
596 tk 1018
    if( depressed ) {
1019
      if( prev_page != SEQ_UI_PAGE_UTIL )
1020
    SEQ_UI_PageSet(prev_page);
240 tk 1021
 
1877 tk 1022
      if( seq_ui_button_state.SELECT_PRESSED )
1023
    SEQ_UI_Msg_Layer("pasted");
1024
      else
1025
    SEQ_UI_Msg_Track("pasted");
596 tk 1026
    }
1027
 
280 tk 1028
    return status;
1029
  }
134 tk 1030
}
1031
 
740 tk 1032
 
134 tk 1033
static s32 SEQ_UI_Button_Clear(s32 depressed)
1034
{
240 tk 1035
  seq_ui_button_state.CLEAR = depressed ? 0 : 1;
280 tk 1036
 
1037
  if( ui_page == SEQ_UI_PAGE_MIXER ) {
2448 tk 1038
    if( !depressed ) {
1039
      SEQ_UI_MIXER_Clear();
1040
      SEQ_UI_Msg_MixerMap("cleared");
752 tk 1041
    }
2525 tk 1042
  } else if( ui_page == SEQ_UI_PAGE_PATTERN || ui_page == SEQ_UI_PAGE_PATTERN_RMX ) {
1043
    if( depressed ) return -1;
1044
    if( SEQ_UI_PATTERN_MultiClear(0) >= 0 )
1045
      SEQ_UI_Msg_Patterns("cleared");
1046
    return 1;
729 tk 1047
  } else if( ui_page == SEQ_UI_PAGE_SONG ) {
2448 tk 1048
    if( !depressed ) {
1049
      SEQ_UI_SONG_Clear();
1050
      SEQ_UI_Msg_SongPos("cleared");
752 tk 1051
    }
2164 tk 1052
  } else if( SEQ_UI_TRKJAM_PatternRecordSelected() ) {
2448 tk 1053
    if( !depressed ) {
1054
      SEQ_UI_UTIL_ClearLivePattern();
1055
      SEQ_UI_Msg_LivePattern("cleared");
2148 tk 1056
    }
2448 tk 1057
  } else if( ui_page == SEQ_UI_PAGE_TRKJAM ) {
1058
    if( !depressed ) {
1059
      SEQ_UI_UTIL_ClearStep(SEQ_UI_VisibleTrackGet(), ui_selected_step, ui_selected_instrument);
1060
 
1061
      if( seq_record_state.ENABLED && !seq_record_options.STEP_RECORD ) {
1062
    SEQ_UI_Msg(((ui_selected_step % 16) < 8) ? SEQ_UI_MSG_USER_R : SEQ_UI_MSG_USER, 1000, "Hold key to", "clear steps");
1063
      } else {
1064
    SEQ_UI_Msg_Step("cleared");
1065
      }
1066
 
1067
      // print edit screen for 2 seconds
1068
      ui_hold_msg_ctr = 2000;
1069
      ui_hold_msg_ctr_drum_edit = 0; // ensure that drum triggers are displayed
1070
      seq_ui_display_update_req = 1;
1071
    }
729 tk 1072
  } else {
2525 tk 1073
    if( seq_ui_button_state.MENU_PRESSED ) {
1074
      if( depressed ) return 1;
1075
      SEQ_UI_PATTERN_MultiClear(1);
1076
      return 1;
1077
    }
1078
 
2448 tk 1079
    if( !depressed ) {
1080
      SEQ_UI_UTIL_ClearButton(0); // button pressed
1081
      SEQ_UI_UTIL_ClearButton(1); // button depressed
1082
      if( seq_ui_button_state.SELECT_PRESSED )
1083
    SEQ_UI_Msg_Layer("cleared");
1084
      else
1085
    SEQ_UI_Msg_Track("cleared");
752 tk 1086
    }
280 tk 1087
  }
2448 tk 1088
 
1089
  return 1;
134 tk 1090
}
1091
 
1014 tk 1092
 
1093
static s32 SEQ_UI_Button_Undo(s32 depressed)
1094
{
1095
  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
1096
 
1097
  seq_ui_button_state.UNDO = depressed ? 0 : 1;
1098
 
1099
  if( ui_page == SEQ_UI_PAGE_MIXER ) {
1100
    if( depressed ) return -1;
1101
    SEQ_UI_MIXER_Undo();
1527 tk 1102
    SEQ_UI_Msg_MixerMap("Undo applied");
1014 tk 1103
    return 1;
1104
  } else {
1105
    if( !depressed ) {
1106
      prev_page = ui_page;
1107
      SEQ_UI_PageSet(SEQ_UI_PAGE_UTIL);
1108
    }
1109
 
1110
    s32 status = SEQ_UI_UTIL_UndoButton(depressed);
1111
 
1112
    if( depressed ) {
1113
      if( prev_page != SEQ_UI_PAGE_UTIL )
1114
    SEQ_UI_PageSet(prev_page);
1115
 
1527 tk 1116
      SEQ_UI_Msg_Track("Undo applied");
1014 tk 1117
    }
1118
 
1119
    return status;
1120
  }
1121
}
1122
 
2308 tk 1123
static s32 SEQ_UI_Button_Move(s32 depressed)
1124
{
1125
  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
1014 tk 1126
 
2308 tk 1127
  seq_ui_button_state.MOVE = depressed ? 0 : 1;
1128
 
1129
  if( !depressed ) {
1130
    prev_page = ui_page;
1131
    SEQ_UI_PageSet(SEQ_UI_PAGE_UTIL);
1132
  }
1133
 
1134
  s32 status = SEQ_UI_UTIL_MoveButton(depressed);
1135
  if( depressed ) {
1136
    if( prev_page != SEQ_UI_PAGE_UTIL )
1137
      SEQ_UI_PageSet(prev_page);
1138
  }
1139
 
1140
  return status;
1141
}
1142
 
1143
static s32 SEQ_UI_Button_Scroll(s32 depressed)
1144
{
1145
  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
1146
 
1147
  seq_ui_button_state.SCROLL = depressed ? 0 : 1;
1148
 
1149
  if( !depressed ) {
1150
    prev_page = ui_page;
1151
    SEQ_UI_PageSet(SEQ_UI_PAGE_UTIL);
1152
  }
1153
 
1154
  s32 status = SEQ_UI_UTIL_ScrollButton(depressed);
1155
  if( depressed ) {
1156
    if( prev_page != SEQ_UI_PAGE_UTIL )
1157
      SEQ_UI_PageSet(prev_page);
1158
  }
1159
 
1160
  return status;
1161
}
1162
 
1163
 
134 tk 1164
static s32 SEQ_UI_Button_Menu(s32 depressed)
1165
{
513 tk 1166
  if( seq_hwcfg_button_beh.menu ) {
1167
    // toggle mode
1168
    if( depressed ) return -1; // ignore when button depressed
1169
    seq_ui_button_state.MENU_FIRST_PAGE_SELECTED = 0;
678 tk 1170
    if( !seq_ui_button_state.MENU_PRESSED ) // due to page change: button going to be set, clear other toggle buttons
1171
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 1172
    seq_ui_button_state.MENU_PRESSED ^= 1; // toggle MENU pressed (will also be released once GP button has been pressed)
1173
  } else {
1174
    // set mode
1175
    seq_ui_button_state.MENU_FIRST_PAGE_SELECTED = 0;
1176
    seq_ui_button_state.MENU_PRESSED = depressed ? 0 : 1;
1177
  }
134 tk 1178
 
1179
  return 0; // no error
1180
}
1181
 
1203 tk 1182
 
1183
static s32 SEQ_UI_Button_Bookmark(s32 depressed)
1184
{
1185
  if( seq_hwcfg_button_beh.bookmark ) {
1186
    if( depressed ) return -1; // ignore when button depressed
1187
    if( !seq_ui_button_state.BOOKMARK ) // due to page change: button going to be set, clear other toggle buttons
1188
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
1189
#if 0
1190
    seq_ui_button_state.BOOKMARK ^= 1; // toggle BOOKMARK pressed (will also be released once GP button has been pressed)
1191
#else
1192
    seq_ui_button_state.BOOKMARK = 1; // seems that it's better *not* to toggle!
1193
#endif
1194
  } else {
1195
    // set mode
1196
    seq_ui_button_state.BOOKMARK = depressed ? 0 : 1;
1197
  }
1198
 
1199
  if( seq_ui_button_state.BOOKMARK ) {
1200
    if( ui_page != SEQ_UI_PAGE_BOOKMARKS )
1201
      ui_page_before_bookmark = ui_page;
1202
    SEQ_UI_PageSet(SEQ_UI_PAGE_BOOKMARKS);
1203
  } else {
1204
    if( ui_page == SEQ_UI_PAGE_BOOKMARKS )
1205
      SEQ_UI_PageSet(ui_page_before_bookmark);
1206
  }
1207
 
1208
  return 0; // no error
1209
}
1210
 
1211
 
1205 tk 1212
static s32 SEQ_UI_Button_DirectBookmark(s32 depressed, u32 bookmark_button)
1213
{
1214
  if( !depressed )
1215
    ui_page_before_bookmark = ui_page;
1216
 
1217
  return SEQ_UI_BOOKMARKS_Button_Handler(bookmark_button, depressed);
1218
}
1219
 
1220
 
134 tk 1221
static s32 SEQ_UI_Button_Select(s32 depressed)
1222
{
1203 tk 1223
  // double function: -> Bookmark if menu button pressed
1224
  if( seq_ui_button_state.MENU_PRESSED )
1225
    return SEQ_UI_Button_Bookmark(depressed);
1226
 
168 tk 1227
  // forward to menu page
1877 tk 1228
  seq_ui_button_state.SELECT_PRESSED = depressed ? 0 : 1;
1229
  if( ui_button_callback != NULL ) {
1230
    ui_button_callback(SEQ_UI_BUTTON_Select, depressed);
1231
    ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0;
591 tk 1232
  }
134 tk 1233
 
1234
  return 0; // no error
1235
}
1236
 
1237
static s32 SEQ_UI_Button_Exit(s32 depressed)
1238
{
951 tk 1239
  // double function: -> Follow if menu button pressed
1240
  if( seq_ui_button_state.MENU_PRESSED )
1241
    return SEQ_UI_Button_Follow(depressed);
1242
 
272 tk 1243
  if( depressed ) return -1; // ignore when button depressed
1244
 
1245
  u8 prev_ui_page = ui_page;
1246
 
168 tk 1247
  // forward to menu page
1123 tk 1248
  if( ui_button_callback != NULL ) {
1249
    if( ui_button_callback(SEQ_UI_BUTTON_Exit, depressed) >= 1 )
1250
      return 1; // page has already handled exit button
740 tk 1251
    ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0;
1252
  }
134 tk 1253
 
167 tk 1254
  // release all button states
984 tk 1255
  // seq_ui_button_state.ALL = 0;
1256
  // clashes with SOLO/ALL/etc.
167 tk 1257
 
272 tk 1258
  // enter menu page if we were not there before
1259
  if( prev_ui_page != SEQ_UI_PAGE_MENU )
1260
    SEQ_UI_PageSet(SEQ_UI_PAGE_MENU);
1261
 
134 tk 1262
  return 0; // no error
1263
}
1264
 
1265
static s32 SEQ_UI_Button_Edit(s32 depressed)
1266
{
741 tk 1267
  seq_ui_button_state.EDIT_PRESSED = depressed ? 0 : 1;
591 tk 1268
 
167 tk 1269
  // change to edit page
1350 tk 1270
  if( !depressed ) {
1271
    SEQ_UI_PageSet(SEQ_UI_PAGE_EDIT);
167 tk 1272
 
1350 tk 1273
    // set/clear encoder fast function if required
1274
    SEQ_UI_InitEncSpeed(1); // auto config
1275
  }
178 tk 1276
 
1350 tk 1277
  // EDIT button notification to button callback
1278
  // currently only used in EDIT page itself!
1279
  if( depressed && ui_page != SEQ_UI_PAGE_EDIT )
1280
    return -1;
1281
 
1282
  if( ui_button_callback != NULL ) {
1283
    ui_button_callback(SEQ_UI_BUTTON_Edit, depressed);
1284
    ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0;
1285
  }
1286
 
134 tk 1287
  return 0; // no error
1288
}
1289
 
1290
static s32 SEQ_UI_Button_Mute(s32 depressed)
1291
{
591 tk 1292
  seq_ui_button_state.MUTE_PRESSED = depressed ? 0 : 1;
1293
 
134 tk 1294
  if( depressed ) return -1; // ignore when button depressed
1295
 
184 tk 1296
  SEQ_UI_PageSet(SEQ_UI_PAGE_MUTE);
1297
 
134 tk 1298
  return 0; // no error
1299
}
1300
 
1301
static s32 SEQ_UI_Button_Pattern(s32 depressed)
1302
{
591 tk 1303
  seq_ui_button_state.PATTERN_PRESSED = depressed ? 0 : 1;
1304
 
134 tk 1305
  if( depressed ) return -1; // ignore when button depressed
1306
 
184 tk 1307
  SEQ_UI_PageSet(SEQ_UI_PAGE_PATTERN);
1308
 
134 tk 1309
  return 0; // no error
1310
}
1311
 
1454 midilab 1312
static s32 SEQ_UI_Button_Pattern_Remix(s32 depressed)
1313
{
1314
 
1315
    if ( ui_page == SEQ_UI_PAGE_PATTERN_RMX ) {
2161 tk 1316
#ifndef MIOS32_FAMILY_EMULATION
1454 midilab 1317
        // to avoid race conditions using the same button(any other way of solving that?)
1318
        vTaskDelay(60);
2161 tk 1319
#endif
1454 midilab 1320
        // a trick to use the same button with 2 functionalitys
1321
        ui_button_callback(SEQ_UI_BUTTON_Edit, depressed);
1322
    } else {
1323
        SEQ_UI_PageSet(SEQ_UI_PAGE_PATTERN_RMX);
1324
    }
1325
 
1326
    return 0; // no error
1327
 
1328
}
1329
 
134 tk 1330
static s32 SEQ_UI_Button_Song(s32 depressed)
1331
{
591 tk 1332
  seq_ui_button_state.SONG_PRESSED = depressed ? 0 : 1;
1333
 
134 tk 1334
  if( depressed ) return -1; // ignore when button depressed
1335
 
399 tk 1336
  SEQ_UI_PageSet(SEQ_UI_PAGE_SONG);
1337
 
134 tk 1338
  return 0; // no error
1339
}
1340
 
1341
static s32 SEQ_UI_Button_Solo(s32 depressed)
1342
{
513 tk 1343
  if( seq_hwcfg_button_beh.solo ) {
1344
    // toggle mode
1345
    if( depressed ) return -1; // ignore when button depressed
2110 tk 1346
    seq_ui_button_state.SOLO ^= 1;    
513 tk 1347
  } else {
1348
    // set mode
1349
    seq_ui_button_state.SOLO = depressed ? 0 : 1;
1350
  }
134 tk 1351
 
2110 tk 1352
  // seq_core_trk_soloed currently only used for the BLM16x16+X
1353
  // which overrules the legacy SOLO function
1354
  if( !seq_ui_button_state.SOLO )
1355
    seq_core_trk_soloed = 0;
1356
 
134 tk 1357
  return 0; // no error
1358
}
1359
 
1360
static s32 SEQ_UI_Button_Fast(s32 depressed)
1361
{
513 tk 1362
  if( seq_hwcfg_button_beh.fast ) {
1363
    // toggle mode
1364
    if( depressed ) return -1; // ignore when button depressed
1365
    seq_ui_button_state.FAST_ENCODERS ^= 1;
1366
  } else {
1367
    // set mode
1368
    seq_ui_button_state.FAST_ENCODERS = depressed ? 0 : 1;
1369
  }
134 tk 1370
 
178 tk 1371
  SEQ_UI_InitEncSpeed(0); // no auto config
1372
 
134 tk 1373
  return 0; // no error
1374
}
1375
 
1121 tk 1376
static s32 SEQ_UI_Button_Fast2(s32 depressed)
1377
{
1378
  if( seq_hwcfg_button_beh.fast2 ) {
1379
    // toggle mode
1380
    if( depressed ) return -1; // ignore when button depressed
1381
    seq_ui_button_state.FAST2_ENCODERS ^= 1;
1382
  } else {
1383
    // set mode
1384
    seq_ui_button_state.FAST2_ENCODERS = depressed ? 0 : 1;
1385
  }
1386
 
1387
  SEQ_UI_InitEncSpeed(0); // no auto config
1388
 
1389
  return 0; // no error
1390
}
1391
 
134 tk 1392
static s32 SEQ_UI_Button_All(s32 depressed)
1393
{
178 tk 1394
  seq_ui_button_state.CHANGE_ALL_STEPS_SAME_VALUE = depressed ? 0 : 1;
134 tk 1395
 
513 tk 1396
  if( seq_hwcfg_button_beh.all ) {
1397
    // toggle mode
1398
    if( depressed ) return -1;
1399
    seq_ui_button_state.CHANGE_ALL_STEPS ^= 1;
1400
  } else {
1401
    // set mode
1402
    seq_ui_button_state.CHANGE_ALL_STEPS = depressed ? 0 : 1;
1403
  }
178 tk 1404
 
134 tk 1405
  return 0; // no error
1406
}
1407
 
1408
static s32 SEQ_UI_Button_StepView(s32 depressed)
1409
{
600 tk 1410
  //  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
1411
  // also used by seq_ui_stepsel
1412
 
513 tk 1413
  if( seq_hwcfg_button_beh.step_view ) {
1414
    if( depressed ) return -1; // ignore when button depressed
678 tk 1415
    if( !seq_ui_button_state.STEP_VIEW ) // due to page change: button going to be set, clear other toggle buttons
1416
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 1417
    seq_ui_button_state.STEP_VIEW ^= 1; // toggle STEP_VIEW pressed (will also be released once GP button has been pressed)
1418
  } else {
1419
    // set mode
1420
    seq_ui_button_state.STEP_VIEW = depressed ? 0 : 1;
1421
  }
134 tk 1422
 
513 tk 1423
  if( seq_ui_button_state.STEP_VIEW ) {
600 tk 1424
    ui_stepview_prev_page = ui_page;
303 tk 1425
    SEQ_UI_PageSet(SEQ_UI_PAGE_STEPSEL);
1426
  } else {
524 tk 1427
    if( ui_page == SEQ_UI_PAGE_STEPSEL )
600 tk 1428
      SEQ_UI_PageSet(ui_stepview_prev_page);
303 tk 1429
  }
134 tk 1430
 
1431
  return 0; // no error
1432
}
1433
 
1713 tk 1434
static s32 SEQ_UI_Button_StepViewInc(s32 depressed)
1435
{
1436
  if( depressed ) return -1; // ignore when button depressed
1437
 
1438
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1439
  int num_steps = SEQ_TRG_NumStepsGet(visible_track);
1440
 
1441
  int new_step_view = ui_selected_step_view + 1;
1442
  if( (16*new_step_view) < num_steps ) {
1443
    // select new step view
1444
    ui_selected_step_view = new_step_view;
1445
 
1446
    // select step within view
1751 tk 1447
    if( !seq_ui_button_state.CHANGE_ALL_STEPS ) { // don't change the selected step if ALL function is active, otherwise the ramp can't be changed over multiple views
1448
      ui_selected_step = (ui_selected_step_view << 4) | (ui_selected_step & 0xf);
1449
    }
1713 tk 1450
  }
1451
 
1452
  char buffer[20];
1453
  sprintf(buffer, "%d-%d", ui_selected_step_view*16 + 1, ui_selected_step_view*16 + 16);
1454
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "Step View", buffer);
1455
 
1456
  return 0; // no error
1457
}
1458
 
1459
static s32 SEQ_UI_Button_StepViewDec(s32 depressed)
1460
{
1461
  if( depressed ) return -1; // ignore when button depressed
1462
 
1463
  int new_step_view = ui_selected_step_view - 1;
1464
  if( new_step_view >= 0 ) {
1465
    // select new step view
1466
    ui_selected_step_view = new_step_view;
1467
 
1468
    // select step within view
1751 tk 1469
    if( !seq_ui_button_state.CHANGE_ALL_STEPS ) { // don't change the selected step if ALL function is active, otherwise the ramp can't be changed over multiple views
1470
      ui_selected_step = (ui_selected_step_view << 4) | (ui_selected_step & 0xf);
1471
    }
1713 tk 1472
  }
1473
 
1474
  char buffer[20];
1475
  sprintf(buffer, "%d-%d", ui_selected_step_view*16 + 1, ui_selected_step_view*16 + 16);
1476
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "Step View", buffer);
1477
 
1478
  return 0; // no error
1479
}
1480
 
513 tk 1481
static s32 SEQ_UI_Button_TrackSel(s32 depressed)
134 tk 1482
{
513 tk 1483
  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
134 tk 1484
 
513 tk 1485
  if( seq_hwcfg_button_beh.track_sel ) {
1486
    if( depressed ) return -1; // ignore when button depressed
678 tk 1487
    if( !seq_ui_button_state.TRACK_SEL ) // due to page change: button going to be set, clear other toggle buttons
1488
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 1489
    seq_ui_button_state.TRACK_SEL ^= 1; // toggle TRACKSEL status (will also be released once GP button has been pressed)
1490
  } else {
1491
    seq_ui_button_state.TRACK_SEL = depressed ? 0 : 1;
1492
  }
1493
 
1494
  if( seq_ui_button_state.TRACK_SEL ) {
1495
    prev_page = ui_page;
1496
    SEQ_UI_PageSet(SEQ_UI_PAGE_TRACKSEL);
1497
  } else {
524 tk 1498
    if( ui_page == SEQ_UI_PAGE_TRACKSEL )
1499
      SEQ_UI_PageSet(prev_page);
513 tk 1500
  }
1501
 
134 tk 1502
  return 0; // no error
1503
}
1504
 
987 tk 1505
static s32 SEQ_UI_Button_Group(s32 depressed, u32 group)
1506
{
1507
  if( depressed ) return -1; // ignore when button depressed
1508
 
1509
  if( group >= 4 ) return -2; // max. 4 group buttons
1510
 
1511
  // in song page: track and group buttons are used to select the cursor position
1512
  if( ui_page == SEQ_UI_PAGE_SONG ) {
1513
    ui_selected_item = 3 + group;
1514
    return 0;
1515
  }
1516
 
1517
  // if group has changed:
1518
  if( group != ui_selected_group ) {
1519
    // get current track selection
1520
    u16 old_tracks = ui_selected_tracks >> (4*ui_selected_group);
1521
 
1522
    // select new group
1523
    ui_selected_group = group;
1524
 
1525
    // take over old track selection
1526
    ui_selected_tracks = old_tracks << (4*ui_selected_group);
1527
  }
1528
 
1529
  // set/clear encoder fast function if required
1530
  SEQ_UI_InitEncSpeed(1); // auto config
1531
 
1532
  return 0; // no error
1533
}
1534
 
484 tk 1535
static s32 SEQ_UI_Button_Track(s32 depressed, u32 track_button)
134 tk 1536
{
484 tk 1537
  static u8 button_state = 0x0f; // all 4 buttons depressed
134 tk 1538
 
484 tk 1539
  if( track_button >= 4 ) return -2; // max. 4 track buttons
134 tk 1540
 
484 tk 1541
  if( depressed ) {
1542
    button_state |= (1 << track_button);
1543
    return 0; // no error
1544
  }
134 tk 1545
 
484 tk 1546
  button_state &= ~(1 << track_button);
1547
 
987 tk 1548
  // in pattern and song page: use track buttons as group buttons
1549
  if( ui_page == SEQ_UI_PAGE_PATTERN || ui_page == SEQ_UI_PAGE_SONG ) {
1550
    return SEQ_UI_Button_Group(depressed, track_button);
1551
  }
1552
 
484 tk 1553
  if( button_state == (~(1 << track_button) & 0xf) ) {
1554
    // if only one select button pressed: radio-button function (1 of 4)
1555
    ui_selected_tracks = 1 << (track_button + 4*ui_selected_group);
1556
  } else {
1557
    // if more than one select button pressed: toggle function (4 of 4)
1558
    ui_selected_tracks ^= 1 << (track_button + 4*ui_selected_group);
1559
  }
1560
 
178 tk 1561
  // set/clear encoder fast function if required
1562
  SEQ_UI_InitEncSpeed(1); // auto config
1563
 
134 tk 1564
  return 0; // no error
1565
}
1566
 
1146 tk 1567
static s32 SEQ_UI_Button_DirectTrack(s32 depressed, u32 track_button)
1568
{
1569
  static u16 button_state = 0xffff; // all 16 buttons depressed
1570
 
1571
  if( track_button >= 16 ) return -2; // max. 16 direct track buttons
1572
 
1573
  if( depressed ) {
1574
    button_state |= (1 << track_button);
1575
    return 0; // no error
1576
  }
1577
 
1578
  button_state &= ~(1 << track_button);
1579
 
1580
  if( button_state == (~(1 << track_button) & 0xffff) ) {
1581
    // if only one select button pressed: radio-button function (1 of 16)
1582
    ui_selected_tracks = 1 << track_button;
1488 tk 1583
    ui_selected_group = track_button / 4;
1146 tk 1584
  } else {
1585
    // if more than one select button pressed: toggle function (16 of 16)
1586
    ui_selected_tracks ^= 1 << track_button;
1587
  }
1588
 
1589
  // set/clear encoder fast function if required
1590
  SEQ_UI_InitEncSpeed(1); // auto config
1591
 
1592
  return 0; // no error
1593
}
1594
 
513 tk 1595
static s32 SEQ_UI_Button_ParLayerSel(s32 depressed)
1596
{
600 tk 1597
  // static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
1598
  // also used by seq_ui_parsel.c
513 tk 1599
 
1600
  if( seq_hwcfg_button_beh.par_layer ) {
1601
    if( depressed ) return -1; // ignore when button depressed
678 tk 1602
    if( !seq_ui_button_state.PAR_LAYER_SEL ) // due to page change: button going to be set, clear other toggle buttons
1603
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 1604
    seq_ui_button_state.PAR_LAYER_SEL ^= 1; // toggle PARSEL status (will also be released once GP button has been pressed)
1605
  } else {
1606
    seq_ui_button_state.PAR_LAYER_SEL = depressed ? 0 : 1;
1607
  }
1608
 
1609
  if( seq_ui_button_state.PAR_LAYER_SEL ) {
2168 tk 1610
    if( ui_page != SEQ_UI_PAGE_PARSEL ) {
1611
      ui_parlayer_prev_page = ui_page;
1612
      SEQ_UI_PageSet(SEQ_UI_PAGE_PARSEL);
1613
    }
513 tk 1614
  } else {
524 tk 1615
    if( ui_page == SEQ_UI_PAGE_PARSEL )
600 tk 1616
      SEQ_UI_PageSet(ui_parlayer_prev_page);
513 tk 1617
  }
1618
 
1619
  // set/clear encoder fast function if required
1620
  SEQ_UI_InitEncSpeed(1); // auto config
1621
 
1622
  return 0; // no error
1623
}
1624
 
134 tk 1625
static s32 SEQ_UI_Button_ParLayer(s32 depressed, u32 par_layer)
1626
{
1117 tk 1627
  static u8 layer_c_pressed = 0;
784 tk 1628
 
134 tk 1629
  if( par_layer >= 3 ) return -2; // max. 3 parlayer buttons
1630
 
1205 tk 1631
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1632
  u8 num_p_layers = SEQ_PAR_NumLayersGet(visible_track);
1633
 
987 tk 1634
  // in song page: parameter layer buttons are used to select the cursor position
1635
  if( ui_page == SEQ_UI_PAGE_SONG ) {
1636
    ui_selected_item = par_layer;
1637
    return 0;
1638
  }
1639
 
1205 tk 1640
  // drum mode in edit page: print parameter layer as long as button is pressed
1641
  if( ui_page == SEQ_UI_PAGE_EDIT ) {
1642
    u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
1643
    if( event_mode == SEQ_EVENT_MODE_Drum ) {
1644
      ui_hold_msg_ctr = depressed ? 0 : ~0; // show value for at least 65 seconds... enough?
2324 tk 1645
      if( ui_hold_msg_ctr )
1646
    ui_hold_msg_ctr_drum_edit = 1; // ensure that layer will be displayed
1205 tk 1647
    }
1648
  }
134 tk 1649
 
784 tk 1650
  // holding Layer C button allows to increment/decrement layer with A/B button
1651
  if( par_layer == 2 )
1652
    layer_c_pressed = !depressed;
1653
 
1654
  if( layer_c_pressed && par_layer == 0 ) {
333 tk 1655
    if( depressed ) return -1; // ignore when button depressed
784 tk 1656
    // increment layer
1657
    if( ++ui_selected_par_layer >= num_p_layers )
1658
      ui_selected_par_layer = 0;
1659
  } else if( layer_c_pressed && par_layer == 1 ) {
333 tk 1660
    if( depressed ) return -1; // ignore when button depressed
784 tk 1661
    // decrement layer
1662
    if( ui_selected_par_layer == 0 )
1663
      ui_selected_par_layer = num_p_layers - 1;
333 tk 1664
    else
784 tk 1665
      --ui_selected_par_layer;
333 tk 1666
  } else {
784 tk 1667
    if( num_p_layers <= 3 ) {
1668
      // 3 layers: direct selection with LayerA/B/C button
333 tk 1669
      if( depressed ) return -1; // ignore when button depressed
784 tk 1670
      if( par_layer >= num_p_layers ) {
1671
    char str1[21];
1672
    sprintf(str1, "Parameter Layer %c", 'A'+par_layer);
1673
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, str1, "not available!");
2324 tk 1674
    ui_hold_msg_ctr = 0;
784 tk 1675
      } else {
1676
    seq_ui_button_state.PAR_LAYER_SEL = 0;
1677
    ui_selected_par_layer = par_layer;
1678
      }
1679
    } else if( num_p_layers <= 4 ) {
1680
      // 4 layers: LayerC Button toggles between C and D
1681
      if( depressed ) return -1; // ignore when button depressed
333 tk 1682
      seq_ui_button_state.PAR_LAYER_SEL = 0;
784 tk 1683
      if( par_layer == 2 )
1684
    ui_selected_par_layer = (ui_selected_par_layer == 2) ? 3 : 2;
1685
      else
1686
    ui_selected_par_layer = par_layer;
333 tk 1687
    } else {
784 tk 1688
      // >4 layers: LayerA/B button selects directly, Layer C button enters layer selection page
1689
      if( par_layer <= 1 ) {
1690
    if( depressed ) return -1; // ignore when button depressed
1691
    seq_ui_button_state.PAR_LAYER_SEL = 0;
1692
    ui_selected_par_layer = par_layer;
2168 tk 1693
 
1694
    if( ui_page == SEQ_UI_PAGE_PARSEL )
1695
      SEQ_UI_PageSet(ui_parlayer_prev_page);
784 tk 1696
      } else {
1697
    return SEQ_UI_Button_ParLayerSel(depressed);
1698
      }
333 tk 1699
    }
1700
  }
1701
 
178 tk 1702
  // set/clear encoder fast function if required
1703
  SEQ_UI_InitEncSpeed(1); // auto config
1704
 
134 tk 1705
  return 0; // no error
1706
}
1707
 
513 tk 1708
static s32 SEQ_UI_Button_TrgLayerSel(s32 depressed)
1709
{
600 tk 1710
  // static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
1711
  // also used by seq_ui_trgsel.c
513 tk 1712
 
1713
  if( seq_hwcfg_button_beh.trg_layer ) {
1714
    if( depressed ) return -1; // ignore when button depressed
678 tk 1715
    if( !seq_ui_button_state.TRG_LAYER_SEL ) // due to page change: button going to be set, clear other toggle buttons
1716
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 1717
    seq_ui_button_state.TRG_LAYER_SEL ^= 1; // toggle TRGSEL status (will also be released once GP button has been pressed)
1718
  } else {
1719
    seq_ui_button_state.TRG_LAYER_SEL = depressed ? 0 : 1;
1720
  }
1721
 
1722
  if( seq_ui_button_state.TRG_LAYER_SEL ) {
2168 tk 1723
    if( ui_page != SEQ_UI_PAGE_TRGSEL ) {
1724
      ui_trglayer_prev_page = ui_page;
1725
      SEQ_UI_PageSet(SEQ_UI_PAGE_TRGSEL);
1726
    }
513 tk 1727
  } else {
524 tk 1728
    if( ui_page == SEQ_UI_PAGE_TRGSEL )
600 tk 1729
      SEQ_UI_PageSet(ui_trglayer_prev_page);
513 tk 1730
  }
1731
 
1732
  return 0; // no error
1733
}
1734
 
134 tk 1735
static s32 SEQ_UI_Button_TrgLayer(s32 depressed, u32 trg_layer)
1736
{
1117 tk 1737
  static u8 layer_c_pressed = 0;
784 tk 1738
 
134 tk 1739
  if( trg_layer >= 3 ) return -2; // max. 3 trglayer buttons
1740
 
326 tk 1741
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1742
  u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
1743
  u8 num_t_layers = SEQ_TRG_NumLayersGet(visible_track);
134 tk 1744
 
1205 tk 1745
  // drum mode in edit page: ensure that trigger layer is print again
1746
  if( ui_page == SEQ_UI_PAGE_EDIT ) {
1747
    u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
1748
    if( event_mode == SEQ_EVENT_MODE_Drum ) {
1749
      if( !depressed )
1750
    ui_hold_msg_ctr = 0;
1751
    }
1752
  }
1753
 
784 tk 1754
  // holding Layer C button allows to increment/decrement layer with A/B button
1755
  if( trg_layer == 2 )
1756
    layer_c_pressed = !depressed;
1757
 
1758
  if( layer_c_pressed && trg_layer == 0 ) {
326 tk 1759
    if( depressed ) return -1; // ignore when button depressed
784 tk 1760
    // increment layer
1761
    if( ++ui_selected_trg_layer >= num_t_layers )
1762
      ui_selected_trg_layer = 0;
1763
  } else if( layer_c_pressed && trg_layer == 1 ) {
326 tk 1764
    if( depressed ) return -1; // ignore when button depressed
784 tk 1765
    // decrement layer
1766
    if( ui_selected_trg_layer == 0 )
1767
      ui_selected_trg_layer = num_t_layers - 1;
326 tk 1768
    else
784 tk 1769
      --ui_selected_trg_layer;
326 tk 1770
  } else {
784 tk 1771
    if( event_mode != SEQ_EVENT_MODE_Drum && num_t_layers <= 3 ) {
1772
      // 3 layers: direct selection with LayerA/B/C button
326 tk 1773
      if( depressed ) return -1; // ignore when button depressed
784 tk 1774
      if( trg_layer >= num_t_layers ) {
1775
    char str1[21];
1776
    sprintf(str1, "Trigger Layer %c", 'A'+trg_layer);
1777
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, str1, "not available!");
1778
      } else {
1779
    seq_ui_button_state.TRG_LAYER_SEL = 0;
1780
    ui_selected_trg_layer = trg_layer;
1781
      }
1782
    } else if( event_mode != SEQ_EVENT_MODE_Drum && num_t_layers <= 4 ) {
1783
      // 4 layers: LayerC Button toggles between C and D
1784
      if( depressed ) return -1; // ignore when button depressed
328 tk 1785
      seq_ui_button_state.TRG_LAYER_SEL = 0;
784 tk 1786
      if( trg_layer == 2 )
1787
    ui_selected_trg_layer = (ui_selected_trg_layer == 2) ? 3 : 2;
1788
      else
1789
    ui_selected_trg_layer = trg_layer;
326 tk 1790
    } else {
784 tk 1791
      // >4 layers or drum mode: LayerA/B button selects directly, Layer C button enters trigger selection page
1792
      // also used for drum tracks
1793
      if( trg_layer <= 1 ) {
1794
    if( depressed ) return -1; // ignore when button depressed
1795
    seq_ui_button_state.TRG_LAYER_SEL = 0;
1796
    ui_selected_trg_layer = trg_layer;
2168 tk 1797
 
1798
    if( ui_page == SEQ_UI_PAGE_TRGSEL )
1799
      SEQ_UI_PageSet(ui_trglayer_prev_page);
784 tk 1800
      } else {
1801
    return SEQ_UI_Button_TrgLayerSel(depressed);
1802
      }
326 tk 1803
    }
1804
  }
1805
 
134 tk 1806
  return 0; // no error
1807
}
1808
 
1809
 
1119 tk 1810
static s32 SEQ_UI_Button_Mixer(s32 depressed)
544 tk 1811
{
1812
  if( depressed ) return -1; // ignore when button depressed
134 tk 1813
 
1119 tk 1814
  SEQ_UI_PageSet(SEQ_UI_PAGE_MIXER);
544 tk 1815
 
1816
  return 0; // no error
1817
}
1818
 
1787 tk 1819
static s32 SEQ_UI_Button_Save(s32 depressed)
1820
{
1821
  if( depressed ) return -1; // ignore when button depressed
1822
 
1823
  u8 group = ui_selected_group;
1824
  seq_pattern_t pattern = seq_pattern[group];
1825
  s32 status;
1826
  if( (status=SEQ_PATTERN_Save(group, pattern)) < 0 ) {
1827
    SEQ_UI_SDCardErrMsg(2000, status);
1828
  } else {
1829
    char str1[21];
1830
    char str2[21];
1831
    sprintf(str1, "Track Group G%d", group + 1);
1832
    sprintf(str2, "stored into %d:%c%d", pattern.bank+1, (pattern.lower ? 'a' : 'A') + pattern.group, pattern.num + 1);
1833
    SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, str1, str2);
1834
  }
1835
 
1836
  return 0; // no error
1837
}
1838
 
1839
static s32 SEQ_UI_Button_SaveAll(s32 depressed)
1840
{
1841
  if( depressed ) return -1; // ignore when button depressed
1842
 
1843
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "Complete Session", "stored!");
1844
  seq_ui_saveall_req = 1;
1845
 
1846
  return 0; // no error
1847
}
1848
 
1119 tk 1849
static s32 SEQ_UI_Button_TrackMode(s32 depressed)
544 tk 1850
{
1851
  if( depressed ) return -1; // ignore when button depressed
1852
 
1119 tk 1853
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKMODE);
544 tk 1854
 
1855
  return 0; // no error
1856
}
1857
 
1119 tk 1858
static s32 SEQ_UI_Button_TrackGroove(s32 depressed)
544 tk 1859
{
1860
  if( depressed ) return -1; // ignore when button depressed
1861
 
1119 tk 1862
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKGRV);
1863
 
1864
  return 0; // no error
1865
}
1866
 
1867
static s32 SEQ_UI_Button_TrackLength(s32 depressed)
1868
{
1869
  if( depressed ) return -1; // ignore when button depressed
1870
 
1871
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKLEN);
1872
 
1873
  return 0; // no error
1874
}
1875
 
1876
static s32 SEQ_UI_Button_TrackDirection(s32 depressed)
1877
{
1878
  if( depressed ) return -1; // ignore when button depressed
1879
 
1880
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKDIR);
1881
 
1882
  return 0; // no error
1883
}
1884
 
1885
static s32 SEQ_UI_Button_TrackMorph(s32 depressed)
1886
{
1887
  if( depressed ) return -1; // ignore when button depressed
1888
 
1889
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKMORPH);
1890
 
1891
  return 0; // no error
1892
}
1893
 
1894
static s32 SEQ_UI_Button_TrackTranspose(s32 depressed)
1895
{
1896
  if( depressed ) return -1; // ignore when button depressed
1897
 
544 tk 1898
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKTRAN);
1899
 
1900
  return 0; // no error
1901
}
1902
 
2294 tk 1903
static s32 SEQ_UI_Button_Fx(s32 depressed)
1904
{
1905
  if( depressed ) return -1; // ignore when button depressed
1906
 
1907
  SEQ_UI_PageSet(SEQ_UI_PAGE_FX);
1908
 
1909
  return 0; // no error
1910
}
1911
 
1811 tk 1912
static s32 SEQ_UI_Button_MuteAllTracks(s32 depressed)
1913
{
1914
  if( depressed ) return -1; // ignore when button depressed
1915
  seq_core_trk_muted = 0xffff;
1814 tk 1916
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "All Tracks", "muted");
1811 tk 1917
  return 0; // no error
1918
}
544 tk 1919
 
1811 tk 1920
static s32 SEQ_UI_Button_MuteTrackLayers(s32 depressed)
1921
{
1922
  if( depressed ) return -1; // ignore when button depressed
1923
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1924
  seq_core_trk[visible_track].layer_muted = 0xffff;
1814 tk 1925
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "All Layers", "of current Track muted");
1811 tk 1926
  return 0; // no error
1927
}
1928
 
1929
static s32 SEQ_UI_Button_MuteAllTracksAndLayers(s32 depressed)
1930
{
1931
  if( depressed ) return -1; // ignore when button depressed
1932
  int track;
1933
  for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track)
1934
    seq_core_trk[track].layer_muted = 0xffff;
1935
  seq_core_trk_muted = 0xffff;
1814 tk 1936
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "All Layers", "and Tracks muted");
1811 tk 1937
  return 0; // no error
1938
}
1939
 
1940
static s32 SEQ_UI_Button_UnMuteAllTracks(s32 depressed)
1941
{
1942
  if( depressed ) return -1; // ignore when button depressed
1814 tk 1943
  seq_core_trk_muted = 0x0000;
1944
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "All Tracks", "unmuted");
1811 tk 1945
  return 0; // no error
1946
}
1947
 
1948
static s32 SEQ_UI_Button_UnMuteTrackLayers(s32 depressed)
1949
{
1950
  if( depressed ) return -1; // ignore when button depressed
1951
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1814 tk 1952
  seq_core_trk[visible_track].layer_muted = 0x0000;
1953
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "All Layers", "of current Track unmuted");
1811 tk 1954
  return 0; // no error
1955
}
1956
 
1957
static s32 SEQ_UI_Button_UnMuteAllTracksAndLayers(s32 depressed)
1958
{
1959
  if( depressed ) return -1; // ignore when button depressed
1960
  int track;
1961
  for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track)
1814 tk 1962
    seq_core_trk[track].layer_muted = 0x0000;
1963
  seq_core_trk_muted = 0x0000;
1964
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "All Layers", "and Tracks unmuted");
1811 tk 1965
  return 0; // no error
1966
}
1967
 
742 tk 1968
// only used by keyboard remote function
1969
static s32 SEQ_UI_Button_ToggleGate(s32 depressed)
1970
{
1971
  if( depressed ) return -1; // ignore when button depressed
544 tk 1972
 
742 tk 1973
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1974
  u8 gate = SEQ_TRG_GateGet(visible_track, ui_selected_step, ui_selected_instrument) ? 0 : 1;
1975
  SEQ_TRG_GateSet(visible_track, ui_selected_step, ui_selected_instrument, gate);
544 tk 1976
 
742 tk 1977
  return 0; // no error
1978
}
1979
 
1349 tk 1980
static s32 SEQ_UI_Button_FootSwitch(s32 depressed)
1981
{
1982
  // static variables (only used here, therefore local)
1983
  static u32 fs_time_control = 0; // timestamp of last operation
742 tk 1984
 
1349 tk 1985
  // this is used as a constant value
2079 midilab 1986
  u32 fs_time_delay = 500; // mS - should this be configurable?
742 tk 1987
 
2079 midilab 1988
  // Clear track check
1989
  if( depressed ) {
2448 tk 1990
    // if footswitch time passed between pressed and depressed is less than fs_time_delay miliseconds, clear track.
1991
    if( ( MIOS32_TIMESTAMP_GetDelay(fs_time_control) < fs_time_delay ) && ( fs_time_control != 0 ) ) {
1992
      SEQ_UI_UTIL_ClearButton(0); // button pressed
1993
      SEQ_UI_UTIL_ClearButton(1); // button depressed
1994
      if( seq_ui_button_state.SELECT_PRESSED )
1995
    SEQ_UI_Msg_Layer("cleared");
1996
      else
1997
    SEQ_UI_Msg_Track("cleared");
1349 tk 1998
    }
1999
  } else {
2448 tk 2000
    // store pressed timestamp
2001
    fs_time_control = MIOS32_TIMESTAMP_Get();
1349 tk 2002
  }
2003
 
2448 tk 2004
  // PUNCH_IN, PUNCH_OUT
1349 tk 2005
  if( depressed ) {
2006
    // disable recording
2168 tk 2007
    SEQ_RECORD_Enable(0, 1);
1349 tk 2008
  } else {
2009
    // enable recording
2168 tk 2010
    SEQ_RECORD_Enable(1, 1);
1349 tk 2011
    seq_record_state.ARMED_TRACKS = ui_selected_tracks; // not used yet, just preparation for future changes
2012
  }
2013
 
2014
  return 0; // no error
2015
}
2016
 
2017
 
2502 tk 2018
static s32 SEQ_UI_Button_EncBtnFwd(s32 depressed)
2019
{
2020
  seq_ui_button_state.ENC_BTN_FWD_PRESSED = depressed == 0;
2021
 
2022
  return 0; // no error
2023
}
2024
 
2025
 
134 tk 2026
/////////////////////////////////////////////////////////////////////////////
2027
// Button handler
2028
/////////////////////////////////////////////////////////////////////////////
2029
s32 SEQ_UI_Button_Handler(u32 pin, u32 pin_value)
2030
{
492 tk 2031
  int i;
2032
 
625 tk 2033
  // send MIDI event in remote mode and exit
1316 tk 2034
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT )
625 tk 2035
    return SEQ_MIDI_SYSEX_REMOTE_Client_SendButton(pin, pin_value);
2036
 
1044 tk 2037
  // ignore as long as hardware config hasn't been read
496 tk 2038
  if( !SEQ_FILE_HW_ConfigLocked() )
2039
    return -1;
2040
 
740 tk 2041
  // ignore during a backup or format is created
2042
  if( seq_ui_backup_req || seq_ui_format_req )
634 tk 2043
    return -1;
2044
 
328 tk 2045
  // ensure that selections are matching with track constraints
2046
  SEQ_UI_CheckSelections();
2047
 
492 tk 2048
  // request display update
2049
  seq_ui_display_update_req = 1;
134 tk 2050
 
596 tk 2051
  // stop current message if (new) button has been pressed
2052
  if( pin_value == 0 )
2053
    SEQ_UI_MsgStop();
134 tk 2054
 
596 tk 2055
 
492 tk 2056
  // MEMO: we could also use a jump table with references to the functions
2057
  // here, but this "spagetthi code" simplifies the configuration and
2058
  // the resulting ASM doesn't look that bad!
168 tk 2059
 
492 tk 2060
  for(i=0; i<SEQ_HWCFG_NUM_GP; ++i)
2061
    if( pin == seq_hwcfg_button.gp[i] )
2062
      return SEQ_UI_Button_GP(pin_value, i);
134 tk 2063
 
492 tk 2064
  for(i=0; i<SEQ_HWCFG_NUM_TRACK; ++i)
2065
    if( pin == seq_hwcfg_button.track[i] )
2066
      return SEQ_UI_Button_Track(pin_value, i);
1146 tk 2067
 
2068
  for(i=0; i<SEQ_HWCFG_NUM_DIRECT_TRACK; ++i)
2069
    if( pin == seq_hwcfg_button.direct_track[i] )
2070
      return SEQ_UI_Button_DirectTrack(pin_value, i);
2071
 
1205 tk 2072
  for(i=0; i<SEQ_HWCFG_NUM_DIRECT_BOOKMARK; ++i)
2073
    if( pin == seq_hwcfg_button.direct_bookmark[i] )
2074
      return SEQ_UI_Button_DirectBookmark(pin_value, i);
2075
 
513 tk 2076
  if( pin == seq_hwcfg_button.track_sel )
2077
    return SEQ_UI_Button_TrackSel(pin_value);
134 tk 2078
 
492 tk 2079
  for(i=0; i<SEQ_HWCFG_NUM_GROUP; ++i)
2080
    if( pin == seq_hwcfg_button.group[i] )
2081
      return SEQ_UI_Button_Group(pin_value, i);
134 tk 2082
 
492 tk 2083
  for(i=0; i<SEQ_HWCFG_NUM_PAR_LAYER; ++i)
2084
    if( pin == seq_hwcfg_button.par_layer[i] )
2085
      return SEQ_UI_Button_ParLayer(pin_value, i);
513 tk 2086
  if( pin == seq_hwcfg_button.par_layer_sel )
2087
    return SEQ_UI_Button_ParLayerSel(pin_value);
134 tk 2088
 
492 tk 2089
  for(i=0; i<SEQ_HWCFG_NUM_TRG_LAYER; ++i)
2090
    if( pin == seq_hwcfg_button.trg_layer[i] )
2091
      return SEQ_UI_Button_TrgLayer(pin_value, i);
513 tk 2092
  if( pin == seq_hwcfg_button.trg_layer_sel )
2093
    return SEQ_UI_Button_TrgLayerSel(pin_value);
134 tk 2094
 
492 tk 2095
  if( pin == seq_hwcfg_button.left )
2096
    return SEQ_UI_Button_Left(pin_value);
2097
  if( pin == seq_hwcfg_button.right )
2098
    return SEQ_UI_Button_Right(pin_value);
2099
  if( pin == seq_hwcfg_button.down )
2100
    return SEQ_UI_Button_Down(pin_value);
2101
  if( pin == seq_hwcfg_button.up )
2102
    return SEQ_UI_Button_Up(pin_value);
134 tk 2103
 
492 tk 2104
  if( pin == seq_hwcfg_button.scrub )
2105
    return SEQ_UI_Button_Scrub(pin_value);
2106
  if( pin == seq_hwcfg_button.metronome )
2107
    return SEQ_UI_Button_Metronome(pin_value);
134 tk 2108
 
630 tk 2109
  if( pin == seq_hwcfg_button.record )
2110
    return SEQ_UI_Button_Record(pin_value);
2322 tk 2111
  if( pin == seq_hwcfg_button.jam_live )
2112
    return SEQ_UI_Button_JamLive(pin_value);
2113
  if( pin == seq_hwcfg_button.jam_step )
2114
    return SEQ_UI_Button_JamStep(pin_value);
1219 tk 2115
  if( pin == seq_hwcfg_button.live )
2116
    return SEQ_UI_Button_Live(pin_value);
630 tk 2117
 
492 tk 2118
  if( pin == seq_hwcfg_button.stop )
2119
    return SEQ_UI_Button_Stop(pin_value);
2120
  if( pin == seq_hwcfg_button.pause )
2121
    return SEQ_UI_Button_Pause(pin_value);
2122
  if( pin == seq_hwcfg_button.play )
2123
    return SEQ_UI_Button_Play(pin_value);
2124
  if( pin == seq_hwcfg_button.rew )
2125
    return SEQ_UI_Button_Rew(pin_value);
2126
  if( pin == seq_hwcfg_button.fwd )
2127
    return SEQ_UI_Button_Fwd(pin_value);
596 tk 2128
  if( pin == seq_hwcfg_button.loop )
2129
    return SEQ_UI_Button_Loop(pin_value);
973 tk 2130
  if( pin == seq_hwcfg_button.follow )
2131
    return SEQ_UI_Button_Follow(pin_value);
134 tk 2132
 
492 tk 2133
  if( pin == seq_hwcfg_button.utility )
2134
    return SEQ_UI_Button_Utility(pin_value);
2135
  if( pin == seq_hwcfg_button.copy )
2136
    return SEQ_UI_Button_Copy(pin_value);
2137
  if( pin == seq_hwcfg_button.paste )
2138
    return SEQ_UI_Button_Paste(pin_value);
2139
  if( pin == seq_hwcfg_button.clear )
2140
    return SEQ_UI_Button_Clear(pin_value);
1014 tk 2141
  if( pin == seq_hwcfg_button.undo )
2142
    return SEQ_UI_Button_Undo(pin_value);
2308 tk 2143
  if( pin == seq_hwcfg_button.move )
2144
    return SEQ_UI_Button_Move(pin_value);
2145
  if( pin == seq_hwcfg_button.scroll )
2146
    return SEQ_UI_Button_Scroll(pin_value);
134 tk 2147
 
492 tk 2148
  if( pin == seq_hwcfg_button.menu )
2149
    return SEQ_UI_Button_Menu(pin_value);
1203 tk 2150
  if( pin == seq_hwcfg_button.bookmark )
2151
    return SEQ_UI_Button_Bookmark(pin_value);
492 tk 2152
  if( pin == seq_hwcfg_button.select )
2153
    return SEQ_UI_Button_Select(pin_value);
2154
  if( pin == seq_hwcfg_button.exit )
2155
    return SEQ_UI_Button_Exit(pin_value);
134 tk 2156
 
513 tk 2157
  if( pin == seq_hwcfg_button.tap_tempo )
2158
    return SEQ_UI_Button_TapTempo(pin_value);
2159
  if( pin == seq_hwcfg_button.tempo_preset )
2160
    return SEQ_UI_Button_TempoPreset(pin_value);
524 tk 2161
  if( pin == seq_hwcfg_button.ext_restart )
2162
    return SEQ_UI_Button_ExtRestart(pin_value);
134 tk 2163
 
492 tk 2164
  if( pin == seq_hwcfg_button.edit )
2165
    return SEQ_UI_Button_Edit(pin_value);
2166
  if( pin == seq_hwcfg_button.mute )
2167
    return SEQ_UI_Button_Mute(pin_value);
2168
  if( pin == seq_hwcfg_button.pattern )
2169
    return SEQ_UI_Button_Pattern(pin_value);
2170
  if( pin == seq_hwcfg_button.song )
2171
    return SEQ_UI_Button_Song(pin_value);
134 tk 2172
 
492 tk 2173
  if( pin == seq_hwcfg_button.solo )
2174
    return SEQ_UI_Button_Solo(pin_value);
2175
  if( pin == seq_hwcfg_button.fast )
2176
    return SEQ_UI_Button_Fast(pin_value);
1121 tk 2177
  if( pin == seq_hwcfg_button.fast2 )
2178
    return SEQ_UI_Button_Fast2(pin_value);
492 tk 2179
  if( pin == seq_hwcfg_button.all )
2180
    return SEQ_UI_Button_All(pin_value);
134 tk 2181
 
492 tk 2182
  if( pin == seq_hwcfg_button.step_view )
2183
    return SEQ_UI_Button_StepView(pin_value);
134 tk 2184
 
544 tk 2185
  if( pin == seq_hwcfg_button.mixer )
2186
    return SEQ_UI_Button_Mixer(pin_value);
2187
 
1787 tk 2188
  if( pin == seq_hwcfg_button.save )
2189
    return SEQ_UI_Button_Save(pin_value);
2190
  if( pin == seq_hwcfg_button.save_all )
2191
    return SEQ_UI_Button_SaveAll(pin_value);
2192
 
1119 tk 2193
  if( pin == seq_hwcfg_button.track_mode )
2194
    return SEQ_UI_Button_TrackMode(pin_value);
2195
  if( pin == seq_hwcfg_button.track_groove )
2196
    return SEQ_UI_Button_TrackGroove(pin_value);
2197
  if( pin == seq_hwcfg_button.track_length )
2198
    return SEQ_UI_Button_TrackLength(pin_value);
2199
  if( pin == seq_hwcfg_button.track_direction )
2200
    return SEQ_UI_Button_TrackDirection(pin_value);
2201
  if( pin == seq_hwcfg_button.track_morph )
2202
    return SEQ_UI_Button_TrackMorph(pin_value);
2203
  if( pin == seq_hwcfg_button.track_transpose )
2204
    return SEQ_UI_Button_TrackTranspose(pin_value);
2294 tk 2205
  if( pin == seq_hwcfg_button.fx )
2206
    return SEQ_UI_Button_Fx(pin_value);
1349 tk 2207
  if( pin == seq_hwcfg_button.footswitch )
2208
    return SEQ_UI_Button_FootSwitch(pin_value);
2502 tk 2209
  if( pin == seq_hwcfg_button.enc_btn_fwd )
2210
    return SEQ_UI_Button_EncBtnFwd(pin_value);
1454 midilab 2211
  if( pin == seq_hwcfg_button.pattern_remix )
2212
    return SEQ_UI_Button_Pattern_Remix(pin_value);
1811 tk 2213
 
2214
  if( pin == seq_hwcfg_button.mute_all_tracks )
2215
    return SEQ_UI_Button_MuteAllTracks(pin_value);
2216
  if( pin == seq_hwcfg_button.mute_track_layers )
2217
    return SEQ_UI_Button_MuteTrackLayers(pin_value);
2218
  if( pin == seq_hwcfg_button.mute_all_tracks_and_layers )
2219
    return SEQ_UI_Button_MuteAllTracksAndLayers(pin_value);
2220
  if( pin == seq_hwcfg_button.unmute_all_tracks )
2221
    return SEQ_UI_Button_UnMuteAllTracks(pin_value);
2222
  if( pin == seq_hwcfg_button.unmute_track_layers )
2223
    return SEQ_UI_Button_UnMuteTrackLayers(pin_value);
2224
  if( pin == seq_hwcfg_button.unmute_all_tracks_and_layers )
2225
    return SEQ_UI_Button_UnMuteAllTracksAndLayers(pin_value);
2226
 
625 tk 2227
  // always print debugging message
2228
#if 1
1081 tk 2229
  MUTEX_MIDIOUT_TAKE;
2230
  DEBUG_MSG("[SEQ_UI_Button_Handler] Button SR:%d, Pin:%d not mapped, it has been %s.\n",
2231
        (pin >> 3) + 1,
2232
        pin & 7,
2233
        pin_value ? "depressed" : "pressed");
2234
  MUTEX_MIDIOUT_GIVE;
625 tk 2235
#endif
2236
 
492 tk 2237
  return -1; // button not mapped
134 tk 2238
}
2239
 
2240
 
2241
/////////////////////////////////////////////////////////////////////////////
524 tk 2242
// BLM Button handler
2243
/////////////////////////////////////////////////////////////////////////////
2244
s32 SEQ_UI_BLM_Button_Handler(u32 row, u32 pin, u32 pin_value)
2245
{
625 tk 2246
  // send MIDI event in remote mode and exit
1316 tk 2247
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT )
625 tk 2248
    return SEQ_MIDI_SYSEX_REMOTE_Client_Send_BLM_Button(row, pin, pin_value);
2249
 
1044 tk 2250
  // ignore as long as hardware config hasn't been read
524 tk 2251
  if( !SEQ_FILE_HW_ConfigLocked() )
2252
    return -1;
2253
 
740 tk 2254
  // ignore during a backup or format is created
2255
  if( seq_ui_backup_req || seq_ui_format_req )
634 tk 2256
    return -1;
2257
 
524 tk 2258
  if( row >= SEQ_CORE_NUM_TRACKS_PER_GROUP )
2259
    return -1; // more than 4 tracks not supported (yet) - could be done in this function w/o much effort
2260
 
2261
  if( pin >= 16 )
2262
    return -1; // more than 16 step buttons not supported (yet) - could be done by selecting the step view
2263
 
2264
  // select track depending on row
2265
  ui_selected_tracks = 1 << (row + 4*ui_selected_group);
2266
 
2267
  // ensure that selections are matching with track constraints
2268
  SEQ_UI_CheckSelections();
2269
 
2270
  // request display update
2271
  seq_ui_display_update_req = 1;
2272
 
2273
  // emulate general purpose button
758 tk 2274
  if( seq_hwcfg_blm.buttons_no_ui ) {
763 tk 2275
    s32 status = SEQ_UI_EDIT_Button_Handler(pin, pin_value);
758 tk 2276
    ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0;
2277
    return status;
763 tk 2278
  }
2279
 
2280
  return SEQ_UI_Button_GP(pin_value, pin); // no error, pin_value and pin are swapped for this function due to consistency reasons
524 tk 2281
}
2282
 
2283
 
2284
/////////////////////////////////////////////////////////////////////////////
134 tk 2285
// Encoder handler
2286
/////////////////////////////////////////////////////////////////////////////
2287
s32 SEQ_UI_Encoder_Handler(u32 encoder, s32 incrementer)
2288
{
625 tk 2289
  // send MIDI event in remote mode and exit
1316 tk 2290
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT )
625 tk 2291
    return SEQ_MIDI_SYSEX_REMOTE_Client_SendEncoder(encoder, incrementer);
2292
 
1044 tk 2293
  // ignore as long as hardware config hasn't been read
496 tk 2294
  if( !SEQ_FILE_HW_ConfigLocked() )
2295
    return -1;
2296
 
740 tk 2297
  // ignore during a backup or format is created
2298
  if( seq_ui_backup_req || seq_ui_format_req )
634 tk 2299
    return -1;
2300
 
1341 tk 2301
  if( encoder >= SEQ_HWCFG_NUM_ENCODERS )
134 tk 2302
    return -1; // encoder doesn't exist
2303
 
328 tk 2304
  // ensure that selections are matching with track constraints
2305
  SEQ_UI_CheckSelections();
2306
 
596 tk 2307
  // stop current message
2308
  SEQ_UI_MsgStop();
2309
 
134 tk 2310
  // limit incrementer
2311
  if( incrementer > 3 )
2312
    incrementer = 3;
2313
  else if( incrementer < -3 )
2314
    incrementer = -3;
2315
 
1341 tk 2316
  // encoder 17 increments BPM
2317
  if( encoder == 17 ) {
2318
    u16 value = (u16)(seq_core_bpm_preset_tempo[seq_core_bpm_preset_num]*10);
2319
    if( SEQ_UI_Var16_Inc(&value, 25, 3000, incrementer) ) { // at 384ppqn, the minimum BPM rate is ca. 2.5
2320
      // set new BPM
2321
      seq_core_bpm_preset_tempo[seq_core_bpm_preset_num] = (float)value/10.0;
2322
      SEQ_CORE_BPM_Update(seq_core_bpm_preset_tempo[seq_core_bpm_preset_num], seq_core_bpm_preset_ramp[seq_core_bpm_preset_num]);
2323
      //store_file_required = 1;
2324
      seq_ui_display_update_req = 1;      
2325
    }
2326
    return 0;
2327
  }
2328
 
607 tk 2329
  if( seq_ui_button_state.SCRUB && encoder == 0 ) {
2330
    // if sequencer isn't already running, continue it (don't restart)
2331
    if( !SEQ_BPM_IsRunning() )
2332
      SEQ_BPM_Cont();
2333
    ui_seq_pause = 0; // clear pause mode
1278 tk 2334
 
607 tk 2335
    // Scrub sequence back or forth
2336
    portENTER_CRITICAL(); // should be atomic
2337
    SEQ_CORE_Scrub(incrementer);
2338
    portEXIT_CRITICAL();
2501 tk 2339
  } else if( seq_ui_button_state.MENU_PRESSED ) {
2340
    // encoder selects menu page like GP button
2341
    if( encoder >= 1 && encoder <= 16 )
2342
      SEQ_UI_PageSet(SEQ_UI_PAGES_MenuShortcutPageGet(encoder-1));
2343
  } else if( ui_encoder_callback != NULL ) {
2502 tk 2344
    if( seq_ui_button_state.ENC_BTN_FWD_PRESSED ) {
2345
      // encoder emulates a GP button
2504 tk 2346
      if( ui_button_callback ) {
2347
    ui_button_callback(encoder-1, 0);
2348
      }
2349
      if( ui_button_callback ) { // previous call could remove the callback!
2350
    ui_button_callback(encoder-1, 1);
2351
      }
2502 tk 2352
      ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0; // ensure that value is visible when it has been changed
2353
    } else {
2354
      // common handling
2355
      ui_encoder_callback((encoder == 0) ? SEQ_UI_ENCODER_Datawheel : (encoder-1), incrementer);
2356
      ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0; // ensure that value is visible when it has been changed
2357
    }
134 tk 2358
  }
2359
 
2360
  // request display update
159 tk 2361
  seq_ui_display_update_req = 1;
134 tk 2362
 
2363
  return 0; // no error
2364
}
2365
 
2366
 
353 tk 2367
 
134 tk 2368
/////////////////////////////////////////////////////////////////////////////
626 tk 2369
// Receives a MIDI package from APP_NotifyReceivedEvent (-> app.c)
2370
/////////////////////////////////////////////////////////////////////////////
2371
s32 SEQ_UI_REMOTE_MIDI_Receive(mios32_midi_port_t port, mios32_midi_package_t midi_package)
2372
{
2373
#if 1
2374
  // check for active remote mode
1316 tk 2375
  if( seq_midi_sysex_remote_active_mode != SEQ_MIDI_SYSEX_REMOTE_MODE_SERVER )
626 tk 2376
    return 0; // no error
2377
#endif
2378
 
1316 tk 2379
  if( (seq_midi_sysex_remote_port == DEFAULT && seq_midi_sysex_remote_active_port != port) ||
2380
      (seq_midi_sysex_remote_port != DEFAULT && port != seq_midi_sysex_remote_port) )
626 tk 2381
    return 0; // wrong port
2382
 
2383
  // for easier parsing: convert Note Off -> Note On with velocity 0
2384
  if( midi_package.event == NoteOff ) {
2385
    midi_package.event = NoteOn;
2386
    midi_package.velocity = 0;
2387
  }
2388
 
2389
  switch( midi_package.event ) {
2390
    case NoteOn: {
2391
      switch( midi_package.chn ) {
2392
        case Chn1:
2393
      SEQ_UI_Button_Handler(midi_package.note + 0x00, midi_package.velocity ? 0 : 1);
2394
      break;
2395
        case Chn2:
2396
      SEQ_UI_Button_Handler(midi_package.note + 0x80, midi_package.velocity ? 0 : 1);
2397
      break;
2398
        case Chn3:
2399
      SEQ_UI_BLM_Button_Handler(midi_package.note >> 5, midi_package.note & 0x1f, midi_package.velocity ? 0 : 1);
2400
      break;
2401
      }
2402
    } break;
2403
 
2404
    case CC: {
2405
      if( midi_package.cc_number >= 15 && midi_package.cc_number <= 31 )
2406
    SEQ_UI_Encoder_Handler(midi_package.cc_number-15, (int)midi_package.value - 0x40);
2407
    } break;
2408
  }
2409
 
632 tk 2410
  return 1; // MIDI event has been taken for remote function -> don't forward to router/MIDI event parser
626 tk 2411
}
2412
 
2413
 
2414
/////////////////////////////////////////////////////////////////////////////
741 tk 2415
// MIDI Remote Keyboard Function (called from SEQ_MIDI_IN)
2416
/////////////////////////////////////////////////////////////////////////////
742 tk 2417
s32 SEQ_UI_REMOTE_MIDI_Keyboard(u8 key, u8 depressed)
741 tk 2418
{
742 tk 2419
#if 0
1316 tk 2420
  MIOS32_MIDI_SendDebugMessage("SEQ_MIDI_SYSEX_REMOTE_MIDI_Keyboard(%d, %d)\n", key, depressed);
741 tk 2421
#endif
742 tk 2422
 
2423
  switch( key ) {
2424
    case 0x24: // C-2
2425
      return SEQ_UI_Button_GP(depressed, 0);
2426
    case 0x25: // C#2
2427
      return SEQ_UI_Button_Track(depressed, 0);
2428
    case 0x26: // D-2
2429
      return SEQ_UI_Button_GP(depressed, 1);
2430
    case 0x27: // D#2
2431
      return SEQ_UI_Button_Track(depressed, 1);
2432
    case 0x28: // E-2
2433
      return SEQ_UI_Button_GP(depressed, 2);
2434
    case 0x29: // F-2
2435
      return SEQ_UI_Button_GP(depressed, 3);
2436
    case 0x2a: // F#2
2437
      return SEQ_UI_Button_Track(depressed, 2);
2438
    case 0x2b: // G-2
2439
      return SEQ_UI_Button_GP(depressed, 4);
2440
    case 0x2c: // G#2
2441
      return SEQ_UI_Button_Track(depressed, 3);
2442
    case 0x2d: // A-2
2443
      return SEQ_UI_Button_GP(depressed, 5);
2444
    case 0x2e: // A#2
2445
      return SEQ_UI_Button_ParLayer(depressed, 0);
2446
    case 0x2f: // B-2
2447
      return SEQ_UI_Button_GP(depressed, 6);
2448
 
2449
    case 0x30: // C-3
2450
      return SEQ_UI_Button_GP(depressed, 7);
2451
    case 0x31: // C#3
2452
      return SEQ_UI_Button_ParLayer(depressed, 1);
2453
    case 0x32: // D-3
2454
      return SEQ_UI_Button_GP(depressed, 8);
2455
    case 0x33: // D#3
2456
      return SEQ_UI_Button_ParLayer(depressed, 2);
2457
    case 0x34: // E-3
2458
      return SEQ_UI_Button_GP(depressed, 9);
2459
    case 0x35: // F-3
2460
      return SEQ_UI_Button_GP(depressed, 10);
2461
    case 0x36: // F#3
2462
      return SEQ_UI_Button_TrgLayer(depressed, 0);
2463
    case 0x37: // G-3
2464
      return SEQ_UI_Button_GP(depressed, 11);
2465
    case 0x38: // G#3
2466
      return SEQ_UI_Button_TrgLayer(depressed, 1);
2467
    case 0x39: // A-3
2468
      return SEQ_UI_Button_GP(depressed, 12);
2469
    case 0x3a: // A#3
2470
      return SEQ_UI_Button_TrgLayer(depressed, 2);
2471
    case 0x3b: // B-3
2472
      return SEQ_UI_Button_GP(depressed, 13);
2473
 
2474
    case 0x3c: // C-4
2475
      return SEQ_UI_Button_GP(depressed, 14);
2476
    case 0x3d: // C#4
2477
      return SEQ_UI_Button_Group(depressed, 0);
2478
    case 0x3e: // D-4
2479
      return SEQ_UI_Button_GP(depressed, 15);
2480
    case 0x3f: // D#4
2481
      return SEQ_UI_Button_Group(depressed, 1);
2482
    case 0x40: // E-4
2483
      return 0; // ignore
2484
    case 0x41: // F-4
2485
      return SEQ_UI_Button_StepView(depressed);
2486
    case 0x42: // F#4
2162 tk 2487
      return SEQ_UI_Button_Group(depressed, 2);
742 tk 2488
    case 0x43: // G-4
2489
      return 0; // ignore
2490
    case 0x44: // G#4
2162 tk 2491
      return SEQ_UI_Button_Group(depressed, 3);
742 tk 2492
    case 0x45: // A-4
2493
      return SEQ_UI_Button_Left(depressed);
2494
    case 0x46: // A#4
2495
      return SEQ_UI_Button_ToggleGate(depressed);
2496
    case 0x47: // B-4
2497
      return SEQ_UI_Button_Right(depressed);
2498
 
2499
    case 0x48: // C-5
2500
      return SEQ_UI_Button_Edit(depressed);
2501
    case 0x49: // C#5
2502
      return SEQ_UI_Button_Solo(depressed);
2503
    case 0x4a: // D-5
2504
      return SEQ_UI_Button_Mute(depressed);
2505
    case 0x4b: // D#5
2506
      return SEQ_UI_Button_All(depressed);
2507
    case 0x4c: // E-5
2508
      return SEQ_UI_Button_Pattern(depressed);
2509
    case 0x4d: // F-5
2510
      return SEQ_UI_Button_Song(depressed);
2511
    case 0x4e: // F#5
2512
      return SEQ_UI_Button_Fast(depressed);
2513
    case 0x4f: // G-5
2514
      return SEQ_UI_Button_Metronome(depressed);
2515
    case 0x50: // G#5
2516
      return SEQ_UI_Button_ExtRestart(depressed);
2517
    case 0x51: // A-5
2518
      return SEQ_UI_Button_ParLayerSel(depressed);
2519
    case 0x52: // A#5
2520
      return SEQ_UI_Button_TrackSel(depressed);
2521
    case 0x53: // B-5
2522
      return SEQ_UI_Button_Stop(depressed);
2523
 
2524
    case 0x54: // C-6
2525
      return SEQ_UI_Button_Play(depressed);
2526
    case 0x55: // C#6
2527
      return SEQ_UI_Button_Pause(depressed);
2528
    case 0x56: // D-6
2529
      return SEQ_UI_Button_Rew(depressed);
2530
    case 0x57: // D#6
2531
      return SEQ_UI_Button_Fwd(depressed);
2532
    case 0x58: // E-6
2533
      return SEQ_UI_Button_Utility(depressed);
2534
    case 0x59: // F-6
2535
      return SEQ_UI_Button_TempoPreset(depressed);
2536
    case 0x5a: // F#6
2537
      return 0; // ignore
2538
    case 0x5b: // G-6
2539
      return SEQ_UI_Button_Menu(depressed);
2540
    case 0x5c: // G#6
2541
      return SEQ_UI_Button_Select(depressed);
2542
    case 0x5d: // A-6
2543
      return SEQ_UI_Button_Exit(depressed);
2544
    case 0x5e: // A#6
2545
      return SEQ_UI_Button_Down(depressed);
2546
    case 0x5f: // B-6
2547
      return SEQ_UI_Button_Up(depressed);
2548
  }
2549
 
741 tk 2550
  return 0; // no error
2551
}
2552
 
2553
 
2554
/////////////////////////////////////////////////////////////////////////////
134 tk 2555
// Update LCD messages
2556
// Usually called from background task
2557
/////////////////////////////////////////////////////////////////////////////
2558
s32 SEQ_UI_LCD_Handler(void)
2559
{
728 tk 2560
  static u8 boot_animation_wait_ctr = 0;
2561
  static u8 boot_animation_lcd_pos = 0;
2130 tk 2562
  static u8 screen_saver_was_active = 0;
728 tk 2563
 
625 tk 2564
  // special handling in remote client mode
1316 tk 2565
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT )
625 tk 2566
    return SEQ_UI_LCD_Update();
2567
 
159 tk 2568
  if( seq_ui_display_init_req ) {
2569
    seq_ui_display_init_req = 0; // clear request
134 tk 2570
 
278 tk 2571
    // clear force update of LCD
2572
    SEQ_LCD_Clear();
2573
    SEQ_LCD_Update(1);
134 tk 2574
 
168 tk 2575
    // select first menu item
2576
    ui_selected_item = 0;
2577
 
167 tk 2578
    // call init function of current page
2039 tk 2579
    SEQ_UI_PAGES_CallInit(ui_page);
134 tk 2580
 
2581
    // request display update
159 tk 2582
    seq_ui_display_update_req = 1;
134 tk 2583
  }
2584
 
2130 tk 2585
  // print boot screen as long as hardware config hasn't been read or screensaver is active
496 tk 2586
  if( !SEQ_FILE_HW_ConfigLocked() ) {
728 tk 2587
    if( boot_animation_lcd_pos < (40-3) ) {
2588
      if( ++boot_animation_wait_ctr >= 75 ) {
2589
    boot_animation_wait_ctr = 0;
637 tk 2590
 
728 tk 2591
    if( boot_animation_lcd_pos == 0 ) {
2592
      SEQ_LCD_Clear();
2593
      SEQ_LCD_CursorSet(0, 0);
2594
      SEQ_LCD_PrintString(MIOS32_LCD_BOOT_MSG_LINE1 " " MIOS32_LCD_BOOT_MSG_LINE2);
2595
      SEQ_LCD_CursorSet(0, 1);
2596
      SEQ_LCD_PrintString("Searching for SD Card...");
2597
    }
2598
 
2599
    // logo is print on second LCD
2130 tk 2600
    SEQ_LCD_LOGO_Print(40, boot_animation_lcd_pos++);
728 tk 2601
      }
2602
    }
740 tk 2603
  } else if( seq_ui_backup_req || seq_ui_format_req ) {
634 tk 2604
    SEQ_LCD_Clear();
2605
    SEQ_LCD_CursorSet(0, 0);
740 tk 2606
    //                     <-------------------------------------->
2607
    //                     0123456789012345678901234567890123456789
2608
    if( seq_ui_backup_req )
2523 tk 2609
      SEQ_LCD_PrintString("Copy Files - please wait!!!");
740 tk 2610
    else if( seq_ui_format_req )
2523 tk 2611
      SEQ_LCD_PrintString("Creating Files - please wait!!!");
740 tk 2612
    else
2613
      SEQ_LCD_PrintString("Don't know what I'm doing! :-/");
637 tk 2614
 
2615
    if( seq_file_backup_notification != NULL ) {
2616
      int i;
2617
 
2618
      SEQ_LCD_CursorSet(0, 1);
959 tk 2619
      SEQ_LCD_PrintFormattedString("Creating %s", seq_file_backup_notification);
637 tk 2620
 
2621
      SEQ_LCD_CursorSet(40+3, 0);
2622
      SEQ_LCD_PrintString("Total: [");
2623
      for(i=0; i<20; ++i)
2624
    SEQ_LCD_PrintChar((i>(seq_file_backup_percentage/5)) ? ' ' : '#');
2625
      SEQ_LCD_PrintFormattedString("] %3d%%", seq_file_backup_percentage);
2626
 
2627
      SEQ_LCD_CursorSet(40+3, 1);
2628
      SEQ_LCD_PrintString("File:  [");
2629
      for(i=0; i<20; ++i)
1261 tk 2630
    SEQ_LCD_PrintChar((i>(file_copy_percentage/5)) ? ' ' : '#');
2631
      SEQ_LCD_PrintFormattedString("] %3d%%", file_copy_percentage);
637 tk 2632
    }
2633
 
2130 tk 2634
  } else if( SEQ_LCD_LOGO_ScreenSaver_IsActive() ) {
2635
    screen_saver_was_active = 1;
2636
    SEQ_LCD_LOGO_ScreenSaver_Print();
496 tk 2637
  } else if( seq_ui_button_state.MENU_PRESSED && !seq_ui_button_state.MENU_FIRST_PAGE_SELECTED ) {
2638
    SEQ_LCD_CursorSet(0, 0);
2639
    //                   <-------------------------------------->
2640
    //                   0123456789012345678901234567890123456789
306 tk 2641
    SEQ_LCD_PrintString("Menu Shortcuts:");
2642
    SEQ_LCD_PrintSpaces(25 + 40);
2643
    SEQ_LCD_CursorSet(0, 1);
2039 tk 2644
 
2645
    int i;
2646
    for(i=0; i<16; ++i) {
2647
      SEQ_LCD_PrintString(SEQ_UI_PAGES_MenuShortcutNameGet(i));
2648
    }
306 tk 2649
  } else {
2130 tk 2650
    // re-init special chars
2651
    if( screen_saver_was_active ) {
2652
      screen_saver_was_active = 0;
2653
      SEQ_LCD_ReInitSpecialChars();
2654
    }
2655
 
306 tk 2656
    // perform high priority LCD update request
2657
    if( ui_lcd_callback != NULL )
2658
      ui_lcd_callback(1); // high_prio
167 tk 2659
 
306 tk 2660
    // perform low priority LCD update request if requested
2661
    if( seq_ui_display_update_req ) {
2662
      seq_ui_display_update_req = 0; // clear request
328 tk 2663
 
2664
      // ensure that selections are matching with track constraints
2665
      SEQ_UI_CheckSelections();
2666
 
306 tk 2667
      if( ui_lcd_callback != NULL )
2668
    ui_lcd_callback(0); // no high_prio
2669
    }
134 tk 2670
  }
2671
 
353 tk 2672
  // transfer all changed characters to LCD
2673
  SEQ_UI_LCD_Update();
2674
 
2675
  return 0; // no error
2676
}
2677
 
2678
 
2679
/////////////////////////////////////////////////////////////////////////////
2680
// Called from SEQ_UI_LCD_Handler(), but optionally also from other tasks
2681
// to update the LCD screen immediately
2682
/////////////////////////////////////////////////////////////////////////////
1117 tk 2683
// for newer GCC versions it's important to