Subversion Repositories svn.mios32

Rev

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