Subversion Repositories svn.mios32

Rev

Rev 2164 | Rev 2168 | 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 2166 2015-04-26 15:50:16Z 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
 
2166 tk 790
  // change to record page
791
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKJAM);
630 tk 792
 
793
  return 0; // no error
794
}
795
 
1219 tk 796
static s32 SEQ_UI_Button_Live(s32 depressed)
797
{
798
  if( depressed ) return -1; // ignore when button depressed
799
 
800
  // change to live page
801
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKLIVE);
802
 
803
  return 0; // no error
804
}
805
 
134 tk 806
static s32 SEQ_UI_Button_Utility(s32 depressed)
807
{
808
  if( depressed ) return -1; // ignore when button depressed
809
 
240 tk 810
  // change to utility page
811
  SEQ_UI_PageSet(SEQ_UI_PAGE_UTIL);
812
 
134 tk 813
  return 0; // no error
814
}
815
 
1281 tk 816
static s32 SEQ_UI_Button_MultiCopy(s32 depressed)
817
{
818
  if( depressed ) return 1;
819
 
820
  s32 status = 0;
821
  char path[30];
822
 
823
  // create directory if it doesn't exist
824
  strcpy(path, "/PRESETS");
825
  MUTEX_SDCARD_TAKE;
826
  status = FILE_MakeDir(path);
827
  status = FILE_DirExists(path);
828
  MUTEX_SDCARD_GIVE;
829
 
830
  if( status < 0 ) {
831
    SEQ_UI_SDCardErrMsg(2000, status);
832
    return -3;
833
  }
834
 
835
  if( status == 0 ) {
836
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 2000, "/PRESETS directory", "cannot be created!");
837
    return -4;
838
  }
839
 
840
  // copy all selected patterns to preset directory
841
  u8 track, track_id;
842
  for(track=0, track_id=0; track<SEQ_CORE_NUM_TRACKS; ++track) {
843
    if( ui_selected_tracks & (1 << track) ) {
844
      ++track_id;
845
      sprintf(path, "/PRESETS/COPY%d.v4t", track_id);
846
 
847
      char str[30];
848
      sprintf(str, "Exporting G%dT%d to:", (track/4)+1, (track%4)+1);
849
      SEQ_UI_Msg(SEQ_UI_MSG_USER, 2000, str, path);
850
 
851
      MUTEX_SDCARD_TAKE;
1282 tk 852
      status=SEQ_FILE_T_Write(path, track);
1281 tk 853
      MUTEX_SDCARD_GIVE;
854
 
855
      if( status < 0 ) {
856
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 2000, "Error during Export!", "see MIOS Terminal!");
857
    return -6;
858
      }
859
    }
860
  }
861
 
862
  if( !track_id ) {
863
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 2000, "No Track selected", "for Multi-Copy!");
864
  }
865
 
866
  return 0; // no error
867
}
868
 
134 tk 869
static s32 SEQ_UI_Button_Copy(s32 depressed)
870
{
240 tk 871
  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
134 tk 872
 
240 tk 873
  seq_ui_button_state.COPY = depressed ? 0 : 1;
874
 
280 tk 875
  if( ui_page == SEQ_UI_PAGE_MIXER ) {
876
    if( depressed ) return -1;
877
    SEQ_UI_MIXER_Copy();
1527 tk 878
    SEQ_UI_Msg_MixerMap("copied");
280 tk 879
    return 1;
729 tk 880
  } else if( ui_page == SEQ_UI_PAGE_SONG ) {
881
    if( depressed ) return -1;
882
    SEQ_UI_SONG_Copy();
1527 tk 883
    SEQ_UI_Msg_SongPos("copied");
729 tk 884
    return 1;
2164 tk 885
  } else if( SEQ_UI_TRKJAM_PatternRecordSelected() ) {
2148 tk 886
    if( depressed ) return -1;
887
    SEQ_UI_UTIL_CopyLivePattern();
888
    SEQ_UI_Msg_LivePattern("copied");
889
    return 1;
280 tk 890
  } else {
1877 tk 891
    if( seq_ui_button_state.MENU_PRESSED ) {
892
      return SEQ_UI_Button_MultiCopy(depressed);
893
    }
894
 
280 tk 895
    if( !depressed ) {
896
      prev_page = ui_page;
897
      SEQ_UI_PageSet(SEQ_UI_PAGE_UTIL);
898
    }
240 tk 899
 
280 tk 900
    s32 status = SEQ_UI_UTIL_CopyButton(depressed);
240 tk 901
 
596 tk 902
    if( depressed ) {
903
      if( prev_page != SEQ_UI_PAGE_UTIL )
904
    SEQ_UI_PageSet(prev_page);
240 tk 905
 
1527 tk 906
      SEQ_UI_Msg_Track("copied");
596 tk 907
    }
908
 
280 tk 909
    return status;
910
  }
134 tk 911
}
912
 
1281 tk 913
static s32 SEQ_UI_Button_MultiPaste(s32 depressed)
914
{
915
  if( depressed ) return 1;
916
 
917
  s32 status = 0;
918
  char path[30];
919
 
920
  // paste multi copy presets into selected tracks
921
  u8 track, track_id;
922
  for(track=0, track_id=0; track<SEQ_CORE_NUM_TRACKS; ++track) {
923
    if( ui_selected_tracks & (1 << track) ) {
924
      ++track_id;
925
      sprintf(path, "/PRESETS/COPY%d.v4t", track_id);
926
 
927
      char str[30];
928
      sprintf(str, "Importing to G%dT%d:", (track/4)+1, (track%4)+1);
929
      SEQ_UI_Msg(SEQ_UI_MSG_USER, 2000, str, path);
930
 
931
      // mute track to avoid random effects while loading the file
932
      MIOS32_IRQ_Disable(); // this operation should be atomic!
933
      u8 muted = seq_core_trk_muted & (1 << track);
934
      if( !muted )
935
    seq_core_trk_muted |= (1 << track);
936
      MIOS32_IRQ_Enable();
937
 
938
      static seq_file_t_import_flags_t import_flags;
939
      import_flags.ALL = 0xff;
940
 
941
      // read file
942
      MUTEX_SDCARD_TAKE;
943
      status = SEQ_FILE_T_Read(path, track, import_flags);
944
      MUTEX_SDCARD_GIVE;
945
 
946
      // unmute track if it wasn't muted before
947
      MIOS32_IRQ_Disable(); // this operation should be atomic!
948
      if( !muted )
949
    seq_core_trk_muted &= ~(1 << track);
950
      MIOS32_IRQ_Enable();
951
 
952
      if( status == FILE_ERR_OPEN_READ ) {
953
    char str[30];
954
    sprintf(str, "File for G%dT%d missing:", (track/4)+1, (track%4)+1);
955
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 2000, str, path);
956
      } else if( status < 0 ) {
957
    SEQ_UI_SDCardErrMsg(2000, status);
958
      } else {
959
    sprintf(str, "Imported to G%dT%d:", (track/4)+1, (track%4)+1);
960
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 2000, str, path);
961
      }
962
    }
963
  }
964
 
965
  if( !track_id ) {
966
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 2000, "No Track selected", "for Multi-Paste!");
967
  }
968
 
969
  return 0; // no error
970
}
971
 
134 tk 972
static s32 SEQ_UI_Button_Paste(s32 depressed)
973
{
240 tk 974
  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
134 tk 975
 
240 tk 976
  seq_ui_button_state.PASTE = depressed ? 0 : 1;
977
 
280 tk 978
  if( ui_page == SEQ_UI_PAGE_MIXER ) {
979
    if( depressed ) return -1;
980
    SEQ_UI_MIXER_Paste();
1527 tk 981
    SEQ_UI_Msg_MixerMap("pasted");
280 tk 982
    return 1;
729 tk 983
  } else if( ui_page == SEQ_UI_PAGE_SONG ) {
984
    if( depressed ) return -1;
985
    SEQ_UI_SONG_Paste();
1527 tk 986
    SEQ_UI_Msg_SongPos("pasted");
729 tk 987
    return 1;
2164 tk 988
  } else if( SEQ_UI_TRKJAM_PatternRecordSelected() ) {
2148 tk 989
    if( depressed ) return -1;
990
    SEQ_UI_UTIL_PasteLivePattern();
991
    SEQ_UI_Msg_LivePattern("pasted");
992
    return 1;
280 tk 993
  } else {
1877 tk 994
    if( seq_ui_button_state.MENU_PRESSED ) {
995
      return SEQ_UI_Button_MultiPaste(depressed);
996
    }
997
 
280 tk 998
    if( !depressed ) {
999
      prev_page = ui_page;
1000
      SEQ_UI_PageSet(SEQ_UI_PAGE_UTIL);
1001
    }
240 tk 1002
 
280 tk 1003
    s32 status = SEQ_UI_UTIL_PasteButton(depressed);
596 tk 1004
    if( depressed ) {
1005
      if( prev_page != SEQ_UI_PAGE_UTIL )
1006
    SEQ_UI_PageSet(prev_page);
240 tk 1007
 
1877 tk 1008
      if( seq_ui_button_state.SELECT_PRESSED )
1009
    SEQ_UI_Msg_Layer("pasted");
1010
      else
1011
    SEQ_UI_Msg_Track("pasted");
596 tk 1012
    }
1013
 
280 tk 1014
    return status;
1015
  }
134 tk 1016
}
1017
 
740 tk 1018
 
1019
// callback function for delayed Clear Mixer function
752 tk 1020
static void SEQ_UI_Button_Clear_Mixer(u32 dummy)
740 tk 1021
{
1022
  SEQ_UI_MIXER_Clear();
1527 tk 1023
  SEQ_UI_Msg_MixerMap("cleared");
740 tk 1024
}
1025
 
1026
// callback function for delayed Clear SongPos function
752 tk 1027
static void SEQ_UI_Button_Clear_SongPos(u32 dummy)
740 tk 1028
{
1029
  SEQ_UI_SONG_Clear();
1527 tk 1030
  SEQ_UI_Msg_SongPos("cleared");
740 tk 1031
}
1032
 
2148 tk 1033
// callback function for delayed Clear LivePattern function
1034
static void SEQ_UI_Button_Clear_LivePattern(u32 dummy)
1035
{
1036
  SEQ_UI_UTIL_ClearLivePattern();
1037
  SEQ_UI_Msg_LivePattern("cleared");
1038
}
1039
 
740 tk 1040
// callback function for clear track
752 tk 1041
static void SEQ_UI_Button_Clear_Track(u32 dummy)
740 tk 1042
{
1043
  SEQ_UI_UTIL_ClearButton(0); // button pressed
1044
  SEQ_UI_UTIL_ClearButton(1); // button depressed
1877 tk 1045
  if( seq_ui_button_state.SELECT_PRESSED )
1046
    SEQ_UI_Msg_Layer("cleared");
1047
  else
1048
    SEQ_UI_Msg_Track("cleared");
740 tk 1049
}
1050
 
