Subversion Repositories svn.mios32

Rev

Rev 2092 | Rev 2110 | 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 2102 2014-12-15 17:40:04Z 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
1277
    seq_ui_button_state.SOLO ^= 1;
1278
  } else {
1279
    // set mode
1280
    seq_ui_button_state.SOLO = depressed ? 0 : 1;
1281
  }
134 tk 1282
 
1283
  return 0; // no error
1284
}
1285
 
1286
static s32 SEQ_UI_Button_Fast(s32 depressed)
1287
{
513 tk 1288
  if( seq_hwcfg_button_beh.fast ) {
1289
    // toggle mode
1290
    if( depressed ) return -1; // ignore when button depressed
1291
    seq_ui_button_state.FAST_ENCODERS ^= 1;
1292
  } else {
1293
    // set mode
1294
    seq_ui_button_state.FAST_ENCODERS = depressed ? 0 : 1;
1295
  }
134 tk 1296
 
178 tk 1297
  SEQ_UI_InitEncSpeed(0); // no auto config
1298
 
134 tk 1299
  return 0; // no error
1300
}
1301
 
1121 tk 1302
static s32 SEQ_UI_Button_Fast2(s32 depressed)
1303
{
1304
  if( seq_hwcfg_button_beh.fast2 ) {
1305
    // toggle mode
1306
    if( depressed ) return -1; // ignore when button depressed
1307
    seq_ui_button_state.FAST2_ENCODERS ^= 1;
1308
  } else {
1309
    // set mode
1310
    seq_ui_button_state.FAST2_ENCODERS = depressed ? 0 : 1;
1311
  }
1312
 
1313
  SEQ_UI_InitEncSpeed(0); // no auto config
1314
 
1315
  return 0; // no error
1316
}
1317
 
134 tk 1318
static s32 SEQ_UI_Button_All(s32 depressed)
1319
{
178 tk 1320
  seq_ui_button_state.CHANGE_ALL_STEPS_SAME_VALUE = depressed ? 0 : 1;
134 tk 1321
 
513 tk 1322
  if( seq_hwcfg_button_beh.all ) {
1323
    // toggle mode
1324
    if( depressed ) return -1;
1325
    seq_ui_button_state.CHANGE_ALL_STEPS ^= 1;
1326
  } else {
1327
    // set mode
1328
    seq_ui_button_state.CHANGE_ALL_STEPS = depressed ? 0 : 1;
1329
  }
178 tk 1330
 
134 tk 1331
  return 0; // no error
1332
}
1333
 
1334
static s32 SEQ_UI_Button_StepView(s32 depressed)
1335
{
600 tk 1336
  //  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
1337
  // also used by seq_ui_stepsel
1338
 
513 tk 1339
  if( seq_hwcfg_button_beh.step_view ) {
1340
    if( depressed ) return -1; // ignore when button depressed
678 tk 1341
    if( !seq_ui_button_state.STEP_VIEW ) // due to page change: button going to be set, clear other toggle buttons
1342
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 1343
    seq_ui_button_state.STEP_VIEW ^= 1; // toggle STEP_VIEW pressed (will also be released once GP button has been pressed)
1344
  } else {
1345
    // set mode
1346
    seq_ui_button_state.STEP_VIEW = depressed ? 0 : 1;
1347
  }
134 tk 1348
 
513 tk 1349
  if( seq_ui_button_state.STEP_VIEW ) {
600 tk 1350
    ui_stepview_prev_page = ui_page;
303 tk 1351
    SEQ_UI_PageSet(SEQ_UI_PAGE_STEPSEL);
1352
  } else {
524 tk 1353
    if( ui_page == SEQ_UI_PAGE_STEPSEL )
600 tk 1354
      SEQ_UI_PageSet(ui_stepview_prev_page);
303 tk 1355
  }
134 tk 1356
 
1357
  return 0; // no error
1358
}
1359
 
1713 tk 1360
static s32 SEQ_UI_Button_StepViewInc(s32 depressed)
1361
{
1362
  if( depressed ) return -1; // ignore when button depressed
1363
 
1364
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1365
  int num_steps = SEQ_TRG_NumStepsGet(visible_track);
1366
 
1367
  int new_step_view = ui_selected_step_view + 1;
1368
  if( (16*new_step_view) < num_steps ) {
1369
    // select new step view
1370
    ui_selected_step_view = new_step_view;
1371
 
1372
    // select step within view
1751 tk 1373
    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
1374
      ui_selected_step = (ui_selected_step_view << 4) | (ui_selected_step & 0xf);
1375
    }
1713 tk 1376
  }
1377
 
1378
  char buffer[20];
1379
  sprintf(buffer, "%d-%d", ui_selected_step_view*16 + 1, ui_selected_step_view*16 + 16);
1380
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "Step View", buffer);
1381
 
1382
  return 0; // no error
1383
}
1384
 
1385
static s32 SEQ_UI_Button_StepViewDec(s32 depressed)
1386
{
1387
  if( depressed ) return -1; // ignore when button depressed
1388
 
1389
  int new_step_view = ui_selected_step_view - 1;
1390
  if( new_step_view >= 0 ) {
1391
    // select new step view
1392
    ui_selected_step_view = new_step_view;
1393
 
1394
    // select step within view
1751 tk 1395
    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
1396
      ui_selected_step = (ui_selected_step_view << 4) | (ui_selected_step & 0xf);
1397
    }
1713 tk 1398
  }
1399
 
1400
  char buffer[20];
1401
  sprintf(buffer, "%d-%d", ui_selected_step_view*16 + 1, ui_selected_step_view*16 + 16);
1402
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "Step View", buffer);
1403
 
1404
  return 0; // no error
1405
}
1406
 
513 tk 1407
static s32 SEQ_UI_Button_TrackSel(s32 depressed)
134 tk 1408
{
513 tk 1409
  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
134 tk 1410
 
513 tk 1411
  if( seq_hwcfg_button_beh.track_sel ) {
1412
    if( depressed ) return -1; // ignore when button depressed
678 tk 1413
    if( !seq_ui_button_state.TRACK_SEL ) // due to page change: button going to be set, clear other toggle buttons
1414
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 1415
    seq_ui_button_state.TRACK_SEL ^= 1; // toggle TRACKSEL status (will also be released once GP button has been pressed)
1416
  } else {
1417
    seq_ui_button_state.TRACK_SEL = depressed ? 0 : 1;
1418
  }
1419
 
1420
  if( seq_ui_button_state.TRACK_SEL ) {
1421
    prev_page = ui_page;
1422
    SEQ_UI_PageSet(SEQ_UI_PAGE_TRACKSEL);
1423
  } else {
524 tk 1424
    if( ui_page == SEQ_UI_PAGE_TRACKSEL )
1425
      SEQ_UI_PageSet(prev_page);
513 tk 1426
  }
1427
 
134 tk 1428
  return 0; // no error
1429
}
1430
 
987 tk 1431
static s32 SEQ_UI_Button_Group(s32 depressed, u32 group)
1432
{
1433
  if( depressed ) return -1; // ignore when button depressed
1434
 
1435
  if( group >= 4 ) return -2; // max. 4 group buttons
1436
 
1437
  // in song page: track and group buttons are used to select the cursor position
1438
  if( ui_page == SEQ_UI_PAGE_SONG ) {
1439
    ui_selected_item = 3 + group;
1440
    return 0;
1441
  }
1442
 
1443
  // if group has changed:
1444
  if( group != ui_selected_group ) {
1445
    // get current track selection
1446
    u16 old_tracks = ui_selected_tracks >> (4*ui_selected_group);
1447
 
1448
    // select new group
1449
    ui_selected_group = group;
1450
 
1451
    // take over old track selection
1452
    ui_selected_tracks = old_tracks << (4*ui_selected_group);
1453
  }
1454
 
1455
  // set/clear encoder fast function if required
1456
  SEQ_UI_InitEncSpeed(1); // auto config
1457
 
1458
  return 0; // no error
1459
}
1460
 
