Subversion Repositories svn.mios32

Rev

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