134 tk 1051
static s32 SEQ_UI_Button_Clear(s32 depressed)
1052
{
1523 tk 1053
#if 0
1054
  u32 clear_delay = 2000;
1055
#else
1056
  u32 clear_delay = 50; // TK: I prefer a much faster clear
1057
#endif
240 tk 1058
  seq_ui_button_state.CLEAR = depressed ? 0 : 1;
280 tk 1059
 
1060
  if( ui_page == SEQ_UI_PAGE_MIXER ) {
740 tk 1061
    if( depressed )
1062
      SEQ_UI_UnInstallDelayedActionCallback(SEQ_UI_Button_Clear_Mixer);
752 tk 1063
    else {
1523 tk 1064
      SEQ_UI_InstallDelayedActionCallback(SEQ_UI_Button_Clear_Mixer, clear_delay, 0);
1065
      SEQ_UI_Msg(SEQ_UI_MSG_DELAYED_ACTION, clear_delay+1, "", "to clear Mixer Map");
752 tk 1066
    }
729 tk 1067
    return 1;
1068
  } else if( ui_page == SEQ_UI_PAGE_SONG ) {
740 tk 1069
    if( depressed )
1070
      SEQ_UI_UnInstallDelayedActionCallback(SEQ_UI_Button_Clear_SongPos);
752 tk 1071
    else {
1523 tk 1072
      SEQ_UI_InstallDelayedActionCallback(SEQ_UI_Button_Clear_SongPos, clear_delay, 0);
1073
      SEQ_UI_Msg(SEQ_UI_MSG_DELAYED_ACTION, clear_delay+1, "", "to clear SongPos");
752 tk 1074
    }
729 tk 1075
    return 1;
2164 tk 1076
  } else if( SEQ_UI_TRKJAM_PatternRecordSelected() ) {
2148 tk 1077
    if( depressed )
1078
      SEQ_UI_UnInstallDelayedActionCallback(SEQ_UI_Button_Clear_LivePattern);
1079
    else {
1080
      SEQ_UI_InstallDelayedActionCallback(SEQ_UI_Button_Clear_LivePattern, clear_delay, 0);
1081
      SEQ_UI_Msg(SEQ_UI_MSG_DELAYED_ACTION, clear_delay+1, "", "to clear Pattern");
1082
    }
1083
    return 1;
729 tk 1084
  } else {
740 tk 1085
    if( depressed )
1086
      SEQ_UI_UnInstallDelayedActionCallback(SEQ_UI_Button_Clear_Track);
752 tk 1087
    else {
1523 tk 1088
      SEQ_UI_InstallDelayedActionCallback(SEQ_UI_Button_Clear_Track, clear_delay, 0);
1089
      SEQ_UI_Msg(SEQ_UI_MSG_DELAYED_ACTION, clear_delay+1, "", "to clear Track");
752 tk 1090
    }
280 tk 1091
    return 1;
1092
  }
134 tk 1093
}
1094
 
1014 tk 1095
 
1096
static s32 SEQ_UI_Button_Undo(s32 depressed)
1097
{
1098
  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
1099
 
1100
  seq_ui_button_state.UNDO = depressed ? 0 : 1;
1101
 
1102
  if( ui_page == SEQ_UI_PAGE_MIXER ) {
1103
    if( depressed ) return -1;
1104
    SEQ_UI_MIXER_Undo();
1527 tk 1105
    SEQ_UI_Msg_MixerMap("Undo applied");
1014 tk 1106
    return 1;
1107
  } else {
1108
    if( !depressed ) {
1109
      prev_page = ui_page;
1110
      SEQ_UI_PageSet(SEQ_UI_PAGE_UTIL);
1111
    }
1112
 
1113
    s32 status = SEQ_UI_UTIL_UndoButton(depressed);
1114
 
1115
    if( depressed ) {
1116
      if( prev_page != SEQ_UI_PAGE_UTIL )
1117
    SEQ_UI_PageSet(prev_page);
1118
 
1527 tk 1119
      SEQ_UI_Msg_Track("Undo applied");
1014 tk 1120
    }
1121
 
1122
    return status;
1123
  }
1124
}
1125
 
1126
 
134 tk 1127
static s32 SEQ_UI_Button_Menu(s32 depressed)
1128
{
513 tk 1129
  if( seq_hwcfg_button_beh.menu ) {
1130
    // toggle mode
1131
    if( depressed ) return -1; // ignore when button depressed
1132
    seq_ui_button_state.MENU_FIRST_PAGE_SELECTED = 0;
678 tk 1133
    if( !seq_ui_button_state.MENU_PRESSED ) // due to page change: button going to be set, clear other toggle buttons
1134
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 1135
    seq_ui_button_state.MENU_PRESSED ^= 1; // toggle MENU pressed (will also be released once GP button has been pressed)
1136
  } else {
1137
    // set mode
1138
    seq_ui_button_state.MENU_FIRST_PAGE_SELECTED = 0;
1139
    seq_ui_button_state.MENU_PRESSED = depressed ? 0 : 1;
1140
  }
134 tk 1141
 
1142
  return 0; // no error
1143
}
1144
 
1203 tk 1145
 
1146
static s32 SEQ_UI_Button_Bookmark(s32 depressed)
1147
{
1148
  if( seq_hwcfg_button_beh.bookmark ) {
1149
    if( depressed ) return -1; // ignore when button depressed
1150
    if( !seq_ui_button_state.BOOKMARK ) // due to page change: button going to be set, clear other toggle buttons
1151
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
1152
#if 0
1153
    seq_ui_button_state.BOOKMARK ^= 1; // toggle BOOKMARK pressed (will also be released once GP button has been pressed)
1154
#else
1155
    seq_ui_button_state.BOOKMARK = 1; // seems that it's better *not* to toggle!
1156
#endif
1157
  } else {
1158
    // set mode
1159
    seq_ui_button_state.BOOKMARK = depressed ? 0 : 1;
1160
  }
1161
 
1162
  if( seq_ui_button_state.BOOKMARK ) {
1163
    if( ui_page != SEQ_UI_PAGE_BOOKMARKS )
1164
      ui_page_before_bookmark = ui_page;
1165
    SEQ_UI_PageSet(SEQ_UI_PAGE_BOOKMARKS);
1166
  } else {
1167
    if( ui_page == SEQ_UI_PAGE_BOOKMARKS )
1168
      SEQ_UI_PageSet(ui_page_before_bookmark);
1169
  }
1170
 
1171
  return 0; // no error
1172
}
1173
 
1174
 
1205 tk 1175
static s32 SEQ_UI_Button_DirectBookmark(s32 depressed, u32 bookmark_button)
1176
{
1177
  if( !depressed )
1178
    ui_page_before_bookmark = ui_page;
1179
 
1180
  return SEQ_UI_BOOKMARKS_Button_Handler(bookmark_button, depressed);
1181
}
1182
 
1183
 
134 tk 1184
static s32 SEQ_UI_Button_Select(s32 depressed)
1185
{
1203 tk 1186
  // double function: -> Bookmark if menu button pressed
1187
  if( seq_ui_button_state.MENU_PRESSED )
1188
    return SEQ_UI_Button_Bookmark(depressed);
1189
 
168 tk 1190
  // forward to menu page
1877 tk 1191
  seq_ui_button_state.SELECT_PRESSED = depressed ? 0 : 1;
1192
  if( ui_button_callback != NULL ) {
1193
    ui_button_callback(SEQ_UI_BUTTON_Select, depressed);
1194
    ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0;
591 tk 1195
  }
134 tk 1196
 
1197
  return 0; // no error
1198
}
1199
 
1200
static s32 SEQ_UI_Button_Exit(s32 depressed)
1201
{
951 tk 1202
  // double function: -> Follow if menu button pressed
1203
  if( seq_ui_button_state.MENU_PRESSED )
1204
    return SEQ_UI_Button_Follow(depressed);
1205
 
272 tk 1206
  if( depressed ) return -1; // ignore when button depressed
1207
 
1208
  u8 prev_ui_page = ui_page;
1209
 
168 tk 1210
  // forward to menu page
1123 tk 1211
  if( ui_button_callback != NULL ) {
1212
    if( ui_button_callback(SEQ_UI_BUTTON_Exit, depressed) >= 1 )
1213
      return 1; // page has already handled exit button
740 tk 1214
    ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0;
1215
  }
134 tk 1216
 
167 tk 1217
  // release all button states
984 tk 1218
  // seq_ui_button_state.ALL = 0;
1219
  // clashes with SOLO/ALL/etc.
167 tk 1220
 
272 tk 1221
  // enter menu page if we were not there before
1222
  if( prev_ui_page != SEQ_UI_PAGE_MENU )
1223
    SEQ_UI_PageSet(SEQ_UI_PAGE_MENU);
1224
 
134 tk 1225
  return 0; // no error
1226
}
1227
 
1228
static s32 SEQ_UI_Button_Edit(s32 depressed)
1229
{
741 tk 1230
  seq_ui_button_state.EDIT_PRESSED = depressed ? 0 : 1;
591 tk 1231
 
167 tk 1232
  // change to edit page
1350 tk 1233
  if( !depressed ) {
1234
    SEQ_UI_PageSet(SEQ_UI_PAGE_EDIT);
167 tk 1235
 
1350 tk 1236
    // set/clear encoder fast function if required
1237
    SEQ_UI_InitEncSpeed(1); // auto config
1238
  }
178 tk 1239
 
1350 tk 1240
  // EDIT button notification to button callback
1241
  // currently only used in EDIT page itself!
1242
  if( depressed && ui_page != SEQ_UI_PAGE_EDIT )
1243
    return -1;
1244
 
1245
  if( ui_button_callback != NULL ) {
1246
    ui_button_callback(SEQ_UI_BUTTON_Edit, depressed);
1247
    ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0;
1248
  }
1249
 
134 tk 1250
  return 0; // no error
1251
}
1252
 
1253
static s32 SEQ_UI_Button_Mute(s32 depressed)
1254
{
591 tk 1255
  seq_ui_button_state.MUTE_PRESSED = depressed ? 0 : 1;
1256
 
134 tk 1257
  if( depressed ) return -1; // ignore when button depressed
1258
 
184 tk 1259
  SEQ_UI_PageSet(SEQ_UI_PAGE_MUTE);
1260
 
134 tk 1261
  return 0; // no error
1262
}
1263
 
1264
static s32 SEQ_UI_Button_Pattern(s32 depressed)
1265
{
591 tk 1266
  seq_ui_button_state.PATTERN_PRESSED = depressed ? 0 : 1;
1267
 
134 tk 1268
  if( depressed ) return -1; // ignore when button depressed
1269
 
184 tk 1270
  SEQ_UI_PageSet(SEQ_UI_PAGE_PATTERN);
1271
 
134 tk 1272
  return 0; // no error
1273
}
1274
 
1454 midilab 1275
static s32 SEQ_UI_Button_Pattern_Remix(s32 depressed)
1276
{
1277
 
1278
    if ( ui_page == SEQ_UI_PAGE_PATTERN_RMX ) {
2161 tk 1279
#ifndef MIOS32_FAMILY_EMULATION
1454 midilab 1280
        // to avoid race conditions using the same button(any other way of solving that?)
1281
        vTaskDelay(60);
2161 tk 1282
#endif
1454 midilab 1283
        // a trick to use the same button with 2 functionalitys
1284
        ui_button_callback(SEQ_UI_BUTTON_Edit, depressed);
1285
    } else {
1286
        SEQ_UI_PageSet(SEQ_UI_PAGE_PATTERN_RMX);
1287
    }
1288
 
1289
    return 0; // no error
1290
 
1291
}
1292
 