484 tk 1461
static s32 SEQ_UI_Button_Track(s32 depressed, u32 track_button)
134 tk 1462
{
484 tk 1463
  static u8 button_state = 0x0f; // all 4 buttons depressed
134 tk 1464
 
484 tk 1465
  if( track_button >= 4 ) return -2; // max. 4 track buttons
134 tk 1466
 
484 tk 1467
  if( depressed ) {
1468
    button_state |= (1 << track_button);
1469
    return 0; // no error
1470
  }
134 tk 1471
 
484 tk 1472
  button_state &= ~(1 << track_button);
1473
 
987 tk 1474
  // in pattern and song page: use track buttons as group buttons
1475
  if( ui_page == SEQ_UI_PAGE_PATTERN || ui_page == SEQ_UI_PAGE_SONG ) {
1476
    return SEQ_UI_Button_Group(depressed, track_button);
1477
  }
1478
 
484 tk 1479
  if( button_state == (~(1 << track_button) & 0xf) ) {
1480
    // if only one select button pressed: radio-button function (1 of 4)
1481
    ui_selected_tracks = 1 << (track_button + 4*ui_selected_group);
1482
  } else {
1483
    // if more than one select button pressed: toggle function (4 of 4)
1484
    ui_selected_tracks ^= 1 << (track_button + 4*ui_selected_group);
1485
  }
1486
 
178 tk 1487
  // set/clear encoder fast function if required
1488
  SEQ_UI_InitEncSpeed(1); // auto config
1489
 
134 tk 1490
  return 0; // no error
1491
}
1492
 
1146 tk 1493
static s32 SEQ_UI_Button_DirectTrack(s32 depressed, u32 track_button)
1494
{
1495
  static u16 button_state = 0xffff; // all 16 buttons depressed
1496
 
1497
  if( track_button >= 16 ) return -2; // max. 16 direct track buttons
1498
 
1499
  if( depressed ) {
1500
    button_state |= (1 << track_button);
1501
    return 0; // no error
1502
  }
1503
 
1504
  button_state &= ~(1 << track_button);
1505
 
1506
  if( button_state == (~(1 << track_button) & 0xffff) ) {
1507
    // if only one select button pressed: radio-button function (1 of 16)
1508
    ui_selected_tracks = 1 << track_button;
1488 tk 1509
    ui_selected_group = track_button / 4;
1146 tk 1510
  } else {
1511
    // if more than one select button pressed: toggle function (16 of 16)
1512
    ui_selected_tracks ^= 1 << track_button;
1513
  }
1514
 
1515
  // set/clear encoder fast function if required
1516
  SEQ_UI_InitEncSpeed(1); // auto config
1517
 
1518
  return 0; // no error
1519
}
1520
 
513 tk 1521
static s32 SEQ_UI_Button_ParLayerSel(s32 depressed)
1522
{
600 tk 1523
  // static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
1524
  // also used by seq_ui_parsel.c
513 tk 1525
 
1526
  if( seq_hwcfg_button_beh.par_layer ) {
1527
    if( depressed ) return -1; // ignore when button depressed
678 tk 1528
    if( !seq_ui_button_state.PAR_LAYER_SEL ) // due to page change: button going to be set, clear other toggle buttons
1529
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 1530
    seq_ui_button_state.PAR_LAYER_SEL ^= 1; // toggle PARSEL status (will also be released once GP button has been pressed)
1531
  } else {
1532
    seq_ui_button_state.PAR_LAYER_SEL = depressed ? 0 : 1;
1533
  }
1534
 
1535
  if( seq_ui_button_state.PAR_LAYER_SEL ) {
600 tk 1536
    ui_parlayer_prev_page = ui_page;
513 tk 1537
    SEQ_UI_PageSet(SEQ_UI_PAGE_PARSEL);
1538
  } else {
524 tk 1539
    if( ui_page == SEQ_UI_PAGE_PARSEL )
600 tk 1540
      SEQ_UI_PageSet(ui_parlayer_prev_page);
513 tk 1541
  }
1542
 
1543
  // set/clear encoder fast function if required
1544
  SEQ_UI_InitEncSpeed(1); // auto config
1545
 
1546
  return 0; // no error
1547
}
1548
 
134 tk 1549
static s32 SEQ_UI_Button_ParLayer(s32 depressed, u32 par_layer)
1550
{
1117 tk 1551
  static u8 layer_c_pressed = 0;
784 tk 1552
 
134 tk 1553
  if( par_layer >= 3 ) return -2; // max. 3 parlayer buttons
1554
 
1205 tk 1555
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1556
  u8 num_p_layers = SEQ_PAR_NumLayersGet(visible_track);
1557
 
987 tk 1558
  // in song page: parameter layer buttons are used to select the cursor position
1559
  if( ui_page == SEQ_UI_PAGE_SONG ) {
1560
    ui_selected_item = par_layer;
1561
    return 0;
1562
  }
1563
 
1205 tk 1564
  // drum mode in edit page: print parameter layer as long as button is pressed
1565
  if( ui_page == SEQ_UI_PAGE_EDIT ) {
1566
    u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
1567
    if( event_mode == SEQ_EVENT_MODE_Drum ) {
1568
      ui_hold_msg_ctr = depressed ? 0 : ~0; // show value for at least 65 seconds... enough?
1569
    }
1570
  }
134 tk 1571
 
784 tk 1572
  // holding Layer C button allows to increment/decrement layer with A/B button
1573
  if( par_layer == 2 )
1574
    layer_c_pressed = !depressed;
1575
 
1576
  if( layer_c_pressed && par_layer == 0 ) {
333 tk 1577
    if( depressed ) return -1; // ignore when button depressed
784 tk 1578
    // increment layer
1579
    if( ++ui_selected_par_layer >= num_p_layers )
1580
      ui_selected_par_layer = 0;
1581
  } else if( layer_c_pressed && par_layer == 1 ) {
333 tk 1582
    if( depressed ) return -1; // ignore when button depressed
784 tk 1583
    // decrement layer
1584
    if( ui_selected_par_layer == 0 )
1585
      ui_selected_par_layer = num_p_layers - 1;
333 tk 1586
    else
784 tk 1587
      --ui_selected_par_layer;
333 tk 1588
  } else {
784 tk 1589
    if( num_p_layers <= 3 ) {
1590
      // 3 layers: direct selection with LayerA/B/C button
333 tk 1591
      if( depressed ) return -1; // ignore when button depressed
784 tk 1592
      if( par_layer >= num_p_layers ) {
1593
    char str1[21];
1594
    sprintf(str1, "Parameter Layer %c", 'A'+par_layer);
1595
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, str1, "not available!");
1596
      } else {
1597
    seq_ui_button_state.PAR_LAYER_SEL = 0;
1598
    ui_selected_par_layer = par_layer;
1599
      }
1600
    } else if( num_p_layers <= 4 ) {
1601
      // 4 layers: LayerC Button toggles between C and D
1602
      if( depressed ) return -1; // ignore when button depressed
333 tk 1603
      seq_ui_button_state.PAR_LAYER_SEL = 0;
784 tk 1604
      if( par_layer == 2 )
1605
    ui_selected_par_layer = (ui_selected_par_layer == 2) ? 3 : 2;
1606
      else
1607
    ui_selected_par_layer = par_layer;
333 tk 1608
    } else {
784 tk 1609
      // >4 layers: LayerA/B button selects directly, Layer C button enters layer selection page
1610
      if( par_layer <= 1 ) {
1611
    if( depressed ) return -1; // ignore when button depressed
1612
    seq_ui_button_state.PAR_LAYER_SEL = 0;
1613
    ui_selected_par_layer = par_layer;
1614
      } else {
1615
    return SEQ_UI_Button_ParLayerSel(depressed);
1616
      }
333 tk 1617
    }
1618
  }
1619
 
178 tk 1620
  // set/clear encoder fast function if required
1621
  SEQ_UI_InitEncSpeed(1); // auto config
1622
 
134 tk 1623
  return 0; // no error
1624
}
1625
 
513 tk 1626
static s32 SEQ_UI_Button_TrgLayerSel(s32 depressed)
1627
{
600 tk 1628
  // static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
1629
  // also used by seq_ui_trgsel.c
513 tk 1630
 
1631
  if( seq_hwcfg_button_beh.trg_layer ) {
1632
    if( depressed ) return -1; // ignore when button depressed
678 tk 1633
    if( !seq_ui_button_state.TRG_LAYER_SEL ) // due to page change: button going to be set, clear other toggle buttons
1634
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 1635
    seq_ui_button_state.TRG_LAYER_SEL ^= 1; // toggle TRGSEL status (will also be released once GP button has been pressed)
1636
  } else {
1637
    seq_ui_button_state.TRG_LAYER_SEL = depressed ? 0 : 1;
1638
  }
1639
 
1640
  if( seq_ui_button_state.TRG_LAYER_SEL ) {
600 tk 1641
    ui_trglayer_prev_page = ui_page;
513 tk 1642
    SEQ_UI_PageSet(SEQ_UI_PAGE_TRGSEL);
1643
  } else {
524 tk 1644
    if( ui_page == SEQ_UI_PAGE_TRGSEL )
600 tk 1645
      SEQ_UI_PageSet(ui_trglayer_prev_page);
513 tk 1646
  }
1647
 
1648
  return 0; // no error
1649
}
1650
 
