Subversion Repositories svn.mios32

Rev

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