134 tk 1293
static s32 SEQ_UI_Button_Song(s32 depressed)
1294
{
591 tk 1295
  seq_ui_button_state.SONG_PRESSED = depressed ? 0 : 1;
1296
 
134 tk 1297
  if( depressed ) return -1; // ignore when button depressed
1298
 
399 tk 1299
  SEQ_UI_PageSet(SEQ_UI_PAGE_SONG);
1300
 
134 tk 1301
  return 0; // no error
1302
}
1303
 
1304
static s32 SEQ_UI_Button_Solo(s32 depressed)
1305
{
513 tk 1306
  if( seq_hwcfg_button_beh.solo ) {
1307
    // toggle mode
1308
    if( depressed ) return -1; // ignore when button depressed
2110 tk 1309
    seq_ui_button_state.SOLO ^= 1;    
513 tk 1310
  } else {
1311
    // set mode
1312
    seq_ui_button_state.SOLO = depressed ? 0 : 1;
1313
  }
134 tk 1314
 
2110 tk 1315
  // seq_core_trk_soloed currently only used for the BLM16x16+X
1316
  // which overrules the legacy SOLO function
1317
  if( !seq_ui_button_state.SOLO )
1318
    seq_core_trk_soloed = 0;
1319
 
134 tk 1320
  return 0; // no error
1321
}
1322
 
1323
static s32 SEQ_UI_Button_Fast(s32 depressed)
1324
{
513 tk 1325
  if( seq_hwcfg_button_beh.fast ) {
1326
    // toggle mode
1327
    if( depressed ) return -1; // ignore when button depressed
1328
    seq_ui_button_state.FAST_ENCODERS ^= 1;
1329
  } else {
1330
    // set mode
1331
    seq_ui_button_state.FAST_ENCODERS = depressed ? 0 : 1;
1332
  }
134 tk 1333
 
178 tk 1334
  SEQ_UI_InitEncSpeed(0); // no auto config
1335
 
134 tk 1336
  return 0; // no error
1337
}
1338
 
1121 tk 1339
static s32 SEQ_UI_Button_Fast2(s32 depressed)
1340
{
1341
  if( seq_hwcfg_button_beh.fast2 ) {
1342
    // toggle mode
1343
    if( depressed ) return -1; // ignore when button depressed
1344
    seq_ui_button_state.FAST2_ENCODERS ^= 1;
1345
  } else {
1346
    // set mode
1347
    seq_ui_button_state.FAST2_ENCODERS = depressed ? 0 : 1;
1348
  }
1349
 
1350
  SEQ_UI_InitEncSpeed(0); // no auto config
1351
 
1352
  return 0; // no error
1353
}
1354
 
134 tk 1355
static s32 SEQ_UI_Button_All(s32 depressed)
1356
{
178 tk 1357
  seq_ui_button_state.CHANGE_ALL_STEPS_SAME_VALUE = depressed ? 0 : 1;
134 tk 1358
 
513 tk 1359
  if( seq_hwcfg_button_beh.all ) {
1360
    // toggle mode
1361
    if( depressed ) return -1;
1362
    seq_ui_button_state.CHANGE_ALL_STEPS ^= 1;
1363
  } else {
1364
    // set mode
1365
    seq_ui_button_state.CHANGE_ALL_STEPS = depressed ? 0 : 1;
1366
  }
178 tk 1367
 
134 tk 1368
  return 0; // no error
1369
}
1370
 
1371
static s32 SEQ_UI_Button_StepView(s32 depressed)
1372
{
600 tk 1373
  //  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
1374
  // also used by seq_ui_stepsel
1375
 
513 tk 1376
  if( seq_hwcfg_button_beh.step_view ) {
1377
    if( depressed ) return -1; // ignore when button depressed
678 tk 1378
    if( !seq_ui_button_state.STEP_VIEW ) // due to page change: button going to be set, clear other toggle buttons
1379
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 1380
    seq_ui_button_state.STEP_VIEW ^= 1; // toggle STEP_VIEW pressed (will also be released once GP button has been pressed)
1381
  } else {
1382
    // set mode
1383
    seq_ui_button_state.STEP_VIEW = depressed ? 0 : 1;
1384
  }
134 tk 1385
 
513 tk 1386
  if( seq_ui_button_state.STEP_VIEW ) {
600 tk 1387
    ui_stepview_prev_page = ui_page;
303 tk 1388
    SEQ_UI_PageSet(SEQ_UI_PAGE_STEPSEL);
1389
  } else {
524 tk 1390
    if( ui_page == SEQ_UI_PAGE_STEPSEL )
600 tk 1391
      SEQ_UI_PageSet(ui_stepview_prev_page);
303 tk 1392
  }
134 tk 1393
 
1394
  return 0; // no error
1395
}
1396
 
1713 tk 1397
static s32 SEQ_UI_Button_StepViewInc(s32 depressed)
1398
{
1399
  if( depressed ) return -1; // ignore when button depressed
1400
 
1401
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1402
  int num_steps = SEQ_TRG_NumStepsGet(visible_track);
1403
 
1404
  int new_step_view = ui_selected_step_view + 1;
1405
  if( (16*new_step_view) < num_steps ) {
1406
    // select new step view
1407
    ui_selected_step_view = new_step_view;
1408
 
1409
    // select step within view
1751 tk 1410
    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
1411
      ui_selected_step = (ui_selected_step_view << 4) | (ui_selected_step & 0xf);
1412
    }
1713 tk 1413
  }
1414
 
1415
  char buffer[20];
1416
  sprintf(buffer, "%d-%d", ui_selected_step_view*16 + 1, ui_selected_step_view*16 + 16);
1417
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "Step View", buffer);
1418
 
1419
  return 0; // no error
1420
}
1421
 
1422
static s32 SEQ_UI_Button_StepViewDec(s32 depressed)
1423
{
1424
  if( depressed ) return -1; // ignore when button depressed
1425
 
1426
  int new_step_view = ui_selected_step_view - 1;
1427
  if( new_step_view >= 0 ) {
1428
    // select new step view
1429
    ui_selected_step_view = new_step_view;
1430
 
1431
    // select step within view
1751 tk 1432
    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
1433
      ui_selected_step = (ui_selected_step_view << 4) | (ui_selected_step & 0xf);
1434
    }
1713 tk 1435
  }
1436
 
1437
  char buffer[20];
1438
  sprintf(buffer, "%d-%d", ui_selected_step_view*16 + 1, ui_selected_step_view*16 + 16);
1439
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "Step View", buffer);
1440
 
1441
  return 0; // no error
1442
}
1443
 
513 tk 1444
static s32 SEQ_UI_Button_TrackSel(s32 depressed)
134 tk 1445
{
513 tk 1446
  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
134 tk 1447
 
513 tk 1448
  if( seq_hwcfg_button_beh.track_sel ) {
1449
    if( depressed ) return -1; // ignore when button depressed
678 tk 1450
    if( !seq_ui_button_state.TRACK_SEL ) // due to page change: button going to be set, clear other toggle buttons
1451
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 1452
    seq_ui_button_state.TRACK_SEL ^= 1; // toggle TRACKSEL status (will also be released once GP button has been pressed)
1453
  } else {
1454
    seq_ui_button_state.TRACK_SEL = depressed ? 0 : 1;
1455
  }
1456
 
1457
  if( seq_ui_button_state.TRACK_SEL ) {
1458
    prev_page = ui_page;
1459
    SEQ_UI_PageSet(SEQ_UI_PAGE_TRACKSEL);
1460
  } else {
524 tk 1461
    if( ui_page == SEQ_UI_PAGE_TRACKSEL )
1462
      SEQ_UI_PageSet(prev_page);
513 tk 1463
  }
1464
 
134 tk 1465
  return 0; // no error
1466
}
1467
 
987 tk 1468
static s32 SEQ_UI_Button_Group(s32 depressed, u32 group)
1469
{
1470
  if( depressed ) return -1; // ignore when button depressed
1471
 
1472
  if( group >= 4 ) return -2; // max. 4 group buttons
1473
 
1474
  // in song page: track and group buttons are used to select the cursor position
1475
  if( ui_page == SEQ_UI_PAGE_SONG ) {
1476
    ui_selected_item = 3 + group;
1477
    return 0;
1478
  }
1479
 
1480
  // if group has changed:
1481
  if( group != ui_selected_group ) {
1482
    // get current track selection
1483
    u16 old_tracks = ui_selected_tracks >> (4*ui_selected_group);
1484
 
1485
    // select new group
1486
    ui_selected_group = group;
1487
 
1488
    // take over old track selection
1489
    ui_selected_tracks = old_tracks << (4*ui_selected_group);
1490
  }
1491
 
1492
  // set/clear encoder fast function if required
1493
  SEQ_UI_InitEncSpeed(1); // auto config
1494
 
1495
  return 0; // no error
1496
}
1497
 
484 tk 1498
static s32 SEQ_UI_Button_Track(s32 depressed, u32 track_button)
134 tk 1499
{
484 tk 1500
  static u8 button_state = 0x0f; // all 4 buttons depressed
134 tk 1501
 
484 tk 1502
  if( track_button >= 4 ) return -2; // max. 4 track buttons
134 tk 1503
 
484 tk 1504
  if( depressed ) {
1505
    button_state |= (1 << track_button);
1506
    return 0; // no error
1507
  }
134 tk 1508
 
484 tk 1509
  button_state &= ~(1 << track_button);
1510
 
987 tk 1511
  // in pattern and song page: use track buttons as group buttons
1512
  if( ui_page == SEQ_UI_PAGE_PATTERN || ui_page == SEQ_UI_PAGE_SONG ) {
1513
    return SEQ_UI_Button_Group(depressed, track_button);
1514
  }
1515
 
484 tk 1516
  if( button_state == (~(1 << track_button) & 0xf) ) {
1517
    // if only one select button pressed: radio-button function (1 of 4)
1518
    ui_selected_tracks = 1 << (track_button + 4*ui_selected_group);
1519
  } else {
1520
    // if more than one select button pressed: toggle function (4 of 4)
1521
    ui_selected_tracks ^= 1 << (track_button + 4*ui_selected_group);
1522
  }
1523
 
178 tk 1524
  // set/clear encoder fast function if required
1525
  SEQ_UI_InitEncSpeed(1); // auto config
1526
 
134 tk 1527
  return 0; // no error
1528
}
1529
 
1146 tk 1530
static s32 SEQ_UI_Button_DirectTrack(s32 depressed, u32 track_button)
1531
{
1532
  static u16 button_state = 0xffff; // all 16 buttons depressed
1533
 
1534
  if( track_button >= 16 ) return -2; // max. 16 direct track buttons
1535
 
1536
  if( depressed ) {
1537
    button_state |= (1 << track_button);
1538
    return 0; // no error
1539
  }
1540
 
1541
  button_state &= ~(1 << track_button);
1542
 
1543
  if( button_state == (~(1 << track_button) & 0xffff) ) {
1544
    // if only one select button pressed: radio-button function (1 of 16)
1545
    ui_selected_tracks = 1 << track_button;
1488 tk 1546
    ui_selected_group = track_button / 4;
1146 tk 1547
  } else {
1548
    // if more than one select button pressed: toggle function (16 of 16)
1549
    ui_selected_tracks ^= 1 << track_button;
1550
  }
1551
 
1552
  // set/clear encoder fast function if required
1553
  SEQ_UI_InitEncSpeed(1); // auto config
1554
 
1555
  return 0; // no error
1556
}
1557
 
