Subversion Repositories svn.mios32

Rev

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