Subversion Repositories svn.mios32

Rev

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