Subversion Repositories svn.mios32

Rev

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