134 tk 1651
static s32 SEQ_UI_Button_TrgLayer(s32 depressed, u32 trg_layer)
1652
{
1117 tk 1653
  static u8 layer_c_pressed = 0;
784 tk 1654
 
134 tk 1655
  if( trg_layer >= 3 ) return -2; // max. 3 trglayer buttons
1656
 
326 tk 1657
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1658
  u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
1659
  u8 num_t_layers = SEQ_TRG_NumLayersGet(visible_track);
134 tk 1660
 
1205 tk 1661
  // drum mode in edit page: ensure that trigger layer is print again
1662
  if( ui_page == SEQ_UI_PAGE_EDIT ) {
1663
    u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
1664
    if( event_mode == SEQ_EVENT_MODE_Drum ) {
1665
      if( !depressed )
1666
    ui_hold_msg_ctr = 0;
1667
    }
1668
  }
1669
 
784 tk 1670
  // holding Layer C button allows to increment/decrement layer with A/B button
1671
  if( trg_layer == 2 )
1672
    layer_c_pressed = !depressed;
1673
 
1674
  if( layer_c_pressed && trg_layer == 0 ) {
326 tk 1675
    if( depressed ) return -1; // ignore when button depressed
784 tk 1676
    // increment layer
1677
    if( ++ui_selected_trg_layer >= num_t_layers )
1678
      ui_selected_trg_layer = 0;
1679
  } else if( layer_c_pressed && trg_layer == 1 ) {
326 tk 1680
    if( depressed ) return -1; // ignore when button depressed
784 tk 1681
    // decrement layer
1682
    if( ui_selected_trg_layer == 0 )
1683
      ui_selected_trg_layer = num_t_layers - 1;
326 tk 1684
    else
784 tk 1685
      --ui_selected_trg_layer;
326 tk 1686
  } else {
784 tk 1687
    if( event_mode != SEQ_EVENT_MODE_Drum && num_t_layers <= 3 ) {
1688
      // 3 layers: direct selection with LayerA/B/C button
326 tk 1689
      if( depressed ) return -1; // ignore when button depressed
784 tk 1690
      if( trg_layer >= num_t_layers ) {
1691
    char str1[21];
1692
    sprintf(str1, "Trigger Layer %c", 'A'+trg_layer);
1693
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, str1, "not available!");
1694
      } else {
1695
    seq_ui_button_state.TRG_LAYER_SEL = 0;
1696
    ui_selected_trg_layer = trg_layer;
1697
      }
1698
    } else if( event_mode != SEQ_EVENT_MODE_Drum && num_t_layers <= 4 ) {
1699
      // 4 layers: LayerC Button toggles between C and D
1700
      if( depressed ) return -1; // ignore when button depressed
328 tk 1701
      seq_ui_button_state.TRG_LAYER_SEL = 0;
784 tk 1702
      if( trg_layer == 2 )
1703
    ui_selected_trg_layer = (ui_selected_trg_layer == 2) ? 3 : 2;
1704
      else
1705
    ui_selected_trg_layer = trg_layer;
326 tk 1706
    } else {
784 tk 1707
      // >4 layers or drum mode: LayerA/B button selects directly, Layer C button enters trigger selection page
1708
      // also used for drum tracks
1709
      if( trg_layer <= 1 ) {
1710
    if( depressed ) return -1; // ignore when button depressed
1711
    seq_ui_button_state.TRG_LAYER_SEL = 0;
1712
    ui_selected_trg_layer = trg_layer;
1713
      } else {
1714
    return SEQ_UI_Button_TrgLayerSel(depressed);
1715
      }
326 tk 1716
    }
1717
  }
1718
 
134 tk 1719
  return 0; // no error
1720
}
1721
 
1722
 
1119 tk 1723
static s32 SEQ_UI_Button_Mixer(s32 depressed)
544 tk 1724
{
1725
  if( depressed ) return -1; // ignore when button depressed
134 tk 1726
 
1119 tk 1727
  SEQ_UI_PageSet(SEQ_UI_PAGE_MIXER);
544 tk 1728
 
1729
  return 0; // no error
1730
}
1731
 
1787 tk 1732
static s32 SEQ_UI_Button_Save(s32 depressed)
1733
{
1734
  if( depressed ) return -1; // ignore when button depressed
1735
 
1736
  u8 group = ui_selected_group;
1737
  seq_pattern_t pattern = seq_pattern[group];
1738
  s32 status;
1739
  if( (status=SEQ_PATTERN_Save(group, pattern)) < 0 ) {
1740
    SEQ_UI_SDCardErrMsg(2000, status);
1741
  } else {
1742
    char str1[21];
1743
    char str2[21];
1744
    sprintf(str1, "Track Group G%d", group + 1);
1745
    sprintf(str2, "stored into %d:%c%d", pattern.bank+1, (pattern.lower ? 'a' : 'A') + pattern.group, pattern.num + 1);
1746
    SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, str1, str2);
1747
  }
1748
 
1749
  return 0; // no error
1750
}
1751
 
1752
static s32 SEQ_UI_Button_SaveAll(s32 depressed)
1753
{
1754
  if( depressed ) return -1; // ignore when button depressed
1755
 
1756
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "Complete Session", "stored!");
1757
  seq_ui_saveall_req = 1;
1758
 
1759
  return 0; // no error
1760
}
1761
 
1119 tk 1762
static s32 SEQ_UI_Button_TrackMode(s32 depressed)
544 tk 1763
{
1764
  if( depressed ) return -1; // ignore when button depressed
1765
 
1119 tk 1766
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKMODE);
544 tk 1767
 
1768
  return 0; // no error
1769
}
1770
 
1119 tk 1771
static s32 SEQ_UI_Button_TrackGroove(s32 depressed)
544 tk 1772
{
1773
  if( depressed ) return -1; // ignore when button depressed
1774
 
1119 tk 1775
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKGRV);
1776
 
1777
  return 0; // no error
1778
}
1779
 
1780
static s32 SEQ_UI_Button_TrackLength(s32 depressed)
1781
{
1782
  if( depressed ) return -1; // ignore when button depressed
1783
 
1784
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKLEN);
1785
 
1786
  return 0; // no error
1787
}
1788
 
1789
static s32 SEQ_UI_Button_TrackDirection(s32 depressed)
1790
{
1791
  if( depressed ) return -1; // ignore when button depressed
1792
 
1793
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKDIR);
1794
 
1795
  return 0; // no error
1796
}
1797
 
1798
static s32 SEQ_UI_Button_TrackMorph(s32 depressed)
1799
{
1800
  if( depressed ) return -1; // ignore when button depressed
1801
 
1802
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKMORPH);
1803
 
1804
  return 0; // no error
1805
}
1806
 
1807
static s32 SEQ_UI_Button_TrackTranspose(s32 depressed)
1808
{
1809
  if( depressed ) return -1; // ignore when button depressed
1810
 
544 tk 1811
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKTRAN);
1812
 
1813
  return 0; // no error
1814
}
1815
 
1811 tk 1816
static s32 SEQ_UI_Button_MuteAllTracks(s32 depressed)
1817
{
1818
  if( depressed ) return -1; // ignore when button depressed
1819
  seq_core_trk_muted = 0xffff;
1814 tk 1820
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "All Tracks", "muted");
1811 tk 1821
  return 0; // no error
1822
}
544 tk 1823
 
1811 tk 1824
static s32 SEQ_UI_Button_MuteTrackLayers(s32 depressed)
1825
{
1826
  if( depressed ) return -1; // ignore when button depressed
1827
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1828
  seq_core_trk[visible_track].layer_muted = 0xffff;
1814 tk 1829
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "All Layers", "of current Track muted");
1811 tk 1830
  return 0; // no error
1831
}
1832
 
1833
static s32 SEQ_UI_Button_MuteAllTracksAndLayers(s32 depressed)
1834
{
1835
  if( depressed ) return -1; // ignore when button depressed
1836
  int track;
1837
  for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track)
1838
    seq_core_trk[track].layer_muted = 0xffff;
1839
  seq_core_trk_muted = 0xffff;
1814 tk 1840
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "All Layers", "and Tracks muted");
1811 tk 1841
  return 0; // no error
1842
}
1843
 
1844
static s32 SEQ_UI_Button_UnMuteAllTracks(s32 depressed)
1845
{
1846
  if( depressed ) return -1; // ignore when button depressed
1814 tk 1847
  seq_core_trk_muted = 0x0000;
1848
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "All Tracks", "unmuted");
1811 tk 1849
  return 0; // no error
1850
}
1851
 
1852
static s32 SEQ_UI_Button_UnMuteTrackLayers(s32 depressed)
1853
{
1854
  if( depressed ) return -1; // ignore when button depressed
1855
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1814 tk 1856
  seq_core_trk[visible_track].layer_muted = 0x0000;
1857
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "All Layers", "of current Track unmuted");
1811 tk 1858
  return 0; // no error
