Subversion Repositories svn.mios32

Rev

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