513 tk 1558
static s32 SEQ_UI_Button_ParLayerSel(s32 depressed)
1559
{
600 tk 1560
  // static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
1561
  // also used by seq_ui_parsel.c
513 tk 1562
 
1563
  if( seq_hwcfg_button_beh.par_layer ) {
1564
    if( depressed ) return -1; // ignore when button depressed
678 tk 1565
    if( !seq_ui_button_state.PAR_LAYER_SEL ) // due to page change: button going to be set, clear other toggle buttons
1566
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 1567
    seq_ui_button_state.PAR_LAYER_SEL ^= 1; // toggle PARSEL status (will also be released once GP button has been pressed)
1568
  } else {
1569
    seq_ui_button_state.PAR_LAYER_SEL = depressed ? 0 : 1;
1570
  }
1571
 
1572
  if( seq_ui_button_state.PAR_LAYER_SEL ) {
600 tk 1573
    ui_parlayer_prev_page = ui_page;
513 tk 1574
    SEQ_UI_PageSet(SEQ_UI_PAGE_PARSEL);
1575
  } else {
524 tk 1576
    if( ui_page == SEQ_UI_PAGE_PARSEL )
600 tk 1577
      SEQ_UI_PageSet(ui_parlayer_prev_page);
513 tk 1578
  }
1579
 
1580
  // set/clear encoder fast function if required
1581
  SEQ_UI_InitEncSpeed(1); // auto config
1582
 
1583
  return 0; // no error
1584
}
1585
 
134 tk 1586
static s32 SEQ_UI_Button_ParLayer(s32 depressed, u32 par_layer)
1587
{
1117 tk 1588
  static u8 layer_c_pressed = 0;
784 tk 1589
 
134 tk 1590
  if( par_layer >= 3 ) return -2; // max. 3 parlayer buttons
1591
 
1205 tk 1592
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1593
  u8 num_p_layers = SEQ_PAR_NumLayersGet(visible_track);
1594
 
987 tk 1595
  // in song page: parameter layer buttons are used to select the cursor position
1596
  if( ui_page == SEQ_UI_PAGE_SONG ) {
1597
    ui_selected_item = par_layer;
1598
    return 0;
1599
  }
1600
 
1205 tk 1601
  // drum mode in edit page: print parameter layer as long as button is pressed
1602
  if( ui_page == SEQ_UI_PAGE_EDIT ) {
1603
    u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
1604
    if( event_mode == SEQ_EVENT_MODE_Drum ) {
1605
      ui_hold_msg_ctr = depressed ? 0 : ~0; // show value for at least 65 seconds... enough?
1606
    }
1607
  }
134 tk 1608
 
784 tk 1609
  // holding Layer C button allows to increment/decrement layer with A/B button
1610
  if( par_layer == 2 )
1611
    layer_c_pressed = !depressed;
1612
 
1613
  if( layer_c_pressed && par_layer == 0 ) {
333 tk 1614
    if( depressed ) return -1; // ignore when button depressed
784 tk 1615
    // increment layer
1616
    if( ++ui_selected_par_layer >= num_p_layers )
1617
      ui_selected_par_layer = 0;
1618
  } else if( layer_c_pressed && par_layer == 1 ) {
333 tk 1619
    if( depressed ) return -1; // ignore when button depressed
784 tk 1620
    // decrement layer
1621
    if( ui_selected_par_layer == 0 )
1622
      ui_selected_par_layer = num_p_layers - 1;
333 tk 1623
    else
784 tk 1624
      --ui_selected_par_layer;
333 tk 1625
  } else {
784 tk 1626
    if( num_p_layers <= 3 ) {
1627
      // 3 layers: direct selection with LayerA/B/C button
333 tk 1628
      if( depressed ) return -1; // ignore when button depressed
784 tk 1629
      if( par_layer >= num_p_layers ) {
1630
    char str1[21];
1631
    sprintf(str1, "Parameter Layer %c", 'A'+par_layer);
1632
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, str1, "not available!");
1633
      } else {
1634
    seq_ui_button_state.PAR_LAYER_SEL = 0;
1635
    ui_selected_par_layer = par_layer;
1636
      }
1637
    } else if( num_p_layers <= 4 ) {
1638
      // 4 layers: LayerC Button toggles between C and D
1639
      if( depressed ) return -1; // ignore when button depressed
333 tk 1640
      seq_ui_button_state.PAR_LAYER_SEL = 0;
784 tk 1641
      if( par_layer == 2 )
1642
    ui_selected_par_layer = (ui_selected_par_layer == 2) ? 3 : 2;
1643
      else
1644
    ui_selected_par_layer = par_layer;
333 tk 1645
    } else {
784 tk 1646
      // >4 layers: LayerA/B button selects directly, Layer C button enters layer selection page
1647
      if( par_layer <= 1 ) {
1648
    if( depressed ) return -1; // ignore when button depressed
1649
    seq_ui_button_state.PAR_LAYER_SEL = 0;
1650
    ui_selected_par_layer = par_layer;
1651
      } else {
1652
    return SEQ_UI_Button_ParLayerSel(depressed);
1653
      }
333 tk 1654
    }
1655
  }
1656
 
178 tk 1657
  // set/clear encoder fast function if required
1658
  SEQ_UI_InitEncSpeed(1); // auto config
1659
 
134 tk 1660
  return 0; // no error
1661
}
1662
 
513 tk 1663
static s32 SEQ_UI_Button_TrgLayerSel(s32 depressed)
1664
{
600 tk 1665
  // static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
1666
  // also used by seq_ui_trgsel.c
513 tk 1667
 
1668
  if( seq_hwcfg_button_beh.trg_layer ) {
1669
    if( depressed ) return -1; // ignore when button depressed
678 tk 1670
    if( !seq_ui_button_state.TRG_LAYER_SEL ) // due to page change: button going to be set, clear other toggle buttons
1671
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 1672
    seq_ui_button_state.TRG_LAYER_SEL ^= 1; // toggle TRGSEL status (will also be released once GP button has been pressed)
1673
  } else {
1674
    seq_ui_button_state.TRG_LAYER_SEL = depressed ? 0 : 1;
1675
  }
1676
 
1677
  if( seq_ui_button_state.TRG_LAYER_SEL ) {
600 tk 1678
    ui_trglayer_prev_page = ui_page;
513 tk 1679
    SEQ_UI_PageSet(SEQ_UI_PAGE_TRGSEL);
1680
  } else {
524 tk 1681
    if( ui_page == SEQ_UI_PAGE_TRGSEL )
600 tk 1682
      SEQ_UI_PageSet(ui_trglayer_prev_page);
513 tk 1683
  }
1684
 
1685
  return 0; // no error
1686
}
1687
 
134 tk 1688
static s32 SEQ_UI_Button_TrgLayer(s32 depressed, u32 trg_layer)
1689
{
1117 tk 1690
  static u8 layer_c_pressed = 0;
784 tk 1691
 
134 tk 1692
  if( trg_layer >= 3 ) return -2; // max. 3 trglayer buttons
1693
 
326 tk 1694
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1695
  u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
1696
  u8 num_t_layers = SEQ_TRG_NumLayersGet(visible_track);
134 tk 1697
 
1205 tk 1698
  // drum mode in edit page: ensure that trigger layer is print again
1699
  if( ui_page == SEQ_UI_PAGE_EDIT ) {
1700
    u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
1701
    if( event_mode == SEQ_EVENT_MODE_Drum ) {
1702
      if( !depressed )
1703
    ui_hold_msg_ctr = 0;
1704
    }
1705
  }
1706
 
784 tk 1707
  // holding Layer C button allows to increment/decrement layer with A/B button
1708
  if( trg_layer == 2 )
1709
    layer_c_pressed = !depressed;
1710
 
1711
  if( layer_c_pressed && trg_layer == 0 ) {
326 tk 1712
    if( depressed ) return -1; // ignore when button depressed
784 tk 1713
    // increment layer
1714
    if( ++ui_selected_trg_layer >= num_t_layers )
1715
      ui_selected_trg_layer = 0;
1716
  } else if( layer_c_pressed && trg_layer == 1 ) {
326 tk 1717
    if( depressed ) return -1; // ignore when button depressed
784 tk 1718
    // decrement layer
1719
    if( ui_selected_trg_layer == 0 )
1720
      ui_selected_trg_layer = num_t_layers - 1;
326 tk 1721
    else
784 tk 1722
      --ui_selected_trg_layer;
326 tk 1723
  } else {
784 tk 1724
    if( event_mode != SEQ_EVENT_MODE_Drum && num_t_layers <= 3 ) {
1725
      // 3 layers: direct selection with LayerA/B/C button
326 tk 1726
      if( depressed ) return -1; // ignore when button depressed
784 tk 1727
      if( trg_layer >= num_t_layers ) {
1728
    char str1[21];
1729
    sprintf(str1, "Trigger Layer %c", 'A'+trg_layer);
1730
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, str1, "not available!");
1731
      } else {
1732
    seq_ui_button_state.TRG_LAYER_SEL = 0;
1733
    ui_selected_trg_layer = trg_layer;
1734
      }
1735
    } else if( event_mode != SEQ_EVENT_MODE_Drum && num_t_layers <= 4 ) {
1736
      // 4 layers: LayerC Button toggles between C and D
1737
      if( depressed ) return -1; // ignore when button depressed
328 tk 1738
      seq_ui_button_state.TRG_LAYER_SEL = 0;
784 tk 1739
      if( trg_layer == 2 )
1740
    ui_selected_trg_layer = (ui_selected_trg_layer == 2) ? 3 : 2;
1741
      else
1742
    ui_selected_trg_layer = trg_layer;
326 tk 1743
    } else {
784 tk 1744
      // >4 layers or drum mode: LayerA/B button selects directly, Layer C button enters trigger selection page
1745
      // also used for drum tracks
1746
      if( trg_layer <= 1 ) {
1747
    if( depressed ) return -1; // ignore when button depressed
1748
    seq_ui_button_state.TRG_LAYER_SEL = 0;
1749
    ui_selected_trg_layer = trg_layer;
1750
      } else {
1751
    return SEQ_UI_Button_TrgLayerSel(depressed);
1752
      }
326 tk 1753
    }
1754
  }
1755
 
134 tk 1756
  return 0; // no error
1757
}
1758
 
1759
 
1119 tk 1760
static s32 SEQ_UI_Button_Mixer(s32 depressed)
544 tk 1761
{
1762
  if( depressed ) return -1; // ignore when button depressed
134 tk 1763
 
1119 tk 1764
  SEQ_UI_PageSet(SEQ_UI_PAGE_MIXER);
544 tk 1765
 
1766
  return 0; // no error
1767
}
1768
 