1859
}
1860
 
1861
static s32 SEQ_UI_Button_UnMuteAllTracksAndLayers(s32 depressed)
1862
{
1863
  if( depressed ) return -1; // ignore when button depressed
1864
  int track;
1865
  for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track)
1814 tk 1866
    seq_core_trk[track].layer_muted = 0x0000;
1867
  seq_core_trk_muted = 0x0000;
1868
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "All Layers", "and Tracks unmuted");
1811 tk 1869
  return 0; // no error
1870
}
1871
 
742 tk 1872
// only used by keyboard remote function
1873
static s32 SEQ_UI_Button_ToggleGate(s32 depressed)
1874
{
1875
  if( depressed ) return -1; // ignore when button depressed
544 tk 1876
 
742 tk 1877
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1878
  u8 gate = SEQ_TRG_GateGet(visible_track, ui_selected_step, ui_selected_instrument) ? 0 : 1;
1879
  SEQ_TRG_GateSet(visible_track, ui_selected_step, ui_selected_instrument, gate);
544 tk 1880
 
742 tk 1881
  return 0; // no error
1882
}
1883
 
1349 tk 1884
static s32 SEQ_UI_Button_FootSwitch(s32 depressed)
1885
{
1886
  // static variables (only used here, therefore local)
1887
  static u32 fs_time_control = 0; // timestamp of last operation
742 tk 1888
 
1349 tk 1889
  // this is used as a constant value
2079 midilab 1890
  u32 fs_time_delay = 500; // mS - should this be configurable?
742 tk 1891
 
2079 midilab 1892
  // Clear track check
1893
  if( depressed ) {
1894
        // if footswitch time passed between pressed and depressed is less than fs_time_delay miliseconds, clear track.
1895
    if( ( MIOS32_TIMESTAMP_GetDelay(fs_time_control) < fs_time_delay ) && ( fs_time_control != 0 ) )
1349 tk 1896
    {
2079 midilab 1897
            SEQ_UI_Button_Clear_Track(0);
1349 tk 1898
    }
1899
  } else {
2079 midilab 1900
        // store pressed timestamp
1901
        fs_time_control = MIOS32_TIMESTAMP_Get();
1349 tk 1902
  }
1903
 
2079 midilab 1904
    // PUNCH_IN, PUNCH_OUT
1349 tk 1905
  if( depressed ) {
1906
    // disable recording
1907
    seq_record_state.ENABLED = 0;
1908
  } else {
1909
    // enable recording
1910
    seq_record_state.ENABLED = 1;
1911
    seq_record_state.ARMED_TRACKS = ui_selected_tracks; // not used yet, just preparation for future changes
1912
  }
1913
 
1914
  return 0; // no error
1915
}
1916
 
1917
 
134 tk 1918
/////////////////////////////////////////////////////////////////////////////
1919
// Button handler
1920
/////////////////////////////////////////////////////////////////////////////
1921
s32 SEQ_UI_Button_Handler(u32 pin, u32 pin_value)
1922
{
492 tk 1923
  int i;
1924
 
625 tk 1925
  // send MIDI event in remote mode and exit
1316 tk 1926
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT )
625 tk 1927
    return SEQ_MIDI_SYSEX_REMOTE_Client_SendButton(pin, pin_value);
1928
 
1044 tk 1929
  // ignore as long as hardware config hasn't been read
496 tk 1930
  if( !SEQ_FILE_HW_ConfigLocked() )
1931
    return -1;
1932
 
740 tk 1933
  // ignore during a backup or format is created
1934
  if( seq_ui_backup_req || seq_ui_format_req )
634 tk 1935
    return -1;
1936
 
328 tk 1937
  // ensure that selections are matching with track constraints
1938
  SEQ_UI_CheckSelections();
1939
 
492 tk 1940
  // request display update
1941
  seq_ui_display_update_req = 1;
134 tk 1942
 
596 tk 1943
  // stop current message if (new) button has been pressed
1944
  if( pin_value == 0 )
1945
    SEQ_UI_MsgStop();
134 tk 1946
 
596 tk 1947
 
492 tk 1948
  // MEMO: we could also use a jump table with references to the functions
1949
  // here, but this "spagetthi code" simplifies the configuration and
1950
  // the resulting ASM doesn't look that bad!
168 tk 1951
 
492 tk 1952
  for(i=0; i<SEQ_HWCFG_NUM_GP; ++i)
1953
    if( pin == seq_hwcfg_button.gp[i] )
1954
      return SEQ_UI_Button_GP(pin_value, i);
134 tk 1955
 
492 tk 1956
  for(i=0; i<SEQ_HWCFG_NUM_TRACK; ++i)
1957
    if( pin == seq_hwcfg_button.track[i] )
1958
      return SEQ_UI_Button_Track(pin_value, i);
1146 tk 1959
 
1960
  for(i=0; i<SEQ_HWCFG_NUM_DIRECT_TRACK; ++i)
1961
    if( pin == seq_hwcfg_button.direct_track[i] )
1962
      return SEQ_UI_Button_DirectTrack(pin_value, i);
1963
 
1205 tk 1964
  for(i=0; i<SEQ_HWCFG_NUM_DIRECT_BOOKMARK; ++i)
1965
    if( pin == seq_hwcfg_button.direct_bookmark[i] )
1966
      return SEQ_UI_Button_DirectBookmark(pin_value, i);
1967
 
513 tk 1968
  if( pin == seq_hwcfg_button.track_sel )
1969
    return SEQ_UI_Button_TrackSel(pin_value);
134 tk 1970
 
492 tk 1971
  for(i=0; i<SEQ_HWCFG_NUM_GROUP; ++i)
1972
    if( pin == seq_hwcfg_button.group[i] )
1973
      return SEQ_UI_Button_Group(pin_value, i);
134 tk 1974
 
492 tk 1975
  for(i=0; i<SEQ_HWCFG_NUM_PAR_LAYER; ++i)
1976
    if( pin == seq_hwcfg_button.par_layer[i] )
1977
      return SEQ_UI_Button_ParLayer(pin_value, i);
513 tk 1978
  if( pin == seq_hwcfg_button.par_layer_sel )
1979
    return SEQ_UI_Button_ParLayerSel(pin_value);
134 tk 1980
 
492 tk 1981
  for(i=0; i<SEQ_HWCFG_NUM_TRG_LAYER; ++i)
1982
    if( pin == seq_hwcfg_button.trg_layer[i] )
1983
      return SEQ_UI_Button_TrgLayer(pin_value, i);
513 tk 1984
  if( pin == seq_hwcfg_button.trg_layer_sel )
1985
    return SEQ_UI_Button_TrgLayerSel(pin_value);
134 tk 1986
 
492 tk 1987
  if( pin == seq_hwcfg_button.left )
1988
    return SEQ_UI_Button_Left(pin_value);
1989
  if( pin == seq_hwcfg_button.right )
1990
    return SEQ_UI_Button_Right(pin_value);
1991
  if( pin == seq_hwcfg_button.down )
1992
    return SEQ_UI_Button_Down(pin_value);
1993
  if( pin == seq_hwcfg_button.up )
1994
    return SEQ_UI_Button_Up(pin_value);
134 tk 1995
 
492 tk 1996
  if( pin == seq_hwcfg_button.scrub )
1997
    return SEQ_UI_Button_Scrub(pin_value);
1998
  if( pin == seq_hwcfg_button.metronome )
1999
    return SEQ_UI_Button_Metronome(pin_value);
134 tk 2000
 
630 tk 2001
  if( pin == seq_hwcfg_button.record )
2002
    return SEQ_UI_Button_Record(pin_value);
1219 tk 2003
  if( pin == seq_hwcfg_button.live )
2004
    return SEQ_UI_Button_Live(pin_value);
630 tk 2005
 
492 tk 2006
  if( pin == seq_hwcfg_button.stop )
2007
    return SEQ_UI_Button_Stop(pin_value);
2008
  if( pin == seq_hwcfg_button.pause )
2009
    return SEQ_UI_Button_Pause(pin_value);
2010
  if( pin == seq_hwcfg_button.play )
2011
    return SEQ_UI_Button_Play(pin_value);
2012
  if( pin == seq_hwcfg_button.rew )
2013
    return SEQ_UI_Button_Rew(pin_value);
2014
  if( pin == seq_hwcfg_button.fwd )
2015
    return SEQ_UI_Button_Fwd(pin_value);
596 tk 2016
  if( pin == seq_hwcfg_button.loop )
2017
    return SEQ_UI_Button_Loop(pin_value);
