Subversion Repositories svn.mios32

Rev

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