Subversion Repositories svn.mios32

Rev

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