973 tk 2018
  if( pin == seq_hwcfg_button.follow )
2019
    return SEQ_UI_Button_Follow(pin_value);
134 tk 2020
 
492 tk 2021
  if( pin == seq_hwcfg_button.utility )
2022
    return SEQ_UI_Button_Utility(pin_value);
2023
  if( pin == seq_hwcfg_button.copy )
2024
    return SEQ_UI_Button_Copy(pin_value);
2025
  if( pin == seq_hwcfg_button.paste )
2026
    return SEQ_UI_Button_Paste(pin_value);
2027
  if( pin == seq_hwcfg_button.clear )
2028
    return SEQ_UI_Button_Clear(pin_value);
1014 tk 2029
  if( pin == seq_hwcfg_button.undo )
2030
    return SEQ_UI_Button_Undo(pin_value);
134 tk 2031
 
492 tk 2032
  if( pin == seq_hwcfg_button.menu )
2033
    return SEQ_UI_Button_Menu(pin_value);
1203 tk 2034
  if( pin == seq_hwcfg_button.bookmark )
2035
    return SEQ_UI_Button_Bookmark(pin_value);
492 tk 2036
  if( pin == seq_hwcfg_button.select )
2037
    return SEQ_UI_Button_Select(pin_value);
2038
  if( pin == seq_hwcfg_button.exit )
2039
    return SEQ_UI_Button_Exit(pin_value);
134 tk 2040
 
513 tk 2041
  if( pin == seq_hwcfg_button.tap_tempo )
2042
    return SEQ_UI_Button_TapTempo(pin_value);
2043
  if( pin == seq_hwcfg_button.tempo_preset )
2044
    return SEQ_UI_Button_TempoPreset(pin_value);
524 tk 2045
  if( pin == seq_hwcfg_button.ext_restart )
2046
    return SEQ_UI_Button_ExtRestart(pin_value);
134 tk 2047
 
492 tk 2048
  if( pin == seq_hwcfg_button.edit )
2049
    return SEQ_UI_Button_Edit(pin_value);
2050
  if( pin == seq_hwcfg_button.mute )
2051
    return SEQ_UI_Button_Mute(pin_value);
2052
  if( pin == seq_hwcfg_button.pattern )
2053
    return SEQ_UI_Button_Pattern(pin_value);
2054
  if( pin == seq_hwcfg_button.song )
2055
    return SEQ_UI_Button_Song(pin_value);
134 tk 2056
 
492 tk 2057
  if( pin == seq_hwcfg_button.solo )
2058
    return SEQ_UI_Button_Solo(pin_value);
2059
  if( pin == seq_hwcfg_button.fast )
2060
    return SEQ_UI_Button_Fast(pin_value);
1121 tk 2061
  if( pin == seq_hwcfg_button.fast2 )
2062
    return SEQ_UI_Button_Fast2(pin_value);
492 tk 2063
  if( pin == seq_hwcfg_button.all )
2064
    return SEQ_UI_Button_All(pin_value);
134 tk 2065
 
492 tk 2066
  if( pin == seq_hwcfg_button.step_view )
2067
    return SEQ_UI_Button_StepView(pin_value);
134 tk 2068
 
544 tk 2069
  if( pin == seq_hwcfg_button.mixer )
2070
    return SEQ_UI_Button_Mixer(pin_value);
2071
 
1787 tk 2072
  if( pin == seq_hwcfg_button.save )
2073
    return SEQ_UI_Button_Save(pin_value);
2074
  if( pin == seq_hwcfg_button.save_all )
2075
    return SEQ_UI_Button_SaveAll(pin_value);
2076
 
1119 tk 2077
  if( pin == seq_hwcfg_button.track_mode )
2078
    return SEQ_UI_Button_TrackMode(pin_value);
2079
  if( pin == seq_hwcfg_button.track_groove )
2080
    return SEQ_UI_Button_TrackGroove(pin_value);
2081
  if( pin == seq_hwcfg_button.track_length )
2082
    return SEQ_UI_Button_TrackLength(pin_value);
2083
  if( pin == seq_hwcfg_button.track_direction )
2084
    return SEQ_UI_Button_TrackDirection(pin_value);
2085
  if( pin == seq_hwcfg_button.track_morph )
2086
    return SEQ_UI_Button_TrackMorph(pin_value);
2087
  if( pin == seq_hwcfg_button.track_transpose )
2088
    return SEQ_UI_Button_TrackTranspose(pin_value);
1349 tk 2089
  if( pin == seq_hwcfg_button.footswitch )
2090
    return SEQ_UI_Button_FootSwitch(pin_value);
1454 midilab 2091
  if( pin == seq_hwcfg_button.pattern_remix )
2092
    return SEQ_UI_Button_Pattern_Remix(pin_value);
1811 tk 2093
 
2094
  if( pin == seq_hwcfg_button.mute_all_tracks )
2095
    return SEQ_UI_Button_MuteAllTracks(pin_value);
2096
  if( pin == seq_hwcfg_button.mute_track_layers )
2097
    return SEQ_UI_Button_MuteTrackLayers(pin_value);
2098
  if( pin == seq_hwcfg_button.mute_all_tracks_and_layers )
2099
    return SEQ_UI_Button_MuteAllTracksAndLayers(pin_value);
2100
  if( pin == seq_hwcfg_button.unmute_all_tracks )
2101
    return SEQ_UI_Button_UnMuteAllTracks(pin_value);
2102
  if( pin == seq_hwcfg_button.unmute_track_layers )
2103
    return SEQ_UI_Button_UnMuteTrackLayers(pin_value);
2104
  if( pin == seq_hwcfg_button.unmute_all_tracks_and_layers )
2105
    return SEQ_UI_Button_UnMuteAllTracksAndLayers(pin_value);
2106
 
625 tk 2107
  // always print debugging message
2108
#if 1
1081 tk 2109
  MUTEX_MIDIOUT_TAKE;
2110
  DEBUG_MSG("[SEQ_UI_Button_Handler] Button SR:%d, Pin:%d not mapped, it has been %s.\n",
2111
        (pin >> 3) + 1,
2112
        pin & 7,
2113
        pin_value ? "depressed" : "pressed");
2114
  MUTEX_MIDIOUT_GIVE;
625 tk 2115
#endif
2116
 
492 tk 2117
  return -1; // button not mapped
134 tk 2118
}
2119
 
2120
 
2121
/////////////////////////////////////////////////////////////////////////////
524 tk 2122
// BLM Button handler
2123
/////////////////////////////////////////////////////////////////////////////
2124
s32 SEQ_UI_BLM_Button_Handler(u32 row, u32 pin, u32 pin_value)
2125
{
625 tk 2126
  // send MIDI event in remote mode and exit
1316 tk 2127
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT )
625 tk 2128
    return SEQ_MIDI_SYSEX_REMOTE_Client_Send_BLM_Button(row, pin, pin_value);
2129
 
1044 tk 2130
  // ignore as long as hardware config hasn't been read
524 tk 2131
  if( !SEQ_FILE_HW_ConfigLocked() )
2132
    return -1;
2133
 
740 tk 2134
  // ignore during a backup or format is created
2135
  if( seq_ui_backup_req || seq_ui_format_req )
634 tk 2136
    return -1;
2137
 
524 tk 2138
  if( row >= SEQ_CORE_NUM_TRACKS_PER_GROUP )
2139
    return -1; // more than 4 tracks not supported (yet) - could be done in this function w/o much effort
2140
 
2141
  if( pin >= 16 )
2142
    return -1; // more than 16 step buttons not supported (yet) - could be done by selecting the step view
2143
 
2144
  // select track depending on row
2145
  ui_selected_tracks = 1 << (row + 4*ui_selected_group);
2146
 
2147
  // ensure that selections are matching with track constraints
2148
  SEQ_UI_CheckSelections();
2149
 
2150
  // request display update
2151
  seq_ui_display_update_req = 1;
2152
 
2153
  // emulate general purpose button
758 tk 2154
  if( seq_hwcfg_blm.buttons_no_ui ) {
763 tk 2155
    s32 status = SEQ_UI_EDIT_Button_Handler(pin, pin_value);
758 tk 2156
    ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0;
2157
    return status;
763 tk 2158
  }
2159
 
2160
  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 2161
}
2162
 
2163
 
2164
/////////////////////////////////////////////////////////////////////////////
134 tk 2165
// Encoder handler
2166
/////////////////////////////////////////////////////////////////////////////
2167
s32 SEQ_UI_Encoder_Handler(u32 encoder, s32 incrementer)
2168
{
625 tk 2169
  // send MIDI event in remote mode and exit
1316 tk 2170
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT )
625 tk 2171
    return SEQ_MIDI_SYSEX_REMOTE_Client_SendEncoder(encoder, incrementer);
