Subversion Repositories svn.mios32

Rev

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