Subversion Repositories svn.mios32

Rev

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