2172
 
1044 tk 2173
  // ignore as long as hardware config hasn't been read
496 tk 2174
  if( !SEQ_FILE_HW_ConfigLocked() )
2175
    return -1;
2176
 
740 tk 2177
  // ignore during a backup or format is created
2178
  if( seq_ui_backup_req || seq_ui_format_req )
634 tk 2179
    return -1;
2180
 
1341 tk 2181
  if( encoder >= SEQ_HWCFG_NUM_ENCODERS )
134 tk 2182
    return -1; // encoder doesn't exist
2183
 
328 tk 2184
  // ensure that selections are matching with track constraints
2185
  SEQ_UI_CheckSelections();
2186
 
596 tk 2187
  // stop current message
2188
  SEQ_UI_MsgStop();
2189
 
134 tk 2190
  // limit incrementer
2191
  if( incrementer > 3 )
2192
    incrementer = 3;
2193
  else if( incrementer < -3 )
2194
    incrementer = -3;
2195
 
1341 tk 2196
  // encoder 17 increments BPM
2197
  if( encoder == 17 ) {
2198
    u16 value = (u16)(seq_core_bpm_preset_tempo[seq_core_bpm_preset_num]*10);
2199
    if( SEQ_UI_Var16_Inc(&value, 25, 3000, incrementer) ) { // at 384ppqn, the minimum BPM rate is ca. 2.5
2200
      // set new BPM
2201
      seq_core_bpm_preset_tempo[seq_core_bpm_preset_num] = (float)value/10.0;
2202
      SEQ_CORE_BPM_Update(seq_core_bpm_preset_tempo[seq_core_bpm_preset_num], seq_core_bpm_preset_ramp[seq_core_bpm_preset_num]);
2203
      //store_file_required = 1;
2204
      seq_ui_display_update_req = 1;      
2205
    }
2206
    return 0;
2207
  }
2208
 
607 tk 2209
  if( seq_ui_button_state.SCRUB && encoder == 0 ) {
2210
    // if sequencer isn't already running, continue it (don't restart)
2211
    if( !SEQ_BPM_IsRunning() )
2212
      SEQ_BPM_Cont();
2213
    ui_seq_pause = 0; // clear pause mode
1278 tk 2214
 
607 tk 2215
    // Scrub sequence back or forth
2216
    portENTER_CRITICAL(); // should be atomic
2217
    SEQ_CORE_Scrub(incrementer);
2218
    portEXIT_CRITICAL();
2219
  } else if( !seq_ui_button_state.MENU_PRESSED && ui_encoder_callback != NULL ) {
173 tk 2220
    ui_encoder_callback((encoder == 0) ? SEQ_UI_ENCODER_Datawheel : (encoder-1), incrementer);
740 tk 2221
    ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0; // ensure that value is visible when it has been changed
134 tk 2222
  }
2223
 
2224
  // request display update
159 tk 2225
  seq_ui_display_update_req = 1;
134 tk 2226
 
2227
  return 0; // no error
2228
}
2229
 
2230
 
353 tk 2231
 
134 tk 2232
/////////////////////////////////////////////////////////////////////////////
626 tk 2233
// Receives a MIDI package from APP_NotifyReceivedEvent (-> app.c)
2234
/////////////////////////////////////////////////////////////////////////////
2235
s32 SEQ_UI_REMOTE_MIDI_Receive(mios32_midi_port_t port, mios32_midi_package_t midi_package)
2236
{
2237
#if 1
2238
  // check for active remote mode
1316 tk 2239
  if( seq_midi_sysex_remote_active_mode != SEQ_MIDI_SYSEX_REMOTE_MODE_SERVER )
626 tk 2240
    return 0; // no error
2241
#endif
2242
 
1316 tk 2243
  if( (seq_midi_sysex_remote_port == DEFAULT && seq_midi_sysex_remote_active_port != port) ||
2244
      (seq_midi_sysex_remote_port != DEFAULT && port != seq_midi_sysex_remote_port) )
626 tk 2245
    return 0; // wrong port
2246
 
2247
  // for easier parsing: convert Note Off -> Note On with velocity 0
2248
  if( midi_package.event == NoteOff ) {
2249
    midi_package.event = NoteOn;
2250
    midi_package.velocity = 0;
2251
  }
2252
 
2253
  switch( midi_package.event ) {
2254
    case NoteOn: {
2255
      switch( midi_package.chn ) {
2256
        case Chn1:
2257
      SEQ_UI_Button_Handler(midi_package.note + 0x00, midi_package.velocity ? 0 : 1);
2258
      break;
2259
        case Chn2:
2260
      SEQ_UI_Button_Handler(midi_package.note + 0x80, midi_package.velocity ? 0 : 1);
2261
      break;
2262
        case Chn3:
2263
      SEQ_UI_BLM_Button_Handler(midi_package.note >> 5, midi_package.note & 0x1f, midi_package.velocity ? 0 : 1);
2264
      break;
2265
      }
2266
    } break;
2267
 
2268
    case CC: {
2269
      if( midi_package.cc_number >= 15 && midi_package.cc_number <= 31 )
2270
    SEQ_UI_Encoder_Handler(midi_package.cc_number-15, (int)midi_package.value - 0x40);
2271
    } break;
2272
  }
2273
 
632 tk 2274
  return 1; // MIDI event has been taken for remote function -> don't forward to router/MIDI event parser
626 tk 2275
}
2276
 
2277
 