1787 tk 1769
static s32 SEQ_UI_Button_Save(s32 depressed)
1770
{
1771
  if( depressed ) return -1; // ignore when button depressed
1772
 
1773
  u8 group = ui_selected_group;
1774
  seq_pattern_t pattern = seq_pattern[group];
1775
  s32 status;
1776
  if( (status=SEQ_PATTERN_Save(group, pattern)) < 0 ) {
1777
    SEQ_UI_SDCardErrMsg(2000, status);
1778
  } else {
1779
    char str1[21];
1780
    char str2[21];
1781
    sprintf(str1, "Track Group G%d", group + 1);
1782
    sprintf(str2, "stored into %d:%c%d", pattern.bank+1, (pattern.lower ? 'a' : 'A') + pattern.group, pattern.num + 1);
1783
    SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, str1, str2);
1784
  }
1785
 
1786
  return 0; // no error
1787
}
1788
 
1789
static s32 SEQ_UI_Button_SaveAll(s32 depressed)
1790
{
1791
  if( depressed ) return -1; // ignore when button depressed
1792
 
1793
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "Complete Session", "stored!");
1794
  seq_ui_saveall_req = 1;
1795
 
1796
  return 0; // no error
1797
}
1798
 
1119 tk 1799
static s32 SEQ_UI_Button_TrackMode(s32 depressed)
544 tk 1800
{
1801
  if( depressed ) return -1; // ignore when button depressed
1802
 
1119 tk 1803
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKMODE);
544 tk 1804
 
1805
  return 0; // no error
1806
}
1807
 
1119 tk 1808
static s32 SEQ_UI_Button_TrackGroove(s32 depressed)
544 tk 1809
{
1810
  if( depressed ) return -1; // ignore when button depressed
1811
 
1119 tk 1812
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKGRV);
1813
 
1814
  return 0; // no error
1815
}
1816
 
1817
static s32 SEQ_UI_Button_TrackLength(s32 depressed)
1818
{
1819
  if( depressed ) return -1; // ignore when button depressed
1820
 
1821
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKLEN);
1822
 
1823
  return 0; // no error
1824
}
1825
 
1826
static s32 SEQ_UI_Button_TrackDirection(s32 depressed)
1827
{
1828
  if( depressed ) return -1; // ignore when button depressed
1829
 
1830
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKDIR);
1831
 
1832
  return 0; // no error
1833
}
1834
 
1835
static s32 SEQ_UI_Button_TrackMorph(s32 depressed)
1836
{
1837
  if( depressed ) return -1; // ignore when button depressed
1838
 
1839
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKMORPH);
1840
 
1841
  return 0; // no error
1842
}
1843
 
1844
static s32 SEQ_UI_Button_TrackTranspose(s32 depressed)
1845
{
1846
  if( depressed ) return -1; // ignore when button depressed
1847
 
544 tk 1848
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKTRAN);
1849
 
1850
  return 0; // no error
1851
}
1852
 
1811 tk 1853
static s32 SEQ_UI_Button_MuteAllTracks(s32 depressed)
1854
{
1855
  if( depressed ) return -1; // ignore when button depressed
1856
  seq_core_trk_muted = 0xffff;
1814 tk 1857
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "All Tracks", "muted");
1811 tk 1858
  return 0; // no error
1859
}
544 tk 1860
 
1811 tk 1861
static s32 SEQ_UI_Button_MuteTrackLayers(s32 depressed)
1862
{
1863
  if( depressed ) return -1; // ignore when button depressed
1864
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1865
  seq_core_trk[visible_track].layer_muted = 0xffff;
1814 tk 1866
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "All Layers", "of current Track muted");
1811 tk 1867
  return 0; // no error
1868
}
1869
 
1870
static s32 SEQ_UI_Button_MuteAllTracksAndLayers(s32 depressed)
1871
{
1872
  if( depressed ) return -1; // ignore when button depressed
1873
  int track;
1874
  for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track)
1875
    seq_core_trk[track].layer_muted = 0xffff;
1876
  seq_core_trk_muted = 0xffff;
1814 tk 1877
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "All Layers", "and Tracks muted");
1811 tk 1878
  return 0; // no error
1879
}
1880
 
1881
static s32 SEQ_UI_Button_UnMuteAllTracks(s32 depressed)
1882
{
1883
  if( depressed ) return -1; // ignore when button depressed
1814 tk 1884
  seq_core_trk_muted = 0x0000;
1885
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "All Tracks", "unmuted");
1811 tk 1886
  return 0; // no error
1887
}
1888
 
1889
static s32 SEQ_UI_Button_UnMuteTrackLayers(s32 depressed)
1890
{
1891
  if( depressed ) return -1; // ignore when button depressed
1892
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1814 tk 1893
  seq_core_trk[visible_track].layer_muted = 0x0000;
1894
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "All Layers", "of current Track unmuted");
1811 tk 1895
  return 0; // no error
1896
}
1897
 
1898
static s32 SEQ_UI_Button_UnMuteAllTracksAndLayers(s32 depressed)
1899
{
1900
  if( depressed ) return -1; // ignore when button depressed
1901
  int track;
1902
  for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track)
1814 tk 1903
    seq_core_trk[track].layer_muted = 0x0000;
1904
  seq_core_trk_muted = 0x0000;
1905
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "All Layers", "and Tracks unmuted");
1811 tk 1906
  return 0; // no error
1907
}
1908
 
742 tk 1909
// only used by keyboard remote function
1910
static s32 SEQ_UI_Button_ToggleGate(s32 depressed)
1911
{
1912
  if( depressed ) return -1; // ignore when button depressed
544 tk 1913
 
742 tk 1914
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1915
  u8 gate = SEQ_TRG_GateGet(visible_track, ui_selected_step, ui_selected_instrument) ? 0 : 1;
1916
  SEQ_TRG_GateSet(visible_track, ui_selected_step, ui_selected_instrument, gate);
544 tk 1917
 
742 tk 1918
  return 0; // no error
1919
}
1920
 
1349 tk 1921
static s32 SEQ_UI_Button_FootSwitch(s32 depressed)
1922
{
1923
  // static variables (only used here, therefore local)
1924
  static u32 fs_time_control = 0; // timestamp of last operation
742 tk 1925
 
1349 tk 1926
  // this is used as a constant value
2079 midilab 1927
  u32 fs_time_delay = 500; // mS - should this be configurable?
742 tk 1928
 
2079 midilab 1929
  // Clear track check
1930
  if( depressed ) {
1931
        // if footswitch time passed between pressed and depressed is less than fs_time_delay miliseconds, clear track.
1932
    if( ( MIOS32_TIMESTAMP_GetDelay(fs_time_control) < fs_time_delay ) && ( fs_time_control != 0 ) )
1349 tk 1933
    {
2079 midilab 1934
            SEQ_UI_Button_Clear_Track(0);
1349 tk 1935
    }
1936
  } else {
2079 midilab 1937
        // store pressed timestamp
1938
        fs_time_control = MIOS32_TIMESTAMP_Get();
1349 tk 1939
  }
1940
 
2079 midilab 1941
    // PUNCH_IN, PUNCH_OUT
1349 tk 1942
  if( depressed ) {
1943
    // disable recording
2154 tk 1944
    SEQ_RECORD_Enable(0);
1349 tk 1945
  } else {
1946
    // enable recording
2154 tk 1947
    SEQ_RECORD_Enable(1);
1349 tk 1948
    seq_record_state.ARMED_TRACKS = ui_selected_tracks; // not used yet, just preparation for future changes
1949
  }
1950
 
1951
  return 0; // no error
1952
}
1953
 
1954
 
134 tk 1955
/////////////////////////////////////////////////////////////////////////////
1956
// Button handler
1957
/////////////////////////////////////////////////////////////////////////////
1958
s32 SEQ_UI_Button_Handler(u32 pin, u32 pin_value)
1959
{
492 tk 1960
  int i;
1961
 
625 tk 1962
  // send MIDI event in remote mode and exit
1316 tk 1963
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT )
625 tk 1964
    return SEQ_MIDI_SYSEX_REMOTE_Client_SendButton(pin, pin_value);
1965
 
1044 tk 1966
  // ignore as long as hardware config hasn't been read
496 tk 1967
  if( !SEQ_FILE_HW_ConfigLocked() )
1968
    return -1;
1969
 
740 tk 1970
  // ignore during a backup or format is created
1971
  if( seq_ui_backup_req || seq_ui_format_req )
634 tk 1972
    return -1;
1973
 
328 tk 1974
  // ensure that selections are matching with track constraints
1975
  SEQ_UI_CheckSelections();
1976
 
492 tk 1977
  // request display update
1978
  seq_ui_display_update_req = 1;
134 tk 1979
 
596 tk 1980
  // stop current message if (new) button has been pressed
1981
  if( pin_value == 0 )
1982
    SEQ_UI_MsgStop();
134 tk 1983
 
596 tk 1984
 
492 tk 1985
  // MEMO: we could also use a jump table with references to the functions
1986
  // here, but this "spagetthi code" simplifies the configuration and
1987
  // the resulting ASM doesn't look that bad!
168 tk 1988
 
492 tk 1989
  for(i=0; i<SEQ_HWCFG_NUM_GP; ++i)
1990
    if( pin == seq_hwcfg_button.gp[i] )
1991
      return SEQ_UI_Button_GP(pin_value, i);
134 tk 1992
 
492 tk 1993
  for(i=0; i<SEQ_HWCFG_NUM_TRACK; ++i)
1994
    if( pin == seq_hwcfg_button.track[i] )
1995
      return SEQ_UI_Button_Track(pin_value, i);
1146 tk 1996
 
1997
  for(i=0; i<SEQ_HWCFG_NUM_DIRECT_TRACK; ++i)
1998
    if( pin == seq_hwcfg_button.direct_track[i] )
1999
      return SEQ_UI_Button_DirectTrack(pin_value, i);
2000
 
1205 tk 2001
  for(i=0; i<SEQ_HWCFG_NUM_DIRECT_BOOKMARK; ++i)
2002
    if( pin == seq_hwcfg_button.direct_bookmark[i] )
2003
      return SEQ_UI_Button_DirectBookmark(pin_value, i);
2004
 
513 tk 2005
  if( pin == seq_hwcfg_button.track_sel )
2006
    return SEQ_UI_Button_TrackSel(pin_value);
134 tk 2007
 
492 tk 2008
  for(i=0; i<SEQ_HWCFG_NUM_GROUP; ++i)
2009
    if( pin == seq_hwcfg_button.group[i] )
2010
      return SEQ_UI_Button_Group(pin_value, i);
134 tk 2011
 
492 tk 2012
  for(i=0; i<SEQ_HWCFG_NUM_PAR_LAYER; ++i)
2013
    if( pin == seq_hwcfg_button.par_layer[i] )
2014
      return SEQ_UI_Button_ParLayer(pin_value, i);
513 tk 2015
  if( pin == seq_hwcfg_button.par_layer_sel )
2016
    return SEQ_UI_Button_ParLayerSel(pin_value);
134 tk 2017
 
492 tk 2018
  for(i=0; i<SEQ_HWCFG_NUM_TRG_LAYER; ++i)
2019
    if( pin == seq_hwcfg_button.trg_layer[i] )
2020
      return SEQ_UI_Button_TrgLayer(pin_value, i);
513 tk 2021
  if( pin == seq_hwcfg_button.trg_layer_sel )
2022
    return SEQ_UI_Button_TrgLayerSel(pin_value);
134 tk 2023
 
492 tk 2024
  if( pin == seq_hwcfg_button.left )
2025
    return SEQ_UI_Button_Left(pin_value);
2026
  if( pin == seq_hwcfg_button.right )
