Subversion Repositories svn.mios32

Rev

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