2278
/////////////////////////////////////////////////////////////////////////////
741 tk 2279
// MIDI Remote Keyboard Function (called from SEQ_MIDI_IN)
2280
/////////////////////////////////////////////////////////////////////////////
742 tk 2281
s32 SEQ_UI_REMOTE_MIDI_Keyboard(u8 key, u8 depressed)
741 tk 2282
{
742 tk 2283
#if 0
1316 tk 2284
  MIOS32_MIDI_SendDebugMessage("SEQ_MIDI_SYSEX_REMOTE_MIDI_Keyboard(%d, %d)\n", key, depressed);
741 tk 2285
#endif
742 tk 2286
 
2287
  switch( key ) {
2288
    case 0x24: // C-2
2289
      return SEQ_UI_Button_GP(depressed, 0);
2290
    case 0x25: // C#2
2291
      return SEQ_UI_Button_Track(depressed, 0);
2292
    case 0x26: // D-2
2293
      return SEQ_UI_Button_GP(depressed, 1);
2294
    case 0x27: // D#2
2295
      return SEQ_UI_Button_Track(depressed, 1);
2296
    case 0x28: // E-2
2297
      return SEQ_UI_Button_GP(depressed, 2);
2298
    case 0x29: // F-2
2299
      return SEQ_UI_Button_GP(depressed, 3);
2300
    case 0x2a: // F#2
2301
      return SEQ_UI_Button_Track(depressed, 2);
2302
    case 0x2b: // G-2
2303
      return SEQ_UI_Button_GP(depressed, 4);
2304
    case 0x2c: // G#2
2305
      return SEQ_UI_Button_Track(depressed, 3);
2306
    case 0x2d: // A-2
2307
      return SEQ_UI_Button_GP(depressed, 5);
2308
    case 0x2e: // A#2
2309
      return SEQ_UI_Button_ParLayer(depressed, 0);
2310
    case 0x2f: // B-2
2311
      return SEQ_UI_Button_GP(depressed, 6);
2312
 
2313
    case 0x30: // C-3
2314
      return SEQ_UI_Button_GP(depressed, 7);
2315
    case 0x31: // C#3
2316
      return SEQ_UI_Button_ParLayer(depressed, 1);
2317
    case 0x32: // D-3
2318
      return SEQ_UI_Button_GP(depressed, 8);
2319
    case 0x33: // D#3
2320
      return SEQ_UI_Button_ParLayer(depressed, 2);
2321
    case 0x34: // E-3
2322
      return SEQ_UI_Button_GP(depressed, 9);
2323
    case 0x35: // F-3
2324
      return SEQ_UI_Button_GP(depressed, 10);
2325
    case 0x36: // F#3
2326
      return SEQ_UI_Button_TrgLayer(depressed, 0);
2327
    case 0x37: // G-3
2328
      return SEQ_UI_Button_GP(depressed, 11);
2329
    case 0x38: // G#3
2330
      return SEQ_UI_Button_TrgLayer(depressed, 1);
2331
    case 0x39: // A-3
2332
      return SEQ_UI_Button_GP(depressed, 12);
2333
    case 0x3a: // A#3
2334
      return SEQ_UI_Button_TrgLayer(depressed, 2);
2335
    case 0x3b: // B-3
2336
      return SEQ_UI_Button_GP(depressed, 13);
2337
 
2338
    case 0x3c: // C-4
2339
      return SEQ_UI_Button_GP(depressed, 14);
2340
    case 0x3d: // C#4
2341
      return SEQ_UI_Button_Group(depressed, 0);
2342
    case 0x3e: // D-4
2343
      return SEQ_UI_Button_GP(depressed, 15);
2344
    case 0x3f: // D#4
2345
      return SEQ_UI_Button_Group(depressed, 1);
2346
    case 0x40: // E-4
2347
      return 0; // ignore
2348
    case 0x41: // F-4
2349
      return SEQ_UI_Button_StepView(depressed);
2350
    case 0x42: // F#4
2351
      return SEQ_UI_Button_Group(depressed, 1);
2352
    case 0x43: // G-4
2353
      return 0; // ignore
2354
    case 0x44: // G#4
2355
      return SEQ_UI_Button_Group(depressed, 2);
2356
    case 0x45: // A-4
2357
      return SEQ_UI_Button_Left(depressed);
2358
    case 0x46: // A#4
2359
      return SEQ_UI_Button_ToggleGate(depressed);
2360
    case 0x47: // B-4
2361
      return SEQ_UI_Button_Right(depressed);
2362
 
2363
    case 0x48: // C-5
2364
      return SEQ_UI_Button_Edit(depressed);
2365
    case 0x49: // C#5
2366
      return SEQ_UI_Button_Solo(depressed);
2367
    case 0x4a: // D-5
2368
      return SEQ_UI_Button_Mute(depressed);
2369
    case 0x4b: // D#5
2370
      return SEQ_UI_Button_All(depressed);
2371
    case 0x4c: // E-5
2372
      return SEQ_UI_Button_Pattern(depressed);
2373
    case 0x4d: // F-5
2374
      return SEQ_UI_Button_Song(depressed);
2375
    case 0x4e: // F#5
2376
      return SEQ_UI_Button_Fast(depressed);
2377
    case 0x4f: // G-5
2378
      return SEQ_UI_Button_Metronome(depressed);
2379
    case 0x50: // G#5
2380
      return SEQ_UI_Button_ExtRestart(depressed);
2381
    case 0x51: // A-5
2382
      return SEQ_UI_Button_ParLayerSel(depressed);
2383
    case 0x52: // A#5
2384
      return SEQ_UI_Button_TrackSel(depressed);
2385
    case 0x53: // B-5
2386
      return SEQ_UI_Button_Stop(depressed);
2387
 
2388
    case 0x54: // C-6
2389
      return SEQ_UI_Button_Play(depressed);
2390
    case 0x55: // C#6
2391
      return SEQ_UI_Button_Pause(depressed);
2392
    case 0x56: // D-6
2393
      return SEQ_UI_Button_Rew(depressed);
2394
    case 0x57: // D#6
2395
      return SEQ_UI_Button_Fwd(depressed);
2396
    case 0x58: // E-6
2397
      return SEQ_UI_Button_Utility(depressed);
2398
    case 0x59: // F-6
2399
      return SEQ_UI_Button_TempoPreset(depressed);
2400
    case 0x5a: // F#6
2401
      return 0; // ignore
2402
    case 0x5b: // G-6
2403
      return SEQ_UI_Button_Menu(depressed);
2404
    case 0x5c: // G#6
2405
      return SEQ_UI_Button_Select(depressed);
2406
    case 0x5d: // A-6
2407
      return SEQ_UI_Button_Exit(depressed);
2408
    case 0x5e: // A#6
2409
      return SEQ_UI_Button_Down(depressed);
2410
    case 0x5f: // B-6
2411
      return SEQ_UI_Button_Up(depressed);
2412
  }
2413
 
741 tk 2414
  return 0; // no error
2415
}
2416
 
2417
 
2418
/////////////////////////////////////////////////////////////////////////////
134 tk 2419
// Update LCD messages
2420
// Usually called from background task
2421
/////////////////////////////////////////////////////////////////////////////
2422
s32 SEQ_UI_LCD_Handler(void)
2423
{
728 tk 2424
  static u8 boot_animation_wait_ctr = 0;
2425
  static u8 boot_animation_lcd_pos = 0;
2426
 
625 tk 2427
  // special handling in remote client mode
1316 tk 2428
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT )
625 tk 2429
    return SEQ_UI_LCD_Update();
2430
 
159 tk 2431
  if( seq_ui_display_init_req ) {
2432
    seq_ui_display_init_req = 0; // clear request
134 tk 2433
 
278 tk 2434
    // clear force update of LCD
2435
    SEQ_LCD_Clear();
2436
    SEQ_LCD_Update(1);
134 tk 2437
 
168 tk 2438
    // select first menu item
2439
    ui_selected_item = 0;
2440
 
167 tk 2441
    // call init function of current page
2039 tk 2442
    SEQ_UI_PAGES_CallInit(ui_page);
134 tk 2443
 
2444
    // request display update
159 tk 2445
    seq_ui_display_update_req = 1;
134 tk 2446
  }
2447
 
1044 tk 2448
  // print boot screen as long as hardware config hasn't been read
496 tk 2449
  if( !SEQ_FILE_HW_ConfigLocked() ) {
728 tk 2450
    if( boot_animation_lcd_pos < (40-3) ) {
2451
      if( ++boot_animation_wait_ctr >= 75 ) {
2452
    boot_animation_wait_ctr = 0;
637 tk 2453
 
728 tk 2454
    if( boot_animation_lcd_pos == 0 ) {
2455
      SEQ_LCD_Clear();
2456
      SEQ_LCD_CursorSet(0, 0);
2457
      SEQ_LCD_PrintString(MIOS32_LCD_BOOT_MSG_LINE1 " " MIOS32_LCD_BOOT_MSG_LINE2);
2458
      SEQ_LCD_CursorSet(0, 1);
2459
      SEQ_LCD_PrintString("Searching for SD Card...");
2460
    }
2461
 
2462
    // logo is print on second LCD
2463
    SEQ_LCD_LOGO_Print(boot_animation_lcd_pos++);
2464
      }
2465
    }
740 tk 2466
  } else if( seq_ui_backup_req || seq_ui_format_req ) {
634 tk 2467
    SEQ_LCD_Clear();
2468
    SEQ_LCD_CursorSet(0, 0);
740 tk 2469
    //                     <-------------------------------------->
2470
    //                     0123456789012345678901234567890123456789
2471
    if( seq_ui_backup_req )
959 tk 2472
      SEQ_LCD_PrintString("Copy Files - be patient!!!");
740 tk 2473
    else if( seq_ui_format_req )
959 tk 2474
      SEQ_LCD_PrintString("Creating Files - be patient!!!");
740 tk 2475
    else
2476
      SEQ_LCD_PrintString("Don't know what I'm doing! :-/");
637 tk 2477
 
2478
    if( seq_file_backup_notification != NULL ) {
2479
      int i;
2480
 
2481
      SEQ_LCD_CursorSet(0, 1);
959 tk 2482
      SEQ_LCD_PrintFormattedString("Creating %s", seq_file_backup_notification);
637 tk 2483
 
2484
      SEQ_LCD_CursorSet(40+3, 0);
2485
      SEQ_LCD_PrintString("Total: [");
2486
      for(i=0; i<20; ++i)
2487
    SEQ_LCD_PrintChar((i>(seq_file_backup_percentage/5)) ? ' ' : '#');
2488
      SEQ_LCD_PrintFormattedString("] %3d%%", seq_file_backup_percentage);
2489
 
2490
      SEQ_LCD_CursorSet(40+3, 1);
2491
      SEQ_LCD_PrintString("File:  [");
2492
      for(i=0; i<20; ++i)
1261 tk 2493
    SEQ_LCD_PrintChar((i>(file_copy_percentage/5)) ? ' ' : '#');
2494
      SEQ_LCD_PrintFormattedString("] %3d%%", file_copy_percentage);
637 tk 2495
    }
2496
 
496 tk 2497
  } else if( seq_ui_button_state.MENU_PRESSED && !seq_ui_button_state.MENU_FIRST_PAGE_SELECTED ) {
2498
    SEQ_LCD_CursorSet(0, 0);
2499
    //                   <-------------------------------------->
2500
    //                   0123456789012345678901234567890123456789
306 tk 2501
    SEQ_LCD_PrintString("Menu Shortcuts:");
2502
    SEQ_LCD_PrintSpaces(25 + 40);
2503
    SEQ_LCD_CursorSet(0, 1);
2039 tk 2504
 
2505
    int i;
2506
    for(i=0; i<16; ++i) {
2507
      SEQ_LCD_PrintString(SEQ_UI_PAGES_MenuShortcutNameGet(i));
2508
    }
306 tk 2509
  } else {
2510
    // perform high priority LCD update request
2511
    if( ui_lcd_callback != NULL )
2512
      ui_lcd_callback(1); // high_prio
167 tk 2513
 
306 tk 2514
    // perform low priority LCD update request if requested
2515
    if( seq_ui_display_update_req ) {
2516
      seq_ui_display_update_req = 0; // clear request
328 tk 2517
 
2518
      // ensure that selections are matching with track constraints
2519
      SEQ_UI_CheckSelections();
2520
 
306 tk 2521
      if( ui_lcd_callback != NULL )
2522
    ui_lcd_callback(0); // no high_prio
2523
    }
134 tk 2524
  }