2027
    return SEQ_UI_Button_Right(pin_value);
2028
  if( pin == seq_hwcfg_button.down )
2029
    return SEQ_UI_Button_Down(pin_value);
2030
  if( pin == seq_hwcfg_button.up )
2031
    return SEQ_UI_Button_Up(pin_value);
134 tk 2032
 
492 tk 2033
  if( pin == seq_hwcfg_button.scrub )
2034
    return SEQ_UI_Button_Scrub(pin_value);
2035
  if( pin == seq_hwcfg_button.metronome )
2036
    return SEQ_UI_Button_Metronome(pin_value);
134 tk 2037
 
630 tk 2038
  if( pin == seq_hwcfg_button.record )
2039
    return SEQ_UI_Button_Record(pin_value);
1219 tk 2040
  if( pin == seq_hwcfg_button.live )
2041
    return SEQ_UI_Button_Live(pin_value);
630 tk 2042
 
492 tk 2043
  if( pin == seq_hwcfg_button.stop )
2044
    return SEQ_UI_Button_Stop(pin_value);
2045
  if( pin == seq_hwcfg_button.pause )
2046
    return SEQ_UI_Button_Pause(pin_value);
2047
  if( pin == seq_hwcfg_button.play )
2048
    return SEQ_UI_Button_Play(pin_value);
2049
  if( pin == seq_hwcfg_button.rew )
2050
    return SEQ_UI_Button_Rew(pin_value);
2051
  if( pin == seq_hwcfg_button.fwd )
2052
    return SEQ_UI_Button_Fwd(pin_value);
596 tk 2053
  if( pin == seq_hwcfg_button.loop )
2054
    return SEQ_UI_Button_Loop(pin_value);
973 tk 2055
  if( pin == seq_hwcfg_button.follow )
2056
    return SEQ_UI_Button_Follow(pin_value);
134 tk 2057
 
492 tk 2058
  if( pin == seq_hwcfg_button.utility )
2059
    return SEQ_UI_Button_Utility(pin_value);
2060
  if( pin == seq_hwcfg_button.copy )
2061
    return SEQ_UI_Button_Copy(pin_value);
2062
  if( pin == seq_hwcfg_button.paste )
2063
    return SEQ_UI_Button_Paste(pin_value);
2064
  if( pin == seq_hwcfg_button.clear )
2065
    return SEQ_UI_Button_Clear(pin_value);
1014 tk 2066
  if( pin == seq_hwcfg_button.undo )
2067
    return SEQ_UI_Button_Undo(pin_value);
134 tk 2068
 
492 tk 2069
  if( pin == seq_hwcfg_button.menu )
2070
    return SEQ_UI_Button_Menu(pin_value);
1203 tk 2071
  if( pin == seq_hwcfg_button.bookmark )
2072
    return SEQ_UI_Button_Bookmark(pin_value);
492 tk 2073
  if( pin == seq_hwcfg_button.select )
2074
    return SEQ_UI_Button_Select(pin_value);
2075
  if( pin == seq_hwcfg_button.exit )
2076
    return SEQ_UI_Button_Exit(pin_value);
134 tk 2077
 
513 tk 2078
  if( pin == seq_hwcfg_button.tap_tempo )
2079
    return SEQ_UI_Button_TapTempo(pin_value);
2080
  if( pin == seq_hwcfg_button.tempo_preset )
2081
    return SEQ_UI_Button_TempoPreset(pin_value);
524 tk 2082
  if( pin == seq_hwcfg_button.ext_restart )
2083
    return SEQ_UI_Button_ExtRestart(pin_value);
134 tk 2084
 
492 tk 2085
  if( pin == seq_hwcfg_button.edit )
2086
    return SEQ_UI_Button_Edit(pin_value);
2087
  if( pin == seq_hwcfg_button.mute )
2088
    return SEQ_UI_Button_Mute(pin_value);
2089
  if( pin == seq_hwcfg_button.pattern )
2090
    return SEQ_UI_Button_Pattern(pin_value);
2091
  if( pin == seq_hwcfg_button.song )
2092
    return SEQ_UI_Button_Song(pin_value);
134 tk 2093
 
492 tk 2094
  if( pin == seq_hwcfg_button.solo )
2095
    return SEQ_UI_Button_Solo(pin_value);
2096
  if( pin == seq_hwcfg_button.fast )
2097
    return SEQ_UI_Button_Fast(pin_value);
1121 tk 2098
  if( pin == seq_hwcfg_button.fast2 )
2099
    return SEQ_UI_Button_Fast2(pin_value);
492 tk 2100
  if( pin == seq_hwcfg_button.all )
2101
    return SEQ_UI_Button_All(pin_value);
134 tk 2102
 
492 tk 2103
  if( pin == seq_hwcfg_button.step_view )
2104
    return SEQ_UI_Button_StepView(pin_value);
134 tk 2105
 
544 tk 2106
  if( pin == seq_hwcfg_button.mixer )
2107
    return SEQ_UI_Button_Mixer(pin_value);
2108
 
1787 tk 2109
  if( pin == seq_hwcfg_button.save )
2110
    return SEQ_UI_Button_Save(pin_value);
2111
  if( pin == seq_hwcfg_button.save_all )
2112
    return SEQ_UI_Button_SaveAll(pin_value);
2113
 
1119 tk 2114
  if( pin == seq_hwcfg_button.track_mode )
2115
    return SEQ_UI_Button_TrackMode(pin_value);
2116
  if( pin == seq_hwcfg_button.track_groove )
2117
    return SEQ_UI_Button_TrackGroove(pin_value);
2118
  if( pin == seq_hwcfg_button.track_length )
2119
    return SEQ_UI_Button_TrackLength(pin_value);
2120
  if( pin == seq_hwcfg_button.track_direction )
2121
    return SEQ_UI_Button_TrackDirection(pin_value);
2122
  if( pin == seq_hwcfg_button.track_morph )
2123
    return SEQ_UI_Button_TrackMorph(pin_value);
2124
  if( pin == seq_hwcfg_button.track_transpose )
2125
    return SEQ_UI_Button_TrackTranspose(pin_value);
1349 tk 2126
  if( pin == seq_hwcfg_button.footswitch )
2127
    return SEQ_UI_Button_FootSwitch(pin_value);
1454 midilab 2128
  if( pin == seq_hwcfg_button.pattern_remix )
2129
    return SEQ_UI_Button_Pattern_Remix(pin_value);
1811 tk 2130
 
2131
  if( pin == seq_hwcfg_button.mute_all_tracks )
2132
    return SEQ_UI_Button_MuteAllTracks(pin_value);
2133
  if( pin == seq_hwcfg_button.mute_track_layers )
2134
    return SEQ_UI_Button_MuteTrackLayers(pin_value);
2135
  if( pin == seq_hwcfg_button.mute_all_tracks_and_layers )
2136
    return SEQ_UI_Button_MuteAllTracksAndLayers(pin_value);
2137
  if( pin == seq_hwcfg_button.unmute_all_tracks )
2138
    return SEQ_UI_Button_UnMuteAllTracks(pin_value);
2139
  if( pin == seq_hwcfg_button.unmute_track_layers )
2140
    return SEQ_UI_Button_UnMuteTrackLayers(pin_value);
2141
  if( pin == seq_hwcfg_button.unmute_all_tracks_and_layers )
2142
    return SEQ_UI_Button_UnMuteAllTracksAndLayers(pin_value);
2143
 
625 tk 2144
  // always print debugging message
2145
#if 1
1081 tk 2146
  MUTEX_MIDIOUT_TAKE;
2147
  DEBUG_MSG("[SEQ_UI_Button_Handler] Button SR:%d, Pin:%d not mapped, it has been %s.\n",
2148
        (pin >> 3) + 1,
2149
        pin & 7,
2150
        pin_value ? "depressed" : "pressed");
2151
  MUTEX_MIDIOUT_GIVE;
625 tk 2152
#endif
2153
 
492 tk 2154
  return -1; // button not mapped
134 tk 2155
}
2156
 
2157
 
2158
/////////////////////////////////////////////////////////////////////////////
524 tk 2159
// BLM Button handler
2160
/////////////////////////////////////////////////////////////////////////////
2161
s32 SEQ_UI_BLM_Button_Handler(u32 row, u32 pin, u32 pin_value)
2162
{
625 tk 2163
  // send MIDI event in remote mode and exit
1316 tk 2164
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT )
625 tk 2165
    return SEQ_MIDI_SYSEX_REMOTE_Client_Send_BLM_Button(row, pin, pin_value);
2166
 
1044 tk 2167
  // ignore as long as hardware config hasn't been read
524 tk 2168
  if( !SEQ_FILE_HW_ConfigLocked() )
2169
    return -1;
2170
 
740 tk 2171
  // ignore during a backup or format is created
2172
  if( seq_ui_backup_req || seq_ui_format_req )
634 tk 2173
    return -1;
2174
 
524 tk 2175
  if( row >= SEQ_CORE_NUM_TRACKS_PER_GROUP )
2176
    return -1; // more than 4 tracks not supported (yet) - could be done in this function w/o much effort
2177
 
2178
  if( pin >= 16 )
2179
    return -1; // more than 16 step buttons not supported (yet) - could be done by selecting the step view
2180
 
2181
  // select track depending on row
2182
  ui_selected_tracks = 1 << (row + 4*ui_selected_group);
2183
 
2184
  // ensure that selections are matching with track constraints
2185
  SEQ_UI_CheckSelections();
2186
 
2187
  // request display update
2188
  seq_ui_display_update_req = 1;
2189
 
2190
  // emulate general purpose button
758 tk 2191
  if( seq_hwcfg_blm.buttons_no_ui ) {
763 tk 2192
    s32 status = SEQ_UI_EDIT_Button_Handler(pin, pin_value);
758 tk 2193
    ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0;
2194
    return status;
763 tk 2195
  }
2196
 
2197
  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 2198
}
2199
 
2200
 
2201
/////////////////////////////////////////////////////////////////////////////
134 tk 2202
// Encoder handler
2203
/////////////////////////////////////////////////////////////////////////////
2204
s32 SEQ_UI_Encoder_Handler(u32 encoder, s32 incrementer)
2205
{
625 tk 2206
  // send MIDI event in remote mode and exit
1316 tk 2207
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT )
625 tk 2208
    return SEQ_MIDI_SYSEX_REMOTE_Client_SendEncoder(encoder, incrementer);
2209
 
1044 tk 2210
  // ignore as long as hardware config hasn't been read
496 tk 2211
  if( !SEQ_FILE_HW_ConfigLocked() )
2212
    return -1;
2213
 
740 tk 2214
  // ignore during a backup or format is created
2215
  if( seq_ui_backup_req || seq_ui_format_req )
634 tk 2216
    return -1;
2217
 
1341 tk 2218
  if( encoder >= SEQ_HWCFG_NUM_ENCODERS )
134 tk 2219
    return -1; // encoder doesn't exist
2220
 
328 tk 2221
  // ensure that selections are matching with track constraints
2222
  SEQ_UI_CheckSelections();
2223
 
596 tk 2224
  // stop current message
2225
  SEQ_UI_MsgStop();
2226
 
134 tk 2227
  // limit incrementer
2228
  if( incrementer > 3 )
2229
    incrementer = 3;
