Subversion Repositories svn.mios32

Rev

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