2525
 
353 tk 2526
  // transfer all changed characters to LCD
2527
  SEQ_UI_LCD_Update();
2528
 
2529
  return 0; // no error
2530
}
2531
 
2532
 
2533
/////////////////////////////////////////////////////////////////////////////
2534
// Called from SEQ_UI_LCD_Handler(), but optionally also from other tasks
2535
// to update the LCD screen immediately
2536
/////////////////////////////////////////////////////////////////////////////
1117 tk 2537
// for newer GCC versions it's important to declare constant arrays outside a function
2538
//                                             00112233
2539
static const char animation_l_arrows[2*4+1] = "   >>>> ";
2540
//                                             00112233
2541
static const char animation_r_arrows[2*4+1] = "  < << <";
2542
//                                               00112233
2543
static const char animation_l_brackets[2*4+1] = "   )))) ";
2544
//                                               00112233
2545
static const char animation_r_brackets[2*4+1] = "  ( (( (";
2546
//                                            00112233
2547
static const char animation_l_stars[2*4+1] = "   **** ";
2548
//                                            00112233
2549
static const char animation_r_stars[2*4+1] = "  * ** *";
353 tk 2550
s32 SEQ_UI_LCD_Update(void)
2551
{
625 tk 2552
  // special handling in remote client mode
1316 tk 2553
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT ) {
626 tk 2554
    MIOS32_IRQ_Disable();
1316 tk 2555
    u8 force = seq_midi_sysex_remote_force_lcd_update;
2556
    seq_midi_sysex_remote_force_lcd_update = 0;
626 tk 2557
    MIOS32_IRQ_Enable();
2558
    return SEQ_LCD_Update(force);
625 tk 2559
  }
2560
 
596 tk 2561
  // if UI message active: copy over the text
2562
  if( ui_msg_ctr ) {
774 tk 2563
    char *animation_l_ptr;
2564
    char *animation_r_ptr;
596 tk 2565
    u8 msg_x = 0;
2566
    u8 right_aligned = 0;
740 tk 2567
    u8 disable_message = 0;
299 tk 2568
 
596 tk 2569
    switch( ui_msg_type ) {
2570
      case SEQ_UI_MSG_SDCARD: {
1117 tk 2571
    animation_l_ptr = (char *)animation_l_arrows;
2572
    animation_r_ptr = (char *)animation_r_arrows;
596 tk 2573
    msg_x = 0; // MEMO: print such important information at first LCD for the case the user hasn't connected the second LCD yet
2574
    right_aligned = 0;
2575
      } break;
2576
 
756 tk 2577
      case SEQ_UI_MSG_DELAYED_ACTION:
2578
      case SEQ_UI_MSG_DELAYED_ACTION_R: {
1117 tk 2579
    animation_l_ptr = (char *)animation_l_brackets;
2580
    animation_r_ptr = (char *)animation_r_brackets;
756 tk 2581
    if( ui_msg_type == SEQ_UI_MSG_DELAYED_ACTION_R ) {
2582
      msg_x = 40; // right LCD
2583
      right_aligned = 0;
2584
    } else {
2585
      msg_x = 39; // left LCD
2586
      right_aligned = 1;
2587
    }
740 tk 2588
 
2589
    if( ui_delayed_action_callback == NULL ) {
2590
      disable_message = 1; // button has been depressed before delay
2591
    } else {
2592
      int seconds = (ui_delayed_action_ctr / 1000) + 1;
2593
      if( seconds == 1 )
2594
        sprintf(ui_msg[0], "Hold for 1 second ");
2595
      else
2596
        sprintf(ui_msg[0], "Hold for %d seconds", seconds);
2597
    }
2598
      } break;
2599
 
741 tk 2600
      case SEQ_UI_MSG_USER_R: {
1117 tk 2601
    animation_l_ptr = (char *)animation_l_stars;
2602
    animation_r_ptr = (char *)animation_r_stars;
741 tk 2603
    msg_x = 40; // right display
2604
    right_aligned = 0;
2605
      } break;
2606
 
596 tk 2607
      default: {
1117 tk 2608
    animation_l_ptr = (char *)animation_l_stars;
2609
    animation_r_ptr = (char *)animation_r_stars;
596 tk 2610
    msg_x = 39;
2611
    right_aligned = 1;
2612
      } break;
2613
 
2614
    }
2615
 
740 tk 2616
    if( !disable_message ) {
2617
      int anum = (ui_msg_ctr % 1000) / 250;
596 tk 2618
 
740 tk 2619
      int len[2];
2620
      len[0] = strlen((char *)ui_msg[0]);
2621
      len[1] = strlen((char *)ui_msg[1]);
2622
      int len_max = len[0];
2623
      if( len[1] > len_max )
2624
    len_max = len[1];
596 tk 2625
 
740 tk 2626
      if( right_aligned )
2627
    msg_x -= (9 + len_max);
596 tk 2628
 
740 tk 2629
      int line;
2630
      for(line=0; line<2; ++line) {
2631
    SEQ_LCD_CursorSet(msg_x, line);
596 tk 2632
 
740 tk 2633
    // ensure that both lines are padded with same number of spaces
2634
    int end_pos = len[line];
2635
    while( end_pos < len_max )
2636
      ui_msg[line][end_pos++] = ' ';
2637
    ui_msg[line][end_pos] = 0;
2638
 
2639
    SEQ_LCD_PrintFormattedString(" %c%c| %s |%c%c ",
2640
                     *(animation_l_ptr + 2*anum + 0), *(animation_l_ptr + 2*anum + 1),
2641
                     (char *)ui_msg[line],
2642
                     *(animation_r_ptr + 2*anum + 0), *(animation_r_ptr + 2*anum + 1));
2643
      }
299 tk 2644
    }
2645
  }
2646
 
278 tk 2647
  // transfer all changed characters to LCD
353 tk 2648
  // SEQ_LCD_Update provides a MUTEX handling to allow updates from different tasks
2649
  return SEQ_LCD_Update(0);
134 tk 2650
}
2651
 
2652
 
2653
/////////////////////////////////////////////////////////////////////////////
2654
// Update all LEDs
2655
// Usually called from background task
2656
/////////////////////////////////////////////////////////////////////////////
2657
s32 SEQ_UI_LED_Handler(void)
2658
{
1811 tk 2659
  u8 visible_track = SEQ_UI_VisibleTrackGet();
626 tk 2660
  static u8 remote_led_sr[SEQ_LED_NUM_SR];
2661
 
625 tk 2662
  // ignore in remote client mode
1316 tk 2663
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT )
625 tk 2664
    return 0; // no error
2665
 
1044 tk 2666
  // ignore as long as hardware config hasn't been read
496 tk 2667
  if( !SEQ_FILE_HW_ConfigLocked() )
2668
    return -1;
2669
 
134 tk 2670
  // track LEDs
987 tk 2671
  // in pattern page: track buttons are used as group buttons
2672
  if( ui_page == SEQ_UI_PAGE_PATTERN ) {
2673
    SEQ_LED_PinSet(seq_hwcfg_led.track[0], (ui_selected_group == 0));
2674
    SEQ_LED_PinSet(seq_hwcfg_led.track[1], (ui_selected_group == 1));
2675
    SEQ_LED_PinSet(seq_hwcfg_led.track[2], (ui_selected_group == 2));
2676
    SEQ_LED_PinSet(seq_hwcfg_led.track[3], (ui_selected_group == 3));
2677
  } else if( ui_page == SEQ_UI_PAGE_SONG ) {
2678
    // in song page: track and group buttons are used to select the cursor position
2679
    SEQ_LED_PinSet(seq_hwcfg_led.track[0], (ui_selected_item == 3));
2680
    SEQ_LED_PinSet(seq_hwcfg_led.track[1], (ui_selected_item == 4));
2681
    SEQ_LED_PinSet(seq_hwcfg_led.track[2], (ui_selected_item == 5));
2682
    SEQ_LED_PinSet(seq_hwcfg_led.track[3], (ui_selected_item == 6));