2230
  else if( incrementer < -3 )
2231
    incrementer = -3;
2232
 
1341 tk 2233
  // encoder 17 increments BPM
2234
  if( encoder == 17 ) {
2235
    u16 value = (u16)(seq_core_bpm_preset_tempo[seq_core_bpm_preset_num]*10);
2236
    if( SEQ_UI_Var16_Inc(&value, 25, 3000, incrementer) ) { // at 384ppqn, the minimum BPM rate is ca. 2.5
2237
      // set new BPM
2238
      seq_core_bpm_preset_tempo[seq_core_bpm_preset_num] = (float)value/10.0;
2239
      SEQ_CORE_BPM_Update(seq_core_bpm_preset_tempo[seq_core_bpm_preset_num], seq_core_bpm_preset_ramp[seq_core_bpm_preset_num]);
2240
      //store_file_required = 1;
2241
      seq_ui_display_update_req = 1;      
2242
    }
2243
    return 0;
2244
  }
2245
 
607 tk 2246
  if( seq_ui_button_state.SCRUB && encoder == 0 ) {
2247
    // if sequencer isn't already running, continue it (don't restart)
2248
    if( !SEQ_BPM_IsRunning() )
2249
      SEQ_BPM_Cont();
2250
    ui_seq_pause = 0; // clear pause mode
1278 tk 2251
 
607 tk 2252
    // Scrub sequence back or forth
2253
    portENTER_CRITICAL(); // should be atomic
2254
    SEQ_CORE_Scrub(incrementer);
2255
    portEXIT_CRITICAL();
2256
  } else if( !seq_ui_button_state.MENU_PRESSED && ui_encoder_callback != NULL ) {
173 tk 2257
    ui_encoder_callback((encoder == 0) ? SEQ_UI_ENCODER_Datawheel : (encoder-1), incrementer);
740 tk 2258
    ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0; // ensure that value is visible when it has been changed
134 tk 2259
  }
2260
 
2261
  // request display update
159 tk 2262
  seq_ui_display_update_req = 1;
134 tk 2263
 
2264
  return 0; // no error
2265
}
2266
 
2267
 
353 tk 2268
 
134 tk 2269
/////////////////////////////////////////////////////////////////////////////
626 tk 2270
// Receives a MIDI package from APP_NotifyReceivedEvent (-> app.c)
2271
/////////////////////////////////////////////////////////////////////////////
2272
s32 SEQ_UI_REMOTE_MIDI_Receive(mios32_midi_port_t port, mios32_midi_package_t midi_package)
2273
{
2274
#if 1
2275
  // check for active remote mode
1316 tk 2276
  if( seq_midi_sysex_remote_active_mode != SEQ_MIDI_SYSEX_REMOTE_MODE_SERVER )
626 tk 2277
    return 0; // no error
2278
#endif
2279
 
1316 tk 2280
  if( (seq_midi_sysex_remote_port == DEFAULT && seq_midi_sysex_remote_active_port != port) ||
2281
      (seq_midi_sysex_remote_port != DEFAULT && port != seq_midi_sysex_remote_port) )
626 tk 2282
    return 0; // wrong port
2283
 
2284
  // for easier parsing: convert Note Off -> Note On with velocity 0
2285
  if( midi_package.event == NoteOff ) {
2286
    midi_package.event = NoteOn;
2287
    midi_package.velocity = 0;
2288
  }
2289
 
2290
  switch( midi_package.event ) {
2291
    case NoteOn: {
2292
      switch( midi_package.chn ) {
2293
        case Chn1:
2294
      SEQ_UI_Button_Handler(midi_package.note + 0x00, midi_package.velocity ? 0 : 1);
2295
      break;
2296
        case Chn2:
2297
      SEQ_UI_Button_Handler(midi_package.note + 0x80, midi_package.velocity ? 0 : 1);
2298
      break;
2299
        case Chn3:
2300
      SEQ_UI_BLM_Button_Handler(midi_package.note >> 5, midi_package.note & 0x1f, midi_package.velocity ? 0 : 1);
2301
      break;
2302
      }
2303
    } break;
2304
 
2305
    case CC: {
2306
      if( midi_package.cc_number >= 15 && midi_package.cc_number <= 31 )
2307
    SEQ_UI_Encoder_Handler(midi_package.cc_number-15, (int)midi_package.value - 0x40);
2308
    } break;
2309
  }
2310
 
632 tk 2311
  return 1; // MIDI event has been taken for remote function -> don't forward to router/MIDI event parser
626 tk 2312
}
2313
 
2314
 
2315
/////////////////////////////////////////////////////////////////////////////
741 tk 2316
// MIDI Remote Keyboard Function (called from SEQ_MIDI_IN)
2317
/////////////////////////////////////////////////////////////////////////////
742 tk 2318
s32 SEQ_UI_REMOTE_MIDI_Keyboard(u8 key, u8 depressed)
741 tk 2319
{
742 tk 2320
#if 0
1316 tk 2321
  MIOS32_MIDI_SendDebugMessage("SEQ_MIDI_SYSEX_REMOTE_MIDI_Keyboard(%d, %d)\n", key, depressed);
741 tk 2322
#endif
742 tk 2323
 
2324
  switch( key ) {
2325
    case 0x24: // C-2
2326
      return SEQ_UI_Button_GP(depressed, 0);
2327
    case 0x25: // C#2
2328
      return SEQ_UI_Button_Track(depressed, 0);
2329
    case 0x26: // D-2
2330
      return SEQ_UI_Button_GP(depressed, 1);
2331
    case 0x27: // D#2
2332
      return SEQ_UI_Button_Track(depressed, 1);
2333
    case 0x28: // E-2
2334
      return SEQ_UI_Button_GP(depressed, 2);
2335
    case 0x29: // F-2
2336
      return SEQ_UI_Button_GP(depressed, 3);
2337
    case 0x2a: // F#2
2338
      return SEQ_UI_Button_Track(depressed, 2);
2339
    case 0x2b: // G-2
2340
      return SEQ_UI_Button_GP(depressed, 4);
2341
    case 0x2c: // G#2
2342
      return SEQ_UI_Button_Track(depressed, 3);
2343
    case 0x2d: // A-2
2344
      return SEQ_UI_Button_GP(depressed, 5);
2345
    case 0x2e: // A#2
2346
      return SEQ_UI_Button_ParLayer(depressed, 0);
2347
    case 0x2f: // B-2
2348
      return SEQ_UI_Button_GP(depressed, 6);
2349
 
2350
    case 0x30: // C-3
2351
      return SEQ_UI_Button_GP(depressed, 7);
2352
    case 0x31: // C#3
2353
      return SEQ_UI_Button_ParLayer(depressed, 1);
2354
    case 0x32: // D-3
2355
      return SEQ_UI_Button_GP(depressed, 8);
2356
    case 0x33: // D#3
2357
      return SEQ_UI_Button_ParLayer(depressed, 2);
2358
    case 0x34: // E-3
2359
      return SEQ_UI_Button_GP(depressed, 9);
2360
    case 0x35: // F-3
2361
      return SEQ_UI_Button_GP(depressed, 10);
2362
    case 0x36: // F#3
2363
      return SEQ_UI_Button_TrgLayer(depressed, 0);
2364
    case 0x37: // G-3
2365
      return SEQ_UI_Button_GP(depressed, 11);
2366
    case 0x38: // G#3
2367
      return SEQ_UI_Button_TrgLayer(depressed, 1);
2368
    case 0x39: // A-3
2369
      return SEQ_UI_Button_GP(depressed, 12);
2370
    case 0x3a: // A#3
2371
      return SEQ_UI_Button_TrgLayer(depressed, 2);
2372
    case 0x3b: // B-3
2373
      return SEQ_UI_Button_GP(depressed, 13);
2374
 
2375
    case 0x3c: // C-4
2376
      return SEQ_UI_Button_GP(depressed, 14);
2377
    case 0x3d: // C#4
2378
      return SEQ_UI_Button_Group(depressed, 0);
2379
    case 0x3e: // D-4
2380
      return SEQ_UI_Button_GP(depressed, 15);
2381
    case 0x3f: // D#4
2382
      return SEQ_UI_Button_Group(depressed, 1);
2383
    case 0x40: // E-4
2384
      return 0; // ignore
2385
    case 0x41: // F-4
2386
      return SEQ_UI_Button_StepView(depressed);
2387
    case 0x42: // F#4
2162 tk 2388
      return SEQ_UI_Button_Group(depressed, 2);
742 tk 2389
    case 0x43: // G-4
2390
      return 0; // ignore
2391
    case 0x44: // G#4
2162 tk 2392
      return SEQ_UI_Button_Group(depressed, 3);
742 tk 2393
    case 0x45: // A-4
2394
      return SEQ_UI_Button_Left(depressed);
2395
    case 0x46: // A#4
2396
      return SEQ_UI_Button_ToggleGate(depressed);
2397
    case 0x47: // B-4
2398
      return SEQ_UI_Button_Right(depressed);
2399
 
2400
    case 0x48: // C-5
2401
      return SEQ_UI_Button_Edit(depressed);
2402
    case 0x49: // C#5
2403
      return SEQ_UI_Button_Solo(depressed);
2404
    case 0x4a: // D-5
2405
      return SEQ_UI_Button_Mute(depressed);
2406
    case 0x4b: // D#5
2407
      return SEQ_UI_Button_All(depressed);
2408
    case 0x4c: // E-5
2409
      return SEQ_UI_Button_Pattern(depressed);
2410
    case 0x4d: // F-5
2411
      return SEQ_UI_Button_Song(depressed);
2412
    case 0x4e: // F#5
2413
      return SEQ_UI_Button_Fast(depressed);
2414
    case 0x4f: // G-5
2415
      return SEQ_UI_Button_Metronome(depressed);
2416
    case 0x50: // G#5
2417
      return SEQ_UI_Button_ExtRestart(depressed);
2418
    case 0x51: // A-5
2419
      return SEQ_UI_Button_ParLayerSel(depressed);
2420
    case 0x52: // A#5
2421
      return SEQ_UI_Button_TrackSel(depressed);
2422
    case 0x53: // B-5
2423
      return SEQ_UI_Button_Stop(depressed);
2424
 
2425
    case 0x54: // C-6
2426
      return SEQ_UI_Button_Play(depressed);
2427
    case 0x55: // C#6
2428
      return SEQ_UI_Button_Pause(depressed);
2429
    case 0x56: // D-6
2430
      return SEQ_UI_Button_Rew(depressed);
2431
    case 0x57: // D#6
2432
      return SEQ_UI_Button_Fwd(depressed);
2433
    case 0x58: // E-6
2434
      return SEQ_UI_Button_Utility(depressed);
2435
    case 0x59: // F-6
2436
      return SEQ_UI_Button_TempoPreset(depressed);
2437
    case 0x5a: // F#6
2438
      return 0; // ignore
2439
    case 0x5b: // G-6
2440
      return SEQ_UI_Button_Menu(depressed);
2441
    case 0x5c: // G#6
2442
      return SEQ_UI_Button_Select(depressed);
2443
    case 0x5d: // A-6
2444
      return SEQ_UI_Button_Exit(depressed);
2445
    case 0x5e: // A#6
2446
      return SEQ_UI_Button_Down(depressed);
2447
    case 0x5f: // B-6
2448
      return SEQ_UI_Button_Up(depressed);
2449
  }
2450
 
741 tk 2451
  return 0; // no error
2452
}
2453
 
2454
 
2455
/////////////////////////////////////////////////////////////////////////////
134 tk 2456
// Update LCD messages
2457
// Usually called from background task
2458
/////////////////////////////////////////////////////////////////////////////
2459
s32 SEQ_UI_LCD_Handler(void)
2460
{
728 tk 2461
  static u8 boot_animation_wait_ctr = 0;
2462
  static u8 boot_animation_lcd_pos = 0;
2130 tk 2463
  static u8 screen_saver_was_active = 0;
728 tk 2464
 
625 tk 2465
  // special handling in remote client mode
1316 tk 2466
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT )
625 tk 2467
    return SEQ_UI_LCD_Update();
2468
 
159 tk 2469
  if( seq_ui_display_init_req ) {
2470
    seq_ui_display_init_req = 0; // clear request
134 tk 2471
 
278 tk 2472
    // clear force update of LCD
2473
    SEQ_LCD_Clear();
2474
    SEQ_LCD_Update(1);
134 tk 2475
 
168 tk 2476
    // select first menu item
2477
    ui_selected_item = 0;
2478
 
167 tk 2479
    // call init function of current page
2039 tk 2480
    SEQ_UI_PAGES_CallInit(ui_page);
134 tk 2481
 
2482
    // request display update
159 tk 2483
    seq_ui_display_update_req = 1;
134 tk 2484
  }
2485
 
2130 tk 2486
  // print boot screen as long as hardware config hasn't been read or screensaver is active
496 tk 2487
  if( !SEQ_FILE_HW_ConfigLocked() ) {
728 tk 2488
    if( boot_animation_lcd_pos < (40-3) ) {
2489
      if( ++boot_animation_wait_ctr >= 75 ) {
2490
    boot_animation_wait_ctr = 0;
637 tk 2491
 
728 tk 2492
    if( boot_animation_lcd_pos == 0 ) {
2493
      SEQ_LCD_Clear();
2494
      SEQ_LCD_CursorSet(0, 0);
2495
      SEQ_LCD_PrintString(MIOS32_LCD_BOOT_MSG_LINE1 " " MIOS32_LCD_BOOT_MSG_LINE2);
2496
      SEQ_LCD_CursorSet(0, 1);
2497
      SEQ_LCD_PrintString("Searching for SD Card...");
2498
    }
2499
 
2500
    // logo is print on second LCD
2130 tk 2501
    SEQ_LCD_LOGO_Print(40, boot_animation_lcd_pos++);
728 tk 2502
      }
2503
    }
740 tk 2504
  } else if( seq_ui_backup_req || seq_ui_format_req ) {
634 tk 2505
    SEQ_LCD_Clear();
2506
    SEQ_LCD_CursorSet(0, 0);
740 tk 2507
    //                     <-------------------------------------->
2508
    //                     0123456789012345678901234567890123456789
2509
    if( seq_ui_backup_req )
959 tk 2510
      SEQ_LCD_PrintString("Copy Files - be patient!!!");
740 tk 2511
    else if( seq_ui_format_req )
959 tk 2512
      SEQ_LCD_PrintString("Creating Files - be patient!!!");
740 tk 2513
    else
2514
      SEQ_LCD_PrintString("Don't know what I'm doing! :-/");
637 tk 2515
 
2516
    if( seq_file_backup_notification != NULL ) {
2517
      int i;
2518
 
2519
      SEQ_LCD_CursorSet(0, 1);
959 tk 2520
      SEQ_LCD_PrintFormattedString("Creating %s", seq_file_backup_notification);
637 tk 2521
 
2522
      SEQ_LCD_CursorSet(40+3, 0);
2523
      SEQ_LCD_PrintString("Total: [");
2524
      for(i=0; i<20; ++i)
2525
    SEQ_LCD_PrintChar((i>(seq_file_backup_percentage/5)) ? ' ' : '#');
2526
      SEQ_LCD_PrintFormattedString("] %3d%%", seq_file_backup_percentage);
2527
 
2528
      SEQ_LCD_CursorSet(40+3, 1);
2529
      SEQ_LCD_PrintString("File:  [");
2530
      for(i=0; i<20; ++i)
1261 tk 2531
    SEQ_LCD_PrintChar((i>(file_copy_percentage/5)) ? ' ' : '#');
2532
      SEQ_LCD_PrintFormattedString("] %3d%%", file_copy_percentage);
637 tk 2533
    }
2534
 
2130 tk 2535
  } else if( SEQ_LCD_LOGO_ScreenSaver_IsActive() ) {
2536
    screen_saver_was_active = 1;
2537
    SEQ_LCD_LOGO_ScreenSaver_Print();
496 tk 2538
  } else if( seq_ui_button_state.MENU_PRESSED && !seq_ui_button_state.MENU_FIRST_PAGE_SELECTED ) {
2539
    SEQ_LCD_CursorSet(0, 0);
2540
    //                   <-------------------------------------->
2541
    //                   0123456789012345678901234567890123456789
306 tk 2542
    SEQ_LCD_PrintString("Menu Shortcuts:");
2543
    SEQ_LCD_PrintSpaces(25 + 40);
2544
    SEQ_LCD_CursorSet(0, 1);
2039 tk 2545
 
2546
    int i;
2547
    for(i=0; i<16; ++i) {
2548
      SEQ_LCD_PrintString(SEQ_UI_PAGES_MenuShortcutNameGet(i));
2549
    }
306 tk 2550
  } else {
2130 tk 2551
    // re-init special chars
2552
    if( screen_saver_was_active ) {
2553
      screen_saver_was_active = 0;
2554
      SEQ_LCD_ReInitSpecialChars();
2555
    }
2556
 
306 tk 2557
    // perform high priority LCD update request
2558
    if( ui_lcd_callback != NULL )
2559
      ui_lcd_callback(1); // high_prio
167 tk 2560
 
306 tk 2561
    // perform low priority LCD update request if requested
2562
    if( seq_ui_display_update_req ) {
2563
      seq_ui_display_update_req = 0; // clear request
328 tk 2564
 
2565
      // ensure that selections are matching with track constraints
2566
      SEQ_UI_CheckSelections();
2567
 
306 tk 2568
      if( ui_lcd_callback != NULL )
2569
    ui_lcd_callback(0); // no high_prio
2570
    }
134 tk 2571
  }
2572
 
353 tk 2573
  // transfer all changed characters to LCD
2574
  SEQ_UI_LCD_Update();
2575
 
2576
  return 0; // no error
2577
}
2578
 
2579
 
2580
/////////////////////////////////////////////////////////////////////////////
2581
// Called from SEQ_UI_LCD_Handler(), but optionally also from other tasks
2582
// to update the LCD screen immediately
2583
/////////////////////////////////////////////////////////////////////////////
1117 tk 2584
// for newer GCC versions it's important to declare constant arrays outside a function
2585
//                                             00112233
2586
static const char animation_l_arrows[2*4+1] = "   >>>> ";
2587
//                                             00112233
2588
static const char animation_r_arrows[2*4+1] = "  < << <";
2589
//                                               00112233
2590
static const char animation_l_brackets[2*4+1] = "   )))) ";
2591
//                                               00112233
2592
static const char animation_r_brackets[2*4+1] = "  ( (( (";
2593
//                                            00112233
2594
static const char animation_l_stars[2*4+1] = "   **** ";
2595
//                                            00112233
2596
static const char animation_r_stars[2*4+1] = "  * ** *";
353 tk 2597
s32 SEQ_UI_LCD_Update(void)
2598
{
625 tk 2599
  // special handling in remote client mode
1316 tk 2600
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT ) {
626 tk 2601
    MIOS32_IRQ_Disable();
1316 tk 2602
    u8 force = seq_midi_sysex_remote_force_lcd_update;
2603
    seq_midi_sysex_remote_force_lcd_update = 0;
626 tk 2604
    MIOS32_IRQ_Enable();
2605
    return SEQ_LCD_Update(force);
625 tk 2606
  }
2607
 
596 tk 2608
  // if UI message active: copy over the text
2609
  if( ui_msg_ctr ) {
774 tk 2610
    char *animation_l_ptr;
2611
    char *animation_r_ptr;
596 tk 2612
    u8 msg_x = 0;
2613
    u8 right_aligned = 0;
740 tk 2614
    u8 disable_message = 0;
299 tk 2615
 
596 tk 2616
    switch( ui_msg_type ) {
2617
      case SEQ_UI_MSG_SDCARD: {
1117 tk 2618
    animation_l_ptr = (char *)animation_l_arrows;
2619
    animation_r_ptr = (char *)animation_r_arrows;
596 tk 2620
    msg_x = 0; // MEMO: print such important information at first LCD for the case the user hasn't connected the second LCD yet
2621
    right_aligned = 0;
2622
      } break;
2623
 
756 tk 2624
      case SEQ_UI_MSG_DELAYED_ACTION:
2625
      case SEQ_UI_MSG_DELAYED_ACTION_R: {
1117 tk 2626
    animation_l_ptr = (char *)animation_l_brackets;
2627
    animation_r_ptr = (char *)animation_r_brackets;
756 tk 2628
    if( ui_msg_type == SEQ_UI_MSG_DELAYED_ACTION_R ) {
2629
      msg_x = 40; // right LCD
2630
      right_aligned = 0;
2631
    } else {
2632
      msg_x = 39; // left LCD
2633
      right_aligned = 1;
2634
    }
740 tk 2635
 
2636
    if( ui_delayed_action_callback == NULL ) {
2637
      disable_message = 1; // button has been depressed before delay
2638
    } else {
2639
      int seconds = (ui_delayed_action_ctr / 1000) + 1;
2640
      if( seconds == 1 )
2641
        sprintf(ui_msg[0], "Hold for 1 second ");
2642
      else
2643
        sprintf(ui_msg[0], "Hold for %d seconds", seconds);
2644
    }
2645
      } break;
2646
 
741 tk 2647
      case SEQ_UI_MSG_USER_R: {
1117 tk 2648
    animation_l_ptr = (char *)animation_l_stars;
2649
    animation_r_ptr = (char *)animation_r_stars;
741 tk 2650
    msg_x = 40; // right display
2651
    right_aligned = 0;
2652
      } break;
2653
 
596 tk 2654
      default: {
1117 tk 2655
    animation_l_ptr = (char *)animation_l_stars;
2656
    animation_r_ptr = (char *)animation_r_stars;
596 tk 2657
    msg_x = 39;
2658
    right_aligned = 1;
2659
      } break;
2660
 
2661
    }
2662
 
740 tk 2663
    if( !disable_message ) {
2664
      int anum = (ui_msg_ctr % 1000) / 250;
596 tk 2665
 
740 tk 2666
      int len[2];
2667
      len[0] = strlen((char *)ui_msg[0]);
2668
      len[1] = strlen((char *)ui_msg[1]);
2669
      int len_max = len[0];
2670
      if( len[1] > len_max )
2671
    len_max = len[1];
596 tk 2672
 
740 tk 2673
      if( right_aligned )
2674
    msg_x -= (9 + len_max);
596 tk 2675
 
740 tk 2676
      int line;
2677
      for(line=0; line<2; ++line