Subversion Repositories svn.mios32

Rev

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