Subversion Repositories svn.mios32

Rev

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