Subversion Repositories svn.mios32

Rev

Rev 2524 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
174 tk 1
// $Id: seq_ui_trkevnt.c 2551 2018-01-03 21:11:33Z tk $
2
/*
319 tk 3
 * Track event page
174 tk 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>
326 tk 19
#include <string.h>
766 tk 20
 
21
#include "tasks.h"
22
 
174 tk 23
#include "seq_lcd.h"
24
#include "seq_ui.h"
25
#include "seq_cc.h"
333 tk 26
#include "seq_par.h"
984 tk 27
#include "seq_trg.h"
174 tk 28
#include "seq_layer.h"
690 tk 29
#include "seq_midi_port.h"
30
#include "seq_label.h"
718 tk 31
#include "seq_cc_labels.h"
2041 tk 32
#include "seq_midi_in.h"
1261 tk 33
 
34
#include "file.h"
766 tk 35
#include "seq_file.h"
36
#include "seq_file_t.h"
174 tk 37
 
38
 
39
/////////////////////////////////////////////////////////////////////////////
40
// Local definitions
41
/////////////////////////////////////////////////////////////////////////////
42
 
319 tk 43
// Note/Chord/CC
472 tk 44
#define NUM_OF_ITEMS_NORMAL 8
319 tk 45
#define ITEM_GXTY           0
46
#define ITEM_EVENT_MODE     1
47
#define ITEM_MIDI_PORT      2
48
#define ITEM_MIDI_CHANNEL   3
2092 tk 49
#define ITEM_TRKINST        4
472 tk 50
#define ITEM_LAYER_SELECT   5
51
#define ITEM_LAYER_CONTROL  6
52
#define ITEM_LAYER_PAR      7
174 tk 53
 
319 tk 54
// Drum
55
#define NUM_OF_ITEMS_DRUM   11
472 tk 56
//#define ITEM_GXTY           0
57
//#define ITEM_EVENT_MODE     1
58
//#define ITEM_MIDI_PORT      2
59
//#define ITEM_MIDI_CHANNEL   3
2092 tk 60
//#define ITEM_TRKINST        4
319 tk 61
#define ITEM_LAYER_A_SELECT 5
62
#define ITEM_LAYER_B_SELECT 6
63
#define ITEM_DRUM_SELECT    7
64
#define ITEM_DRUM_NOTE      8
65
#define ITEM_DRUM_VEL_N     9
66
#define ITEM_DRUM_VEL_A     10
174 tk 67
 
766 tk 68
#define IMPORT_NUM_OF_ITEMS    5
69
#define IMPORT_ITEM_NAME       0
70
#define IMPORT_ITEM_CHN        1
71
#define IMPORT_ITEM_MAPS       2
72
#define IMPORT_ITEM_CFG        3
73
#define IMPORT_ITEM_STEPS      4
319 tk 74
 
75
 
766 tk 76
// Preset dialog screens
77
#define PR_DIALOG_NONE          0
2092 tk 78
#define PR_DIALOG_PRESETS       1
79
#define PR_DIALOG_EXPORT_FNAME  2
80
#define PR_DIALOG_EXPORT_FEXISTS 3
81
#define PR_DIALOG_IMPORT        4
766 tk 82
 
83
#define NUM_LIST_DISPLAYED_ITEMS 4
84
#define LIST_ENTRY_WIDTH 9
85
 
86
 
174 tk 87
/////////////////////////////////////////////////////////////////////////////
323 tk 88
// Local types
89
/////////////////////////////////////////////////////////////////////////////
90
 
91
typedef struct {
92
  seq_event_mode_t event_mode;  // event mode as forwarded to SEQ_CC_MIDI_EVENT_MODE
93
  u8               par_layers;  // number of parameter layers
94
  u16              par_steps;   // number of steps per parameter layer
95
  u8               trg_layers;  // number of trigger layers
96
  u16              trg_steps;   // number of steps per trigger layer
328 tk 97
  u8               instruments; // number of instruments per track
323 tk 98
} layer_config_t;
99
 
100
 
101
/////////////////////////////////////////////////////////////////////////////
176 tk 102
// Local prototypes
103
/////////////////////////////////////////////////////////////////////////////
104
 
323 tk 105
static s32 GetLayerConfig(u8 track);
106
static s32 CopyPreset(u8 track, u8 config);
756 tk 107
static void InitReq(u32 dummy);
176 tk 108
 
766 tk 109
static s32 SEQ_UI_TRKEVNT_UpdateDirList(void);
176 tk 110
 
766 tk 111
static s32 DoExport(u8 force_overwrite);
112
static s32 DoImport(void);
113
 
114
 
176 tk 115
/////////////////////////////////////////////////////////////////////////////
178 tk 116
// Local variables
117
/////////////////////////////////////////////////////////////////////////////
118
 
323 tk 119
static u8 selected_layer_config;
472 tk 120
static u8 selected_layer_config_track;
319 tk 121
 
2444 tk 122
static u8 selected_drum_par_layer = 0;
123
 
752 tk 124
static u8 edit_cc_number;
1635 tk 125
static u8 edit_layer_type;
752 tk 126
 
472 tk 127
static const layer_config_t layer_config[] = {
328 tk 128
  //      mode           par_layers  par_steps  trg_layers  trg_steps  instruments
129
  { SEQ_EVENT_MODE_Note,    16,          64,        8,          64,      1 },
130
  { SEQ_EVENT_MODE_Note,     8,         128,        8,         128,      1 },
131
  { SEQ_EVENT_MODE_Note,     4,         256,        8,         256,      1 },
132
  { SEQ_EVENT_MODE_Chord,   16,          64,        8,          64,      1 },
133
  { SEQ_EVENT_MODE_Chord,    8,         128,        8,         128,      1 },
134
  { SEQ_EVENT_MODE_Chord,    4,         256,        8,         256,      1 },
135
  { SEQ_EVENT_MODE_CC,      16,          64,        8,          64,      1 },
136
  { SEQ_EVENT_MODE_CC,       8,         128,        8,         128,      1 },
137
  { SEQ_EVENT_MODE_CC,       4,         256,        8,         256,      1 },
2444 tk 138
  { SEQ_EVENT_MODE_Drum,     4,          16,        2,          64,     16 },
2451 tk 139
  { SEQ_EVENT_MODE_Drum,     4,          16,        2,         128,     16 },
140
  { SEQ_EVENT_MODE_Drum,     4,          16,        1,         256,     16 },
328 tk 141
  { SEQ_EVENT_MODE_Drum,     1,          64,        2,          64,     16 },
142
  { SEQ_EVENT_MODE_Drum,     2,          32,        1,         128,     16 },
143
  { SEQ_EVENT_MODE_Drum,     1,         128,        2,         128,      8 },
2389 tk 144
  { SEQ_EVENT_MODE_Drum,     2,          64,        2,         128,      8 },
984 tk 145
  { SEQ_EVENT_MODE_Drum,     2,          64,        1,         256,      8 },
146
  { SEQ_EVENT_MODE_Drum,     1,          64,        1,          64,     16 },
147
  { SEQ_EVENT_MODE_Drum,     1,         128,        1,         128,      8 },
1316 tk 148
  { SEQ_EVENT_MODE_Drum,     1,         256,        1,         256,      4 }
323 tk 149
};
150
 
319 tk 151
 
766 tk 152
static u8 pr_dialog;
153
 
1261 tk 154
static s32 dir_num_items; // contains FILE error status if < 0
766 tk 155
static u8 dir_view_offset = 0; // only changed once after startup
156
static char dir_name[12]; // directory name of device (first char is 0 if no device selected)
157
 
158
static seq_file_t_import_flags_t import_flags;
159
 
160
 
178 tk 161
/////////////////////////////////////////////////////////////////////////////
2041 tk 162
 
163
typedef enum {
164
  MIDI_LEARN_MODE_OFF = 0,
165
  MIDI_LEARN_MODE_DRUM_NOTE,
166
} midi_learn_mode_t;
167
 
168
static midi_learn_mode_t midi_learn_mode = MIDI_LEARN_MODE_OFF;
169
 
170
/////////////////////////////////////////////////////////////////////////////
174 tk 171
// Local LED handler function
172
/////////////////////////////////////////////////////////////////////////////
173
static s32 LED_Handler(u16 *gp_leds)
174
{
766 tk 175
  switch( pr_dialog ) {
176
    case PR_DIALOG_PRESETS:
177
      *gp_leds = (3 << (2*ui_selected_item));
178
      break;
174 tk 179
 
766 tk 180
    case PR_DIALOG_EXPORT_FNAME:
181
    case PR_DIALOG_EXPORT_FEXISTS:
182
      // no LED functions yet
183
      break;
184
 
185
    case PR_DIALOG_IMPORT:
186
      switch( ui_selected_item ) {
187
        case IMPORT_ITEM_NAME:
188
      *gp_leds |= 0x0100;
189
      break;
190
        case IMPORT_ITEM_CHN:
191
      *gp_leds |= 0x0200;
192
      break;
193
        case IMPORT_ITEM_MAPS:
194
      *gp_leds |= 0x0400;
195
      break;
196
        case IMPORT_ITEM_CFG:
197
      *gp_leds |= 0x0800;
198
      break;
199
        case IMPORT_ITEM_STEPS:
200
      *gp_leds |= 0x1000;
201
      break;
202
      }
203
      break;
204
 
205
    default:
206
      if( ui_cursor_flash ) { // if flashing flag active: no LED flag set
207
    // flash INIT LED if current preset doesn't match with old preset
208
    // this notifies the user, that he should press the "INIT" button
209
    u8 visible_track = SEQ_UI_VisibleTrackGet();
210
    if( selected_layer_config != GetLayerConfig(visible_track) )
211
      *gp_leds = 0x8000;
212
 
213
    return 0;
214
      }
215
 
216
      if( layer_config[selected_layer_config].event_mode == SEQ_EVENT_MODE_Drum ) {
217
    switch( ui_selected_item ) {
218
      case ITEM_GXTY: *gp_leds = 0x0001; break;
219
      case ITEM_EVENT_MODE: *gp_leds = 0x001e; break;
220
      case ITEM_MIDI_PORT: *gp_leds = 0x0020; break;
221
      case ITEM_MIDI_CHANNEL: *gp_leds = 0x0040; break;
2092 tk 222
      case ITEM_TRKINST: *gp_leds = 0x0080; break;
766 tk 223
      case ITEM_LAYER_A_SELECT: *gp_leds = 0x0100; break;
224
      case ITEM_LAYER_B_SELECT: *gp_leds = 0x0200; break;
225
      case ITEM_DRUM_SELECT: *gp_leds = 0x0400; break;
226
      case ITEM_DRUM_NOTE: *gp_leds = 0x0800; break;
227
      case ITEM_DRUM_VEL_N: *gp_leds = 0x1000; break;
228
      case ITEM_DRUM_VEL_A: *gp_leds = 0x2000; break;
229
    }
230
      } else {
231
    switch( ui_selected_item ) {
232
      case ITEM_GXTY: *gp_leds = 0x0001; break;
233
      case ITEM_EVENT_MODE: *gp_leds = 0x001e; break;
234
      case ITEM_MIDI_PORT: *gp_leds = 0x0020; break;
235
      case ITEM_MIDI_CHANNEL: *gp_leds = 0x0040; break;
2092 tk 236
      case ITEM_TRKINST: *gp_leds = 0x0080; break;
766 tk 237
      case ITEM_LAYER_SELECT: *gp_leds = 0x0100; break;
238
      case ITEM_LAYER_CONTROL: *gp_leds = 0x0200; break;
239
      case ITEM_LAYER_PAR: *gp_leds = 0x1c00; break;
240
    }
241
      }
174 tk 242
  }
243
 
244
  return 0; // no error
245
}
246
 
247
 
248
/////////////////////////////////////////////////////////////////////////////
249
// Local encoder callback function
250
// Should return:
251
//   1 if value has been changed
252
//   0 if value hasn't been changed
253
//  -1 if invalid or unsupported encoder
254
/////////////////////////////////////////////////////////////////////////////
255
static s32 Encoder_Handler(seq_ui_encoder_t encoder, s32 incrementer)
256
{
323 tk 257
  u8 event_mode = layer_config[selected_layer_config].event_mode;
335 tk 258
  u8 visible_track = SEQ_UI_VisibleTrackGet();
178 tk 259
 
766 tk 260
  switch( pr_dialog ) {
261
    ///////////////////////////////////////////////////////////////////////////
262
    case PR_DIALOG_PRESETS:
472 tk 263
      switch( encoder ) {
264
        case SEQ_UI_ENCODER_GP9:
766 tk 265
      return SEQ_UI_GxTyInc(incrementer);
174 tk 266
 
472 tk 267
        case SEQ_UI_ENCODER_GP10:
766 tk 268
      return -1; // not mapped
174 tk 269
 
472 tk 270
        case SEQ_UI_ENCODER_GP11:
766 tk 271
        case SEQ_UI_ENCODER_GP12: {
272
      int i;
174 tk 273
 
766 tk 274
      // only via button
275
      if( incrementer != 0 )
276
        return 0;
174 tk 277
 
766 tk 278
      // initialize keypad editor
279
      SEQ_UI_KeyPad_Init();
280
      for(i=0; i<8; ++i)
281
        dir_name[i] = ' ';
282
 
283
      ui_selected_item = 0;
284
      pr_dialog = PR_DIALOG_EXPORT_FNAME;
285
 
286
      return 1;
287
    }
288
 
472 tk 289
        case SEQ_UI_ENCODER_GP13:
481 tk 290
        case SEQ_UI_ENCODER_GP14:
766 tk 291
        case SEQ_UI_ENCODER_GP15:
292
      return -1; // not mapped
472 tk 293
 
481 tk 294
        case SEQ_UI_ENCODER_GP16:
766 tk 295
      // EXIT only via button
296
      if( incrementer == 0 ) {
297
        ui_selected_item = 0;
298
        pr_dialog = PR_DIALOG_NONE;
299
      }
300
      return 1;
301
 
302
        default:
303
      if( SEQ_UI_SelectListItem(incrementer, dir_num_items, NUM_LIST_DISPLAYED_ITEMS, &ui_selected_item, &dir_view_offset) )
304
        SEQ_UI_TRKEVNT_UpdateDirList();
472 tk 305
      }
766 tk 306
      break;
307
 
308
 
309
    ///////////////////////////////////////////////////////////////////////////
310
    case PR_DIALOG_IMPORT: {
311
      if( encoder <= SEQ_UI_ENCODER_GP8 )
312
    return -1; // not mapped
313
 
472 tk 314
      switch( encoder ) {
315
        case SEQ_UI_ENCODER_GP9:
766 tk 316
          ui_selected_item = IMPORT_ITEM_NAME;
317
          break;
174 tk 318
 
472 tk 319
        case SEQ_UI_ENCODER_GP10:
766 tk 320
          ui_selected_item = IMPORT_ITEM_CHN;
321
          break;
322
 
472 tk 323
        case SEQ_UI_ENCODER_GP11:
766 tk 324
          ui_selected_item = IMPORT_ITEM_MAPS;
325
          break;
326
 
472 tk 327
        case SEQ_UI_ENCODER_GP12:
766 tk 328
          ui_selected_item = IMPORT_ITEM_CFG;
329
          break;
330
 
472 tk 331
        case SEQ_UI_ENCODER_GP13:
766 tk 332
          ui_selected_item = IMPORT_ITEM_STEPS;
333
          break;
334
 
472 tk 335
        case SEQ_UI_ENCODER_GP14:
766 tk 336
      // not mapped
337
      return -1;
338
 
339
        case SEQ_UI_ENCODER_GP15:
340
      // IMPORT only via button
341
      if( incrementer == 0 ) {
342
        if( DoImport() == 0 ) {
343
          // exit page
344
          ui_selected_item = 0;
345
          pr_dialog = PR_DIALOG_NONE;
752 tk 346
        }
347
      }
766 tk 348
      return 1;
349
 
350
        case SEQ_UI_ENCODER_GP16: {
351
      // EXIT only via button
352
      if( incrementer == 0 ) {
353
        ui_selected_item = 0;
354
        pr_dialog = PR_DIALOG_NONE;
355
      }
356
      return 1;
357
    } break;
358
      }
359
 
360
      // for GP encoders and Datawheel
361
      switch( ui_selected_item ) {
362
        case IMPORT_ITEM_NAME:
363
      if( !incrementer ) incrementer = import_flags.NAME ? -1 : 1;
364
      import_flags.NAME = incrementer > 0 ? 1 : 0;
472 tk 365
      break;
174 tk 366
 
766 tk 367
        case IMPORT_ITEM_CHN:
368
      if( !incrementer ) incrementer = import_flags.CHN ? -1 : 1;
369
      import_flags.CHN = incrementer > 0 ? 1 : 0;
370
      break;
319 tk 371
 
766 tk 372
        case IMPORT_ITEM_MAPS:
373
      if( !incrementer ) incrementer = import_flags.MAPS ? -1 : 1;
374
      import_flags.MAPS = incrementer > 0 ? 1 : 0;
375
      break;
376
 
377
        case IMPORT_ITEM_CFG:
378
      if( !incrementer ) incrementer = import_flags.CFG ? -1 : 1;
379
      import_flags.CFG = incrementer > 0 ? 1 : 0;
380
      break;
381
 
382
        case IMPORT_ITEM_STEPS:
383
      if( !incrementer ) incrementer = import_flags.STEPS ? -1 : 1;
384
      import_flags.STEPS = incrementer > 0 ? 1 : 0;
385
      break;
472 tk 386
      }
766 tk 387
 
388
      return -1; // invalid or unsupported encoder
472 tk 389
    }
390
 
391
 
766 tk 392
    ///////////////////////////////////////////////////////////////////////////
393
    case PR_DIALOG_EXPORT_FNAME: {
394
      switch( encoder ) {
395
        case SEQ_UI_ENCODER_GP15: {
396
      // SAVE only via button
397
      if( incrementer != 0 )
398
        return 0;
472 tk 399
 
766 tk 400
      if( DoExport(0) == 0 ) { // don't force overwrite
401
        // exit keypad editor
402
        ui_selected_item = 0;
403
        pr_dialog = PR_DIALOG_NONE;
404
      }
174 tk 405
 
766 tk 406
      return 1;
407
    } break;
472 tk 408
 
766 tk 409
        case SEQ_UI_ENCODER_GP16: {
410
      // EXIT only via button
411
      if( incrementer == 0 ) {
412
        ui_selected_item = 0;
413
        pr_dialog = PR_DIALOG_NONE;
414
      }
415
      return 1;
416
    } break;
285 tk 417
      }
472 tk 418
 
766 tk 419
      return SEQ_UI_KeyPad_Handler(encoder, incrementer, (char *)&dir_name[0], 8);
420
    }
472 tk 421
 
174 tk 422
 
766 tk 423
    ///////////////////////////////////////////////////////////////////////////
424
    case PR_DIALOG_EXPORT_FEXISTS: {
425
      switch( encoder ) {
426
        case SEQ_UI_ENCODER_GP11: {
427
      // YES only via button
428
      if( incrementer != 0 )
429
        return 0;
430
 
431
      // YES: overwrite file
432
      if( DoExport(1) == 0 ) { // force overwrite
433
        // exit keypad editor
434
        ui_selected_item = 0;
435
        pr_dialog = PR_DIALOG_NONE;
436
      }
335 tk 437
      return 1;
766 tk 438
    } break;
439
 
440
        case SEQ_UI_ENCODER_GP12: {
441
      // NO only via button
442
      if( incrementer != 0 )
443
        return 0;
444
 
445
      // NO: don't overwrite file - back to filename entry
446
 
447
      ui_selected_item = 0;
448
      pr_dialog = PR_DIALOG_EXPORT_FNAME;
335 tk 449
      return 1;
766 tk 450
    } break;
451
 
452
        case SEQ_UI_ENCODER_GP16: {
453
      // EXIT only via button
454
      if( incrementer == 0 ) {
455
        ui_selected_item = 0;
456
        pr_dialog = PR_DIALOG_NONE;
457
      }
458
      return 1;
459
    } break;
460
      }
461
 
462
      return -1; // not mapped
463
    }
464
 
465
 
466
    ///////////////////////////////////////////////////////////////////////////
467
    default:
468
 
469
      if( encoder >= SEQ_UI_ENCODER_GP9 && encoder <= SEQ_UI_ENCODER_GP16 ) {
470
    if( selected_layer_config != GetLayerConfig(visible_track) ) {
1044 tk 471
      // ENC function disabled as long as pattern hasn't been initialized
766 tk 472
      return -1;
335 tk 473
    }
766 tk 474
 
752 tk 475
    if( event_mode == SEQ_EVENT_MODE_Drum ) {
766 tk 476
      switch( encoder ) {
477
        case SEQ_UI_ENCODER_GP9:
478
          ui_selected_item = ITEM_LAYER_A_SELECT;
479
          break;
480
 
481
        case SEQ_UI_ENCODER_GP10:
482
          ui_selected_item = ITEM_LAYER_B_SELECT;
483
          break;
484
 
485
        case SEQ_UI_ENCODER_GP11:
486
          ui_selected_item = ITEM_DRUM_SELECT;
487
          break;
488
 
489
        case SEQ_UI_ENCODER_GP12:
490
          ui_selected_item = ITEM_DRUM_NOTE;
2041 tk 491
 
492
          // GP12 button activates MIDI learn mode
493
          if( incrementer == 0 ) {
494
        midi_learn_mode = MIDI_LEARN_MODE_DRUM_NOTE;
495
        SEQ_UI_MIDILearnMessage(SEQ_UI_MSG_USER, 1);
496
          }
497
 
766 tk 498
          break;
499
 
500
        case SEQ_UI_ENCODER_GP13:
501
          ui_selected_item = ITEM_DRUM_VEL_N;
502
          break;
503
 
504
        case SEQ_UI_ENCODER_GP14:
505
          ui_selected_item = ITEM_DRUM_VEL_A;
506
          break;
507
 
508
        case SEQ_UI_ENCODER_GP15:
509
          // change to preset page (only via button)
510
          if( incrementer == 0 ) {
511
        ui_selected_item = 0;
512
        pr_dialog = PR_DIALOG_PRESETS;
513
        SEQ_UI_TRKEVNT_UpdateDirList();
514
          }
515
          return 1;
516
 
517
        case SEQ_UI_ENCODER_GP16:
518
          return -1; // EXIT not mapped to encoder
519
      }
752 tk 520
    } else {
766 tk 521
      switch( encoder ) {
522
        case SEQ_UI_ENCODER_GP9:
523
          ui_selected_item = ITEM_LAYER_SELECT;
524
          break;
525
 
526
        case SEQ_UI_ENCODER_GP10:
1635 tk 527
          // Layer selection now has to be confirmed with GP button
528
          if( incrementer ) {
529
        if( ui_selected_item != ITEM_LAYER_CONTROL ) {
530
          edit_layer_type = SEQ_CC_Get(visible_track, SEQ_CC_LAY_CONST_A1 + ui_selected_par_layer);
531
          ui_selected_item = ITEM_LAYER_CONTROL;
532
        }
533
        SEQ_UI_Msg(SEQ_UI_MSG_USER, 2000, "Please confirm new type", "with GP button!");
534
          } else {
535
        if( edit_layer_type != SEQ_CC_Get(visible_track, SEQ_CC_LAY_CONST_A1 + ui_selected_par_layer) ) {
536
          // TODO: has to be done for all selected tracks
537
          SEQ_CC_Set(visible_track, SEQ_CC_LAY_CONST_A1 + ui_selected_par_layer, edit_layer_type);
538
          SEQ_LAYER_CopyParLayerPreset(visible_track, ui_selected_par_layer);
539
          SEQ_UI_Msg(SEQ_UI_MSG_USER, 2000, "Layer Type", "has been changed.");
1771 tk 540
        } else {
541
          // send MIDI event
542
          if( SEQ_LAYER_DirectSendEvent(visible_track, ui_selected_par_layer) >= 0 ) {
543
            SEQ_UI_Msg(SEQ_UI_MSG_USER, 2000, "MIDI event", "has been sent.");
544
          }
1635 tk 545
        }
546
          }
766 tk 547
          break;
548
 
549
        case SEQ_UI_ENCODER_GP11:
550
        case SEQ_UI_ENCODER_GP12:
2294 tk 551
        case SEQ_UI_ENCODER_GP13: {
552
          u8 assignment = SEQ_PAR_AssignmentGet(visible_track, ui_selected_par_layer);
553
          if( ui_selected_item == ITEM_LAYER_CONTROL )
554
        assignment = edit_layer_type;
555
 
556
          if( assignment == SEQ_PAR_Type_CC ) {
557
        // CC number selection now has to be confirmed with GP button
558
        if( incrementer ) {
559
          if( ui_selected_item != ITEM_LAYER_PAR ) {
560
            edit_cc_number = SEQ_CC_Get(visible_track, SEQ_CC_LAY_CONST_B1 + ui_selected_par_layer);
561
            ui_selected_item = ITEM_LAYER_PAR;
562
          }
563
          SEQ_UI_Msg(SEQ_UI_MSG_USER, 2000, "Please confirm CC", "with GP button!");
1771 tk 564
        } else {
2294 tk 565
          if( edit_cc_number != SEQ_CC_Get(visible_track, SEQ_CC_LAY_CONST_B1 + ui_selected_par_layer) ) {
566
            SEQ_CC_Set(visible_track, SEQ_CC_LAY_CONST_B1 + ui_selected_par_layer, edit_cc_number);
567
            SEQ_UI_Msg(SEQ_UI_MSG_USER, 2000, "CC number", "has been changed.");
568
          } else {
569
            // send MIDI event
570
            if( SEQ_LAYER_DirectSendEvent(visible_track, ui_selected_par_layer) >= 0 ) {
571
              SEQ_UI_Msg(SEQ_UI_MSG_USER, 2000, "MIDI event", "has been sent.");
572
            }
1771 tk 573
          }
766 tk 574
        }
2294 tk 575
          } else {
576
        return -1; // ignore
766 tk 577
          }
2294 tk 578
        } break;
766 tk 579
 
580
        case SEQ_UI_ENCODER_GP14:
581
        case SEQ_UI_ENCODER_GP15:
582
          // change to preset page (only via button)
583
          if( incrementer == 0 ) {
584
        ui_selected_item = 0;
585
        pr_dialog = PR_DIALOG_PRESETS;
586
        SEQ_UI_TRKEVNT_UpdateDirList();
587
          }
588
          return 1;
589
 
590
        case SEQ_UI_ENCODER_GP16:
591
          return -1; // not mapped to encoder
592
      }
752 tk 593
    }
766 tk 594
      }
752 tk 595
 
766 tk 596
      switch( encoder ) {
597
        case SEQ_UI_ENCODER_GP1:
598
      ui_selected_item = ITEM_GXTY;
599
      break;
600
 
601
        case SEQ_UI_ENCODER_GP2:
602
        case SEQ_UI_ENCODER_GP3:
603
        case SEQ_UI_ENCODER_GP4:
604
        case SEQ_UI_ENCODER_GP5:
605
      ui_selected_item = ITEM_EVENT_MODE;
606
      break;
607
 
608
        case SEQ_UI_ENCODER_GP6:
609
      ui_selected_item = ITEM_MIDI_PORT;
610
      break;
611
 
612
        case SEQ_UI_ENCODER_GP7:
613
      ui_selected_item = ITEM_MIDI_CHANNEL;
614
      break;
615
 
616
        case SEQ_UI_ENCODER_GP8:
2092 tk 617
      // enter track instrument page if button has been pressed
618
      if( incrementer == 0 )
619
        SEQ_UI_PageSet(SEQ_UI_PAGE_TRKINST);
620
      return 1;
766 tk 621
      }
622
 
623
      // for GP encoders and Datawheel
624
      switch( ui_selected_item ) {
625
        case ITEM_GXTY: return SEQ_UI_GxTyInc(incrementer);
626
        case ITEM_EVENT_MODE: {
627
      u8 max_layer_config = (sizeof(layer_config)/sizeof(layer_config_t)) - 1;
628
      return SEQ_UI_Var8_Inc(&selected_layer_config, 0, max_layer_config, incrementer);
629
    } break;
630
 
631
        case ITEM_MIDI_PORT: {
632
      mios32_midi_port_t port = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_PORT);
633
      u8 port_ix = SEQ_MIDI_PORT_OutIxGet(port);
634
      if( SEQ_UI_Var8_Inc(&port_ix, 0, SEQ_MIDI_PORT_OutNumGet()-1, incrementer) ) {
635
        mios32_midi_port_t new_port = SEQ_MIDI_PORT_OutPortGet(port_ix);
636
        SEQ_UI_CC_Set(SEQ_CC_MIDI_PORT, new_port);
637
        return 1; // value changed
638
      }
639
      return 0; // value not changed
640
    } break;
641
 
642
        case ITEM_MIDI_CHANNEL: return SEQ_UI_CC_Inc(SEQ_CC_MIDI_CHANNEL, 0, 15, incrementer);
643
      }
644
 
645
      if( event_mode == SEQ_EVENT_MODE_Drum ) {
646
    switch( ui_selected_item ) {
647
    case ITEM_DRUM_SELECT: {
648
      u8 num_drums = layer_config[selected_layer_config].instruments;
649
      return SEQ_UI_Var8_Inc(&ui_selected_instrument, 0, num_drums-1, incrementer);
650
    } break;
651
    case ITEM_LAYER_A_SELECT: {
2444 tk 652
      if( layer_config[selected_layer_config].par_layers > 2 ) {
653
        return SEQ_UI_Var8_Inc(&selected_drum_par_layer, 0, layer_config[selected_layer_config].par_layers-1, incrementer);
654
      } else {
655
        selected_drum_par_layer = 0;
656
        if( SEQ_UI_CC_Inc(SEQ_CC_PAR_ASG_DRUM_LAYER_A, 0, SEQ_PAR_NUM_TYPES-1, incrementer) ) {
657
          SEQ_LAYER_CopyParLayerPreset(visible_track, 0);
658
          return 1;
659
        }
660
        return 0;
766 tk 661
      }
662
    } break;
663
    case ITEM_LAYER_B_SELECT: {
2444 tk 664
      if( layer_config[selected_layer_config].par_layers > 2 ) {
665
        if( SEQ_UI_CC_Inc(SEQ_CC_PAR_ASG_DRUM_LAYER_A + selected_drum_par_layer, 0, SEQ_PAR_NUM_TYPES-1, incrementer) ) {
666
          SEQ_LAYER_CopyParLayerPreset(visible_track, selected_drum_par_layer);
667
          return 1;
668
        }
669
        return 0;
670
      } else {
671
        selected_drum_par_layer = 1;
672
        if( SEQ_UI_CC_Inc(SEQ_CC_PAR_ASG_DRUM_LAYER_B, 0, SEQ_PAR_NUM_TYPES-1, incrementer) ) {
673
          SEQ_LAYER_CopyParLayerPreset(visible_track, 1);
674
          return 1;
675
        }
676
        return 0;
766 tk 677
      }
678
    } break;
2041 tk 679
 
680
    case ITEM_DRUM_NOTE: {
681
      return SEQ_UI_CC_Inc(SEQ_CC_LAY_CONST_A1 + ui_selected_instrument, 0, 127, incrementer);
682
    } break;
683
 
684
    case ITEM_DRUM_VEL_N: {
685
      if( !SEQ_CC_TrackHasAccentTrgLayer(visible_track) ) {
686
        SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "VelN can't be changed:", "No accent layer in this config!");
687
      } else if( SEQ_CC_TrackHasVelocityParLayer(visible_track) ) {
688
        SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "VelN can't be changed: Track", "has already a velocity layer!");
689
      } else {
690
        return SEQ_UI_CC_Inc(SEQ_CC_LAY_CONST_B1 + ui_selected_instrument, 0, 127, incrementer);
691
      }
692
    } break;
693
 
694
    case ITEM_DRUM_VEL_A: {
695
      if( !SEQ_CC_TrackHasAccentTrgLayer(visible_track) ) {
696
        SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "VelA can't be changed:", "No accent layer in this config!");
697
      } else {
698
        return SEQ_UI_CC_Inc(SEQ_CC_LAY_CONST_C1 + ui_selected_instrument, 0, 127, incrementer);
699
      }
700
    } break;
333 tk 701
    }
766 tk 702
      } else {
703
    switch( ui_selected_item ) {
1024 tk 704
      case ITEM_LAYER_SELECT:  return SEQ_UI_Var8_Inc(&ui_selected_par_layer, 0, SEQ_PAR_NumLayersGet(visible_track)-1, incrementer);
766 tk 705
      case ITEM_LAYER_PAR:
706
        if( event_mode == SEQ_EVENT_MODE_Drum ) {
707
          return SEQ_UI_CC_Inc(SEQ_CC_LAY_CONST_B1 + ui_selected_par_layer, 0, 127, incrementer);
708
        } else {
709
          // CC number selection now has to be confirmed with GP button
1811 tk 710
          return SEQ_UI_Var8_Inc(&edit_cc_number, 0, 128, incrementer);
766 tk 711
        }
712
 
713
      case ITEM_LAYER_CONTROL: {
1635 tk 714
        // Layer Control selection now has to be confirmed with GP button
2274 tk 715
        u8 value = SEQ_PAR_MappedTypeGet(edit_layer_type);
716
        if( SEQ_UI_Var8_Inc(&value, 0, SEQ_PAR_NUM_TYPES-1, incrementer) > 0 ) {
717
          edit_layer_type = SEQ_PAR_UnMappedTypeGet(value);
718
          return 1;
719
        }
720
        return 0;
766 tk 721
      } break;
722
    }
723
      }
319 tk 724
  }
725
 
174 tk 726
  return -1; // invalid or unsupported encoder
727
}
728
 
729
 
730
/////////////////////////////////////////////////////////////////////////////
731
// Local button callback function
732
// Should return:
733
//   1 if value has been changed
734
//   0 if value hasn't been changed
735
//  -1 if invalid or unsupported button
736
/////////////////////////////////////////////////////////////////////////////
737
static s32 Button_Handler(seq_ui_button_t button, s32 depressed)
738
{
752 tk 739
  u8 event_mode = layer_config[selected_layer_config].event_mode;
323 tk 740
 
766 tk 741
  switch( pr_dialog ) {
742
    ///////////////////////////////////////////////////////////////////////////
743
    case PR_DIALOG_PRESETS:
744
      if( depressed ) return 0; // ignore when button depressed
745
 
746
      if( button >= SEQ_UI_BUTTON_GP9 && button <= SEQ_UI_BUTTON_GP16 )
747
    return Encoder_Handler(button, 0); // re-use encoder handler
748
 
749
      if( button <= SEQ_UI_BUTTON_GP8 || button == SEQ_UI_BUTTON_Select ) {
750
    if( button != SEQ_UI_BUTTON_Select )
751
      ui_selected_item = button / 2;
752
 
753
    if( dir_num_items >= 1 && (ui_selected_item+dir_view_offset) < dir_num_items ) {
754
      // get filename
956 tk 755
      int i;
756
      char *p = (char *)&dir_name[0];
757
      for(i=0; i<8; ++i) {
758
        char c = ui_global_dir_list[LIST_ENTRY_WIDTH*ui_selected_item + i];
759
        if( c != ' ' )
760
          *p++ = c;
761
      }
762
      *p++ = 0;
766 tk 763
      // switch to import page
319 tk 764
      ui_selected_item = 0;
766 tk 765
      pr_dialog = PR_DIALOG_IMPORT;
766
    }
1123 tk 767
 
768
    return 1;
319 tk 769
      }
1123 tk 770
      break;
319 tk 771
 
174 tk 772
 
766 tk 773
    ///////////////////////////////////////////////////////////////////////////
774
    case PR_DIALOG_IMPORT:
775
      if( depressed ) return 0; // ignore when button depressed
776
 
777
      if( button <= SEQ_UI_BUTTON_GP16 )
778
    return Encoder_Handler(button, 0); // re-use encoder handler
779
 
780
      switch( button ) {
781
        case SEQ_UI_BUTTON_Select:
782
        case SEQ_UI_BUTTON_Right:
783
          if( ++ui_selected_item >= IMPORT_NUM_OF_ITEMS )
784
        ui_selected_item = 0;
785
 
786
          return 1; // value always changed
787
 
788
        case SEQ_UI_BUTTON_Left:
789
          if( ui_selected_item == 0 )
790
        ui_selected_item = IMPORT_NUM_OF_ITEMS-1;
1142 tk 791
      else
792
        --ui_selected_item;    
766 tk 793
          return 1; // value always changed
794
 
795
        case SEQ_UI_BUTTON_Up:
796
          return Encoder_Handler(SEQ_UI_ENCODER_Datawheel, 1);
797
 
798
        case SEQ_UI_BUTTON_Down:
799
          return Encoder_Handler(SEQ_UI_ENCODER_Datawheel, -1);
319 tk 800
      }
1123 tk 801
      break;
174 tk 802
 
803
 
766 tk 804
    ///////////////////////////////////////////////////////////////////////////
805
    case PR_DIALOG_EXPORT_FNAME:
806
    case PR_DIALOG_EXPORT_FEXISTS: {
807
      if( depressed ) return 0; // ignore when button depressed
808
 
1123 tk 809
      if( button <= SEQ_UI_BUTTON_GP16 )
810
    return Encoder_Handler(button, 0); // re-use encoder handler
811
    } break;
766 tk 812
 
813
 
814
    ///////////////////////////////////////////////////////////////////////////
815
    default:
816
      if( button == SEQ_UI_BUTTON_GP16 ) {
817
    if( depressed )
818
      SEQ_UI_UnInstallDelayedActionCallback(InitReq);
819
    else {
2502 tk 820
      if( seq_ui_button_state.ENC_BTN_FWD_PRESSED ) {
821
        InitReq(0);
822
      } else {
823
        SEQ_UI_InstallDelayedActionCallback(InitReq, 2000, 0);
824
        SEQ_UI_Msg(SEQ_UI_MSG_DELAYED_ACTION_R, 2001, "", "to initialize Track!");
825
      }
766 tk 826
    }
827
    return 1; // value has been changed
828
      }
829
 
2041 tk 830
      if( depressed ) {
831
    if( button == SEQ_UI_BUTTON_GP12 ) {
832
      if( midi_learn_mode != MIDI_LEARN_MODE_OFF ) {
833
        midi_learn_mode = MIDI_LEARN_MODE_OFF;
834
        SEQ_UI_MIDILearnMessage(SEQ_UI_MSG_USER, 0);
835
      }
836
    }
766 tk 837
 
2041 tk 838
    return 0; // ignore when button depressed
839
      }
840
 
766 tk 841
      if( button <= SEQ_UI_BUTTON_GP15 )
842
    return Encoder_Handler((seq_ui_encoder_t)button, 0);
843
 
844
      switch( button ) {
845
        case SEQ_UI_BUTTON_Select:
846
        case SEQ_UI_BUTTON_Right:
847
      if( event_mode == SEQ_EVENT_MODE_Drum ) {
848
        if( ++ui_selected_item >= NUM_OF_ITEMS_DRUM )
849
          ui_selected_item = 0;
850
      } else {
851
        if( ++ui_selected_item >= NUM_OF_ITEMS_NORMAL )
852
          ui_selected_item = 0;
853
      }
854
 
855
      return 1; // value always changed
856
 
857
        case SEQ_UI_BUTTON_Left:
858
      if( event_mode == SEQ_EVENT_MODE_Drum ) {
859
        if( ui_selected_item == 0 )
860
          ui_selected_item = NUM_OF_ITEMS_DRUM-1;
1142 tk 861
        else
862
          --ui_selected_item;
766 tk 863
      } else {
864
        if( ui_selected_item == 0 )
865
          ui_selected_item = NUM_OF_ITEMS_NORMAL-1;
1142 tk 866
        else
867
          --ui_selected_item;
766 tk 868
      }
869
      return 1; // value always changed
870
 
871
        case SEQ_UI_BUTTON_Up:
872
      return Encoder_Handler(SEQ_UI_ENCODER_Datawheel, 1);
873
 
874
        case SEQ_UI_BUTTON_Down:
875
      return Encoder_Handler(SEQ_UI_ENCODER_Datawheel, -1);
876
      }
174 tk 877
  }
878
 
1123 tk 879
  if( depressed )
880
    return 0; // ignore when button depressed
881
 
882
  switch( button ) {
883
  case SEQ_UI_BUTTON_Exit:
884
    if( pr_dialog != PR_DIALOG_NONE ) {
885
      // switch to main dialog
886
      pr_dialog = PR_DIALOG_NONE;
887
      ui_selected_item = 0;
888
      return 1;
889
    }
890
    break;
891
  }
892
 
174 tk 893
  return -1; // invalid or unsupported button
894
}
895
 
896
 
897
/////////////////////////////////////////////////////////////////////////////
898
// Local Display Handler function
899
// IN: <high_prio>: if set, a high-priority LCD update is requested
900
/////////////////////////////////////////////////////////////////////////////
901
static s32 LCD_Handler(u8 high_prio)
902
{
903
  if( high_prio )
904
    return 0; // there are no high-priority updates
905
 
906
  // layout:
907
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
908
  // 01234567890123456789012345678901234567890123456789012345678901234567890123456789
909
  // <--------------------------------------><-------------------------------------->
2092 tk 910
  // Trk. Type Steps/ParL/TrgL Port Chn. Trk.Layer  controls                         
911
  // G1T1 Note  256   4     8  IIC2  12  Inst  D    Prob                PRESETS  INIT
174 tk 912
 
2092 tk 913
  // Trk. Type Steps/ParL/TrgL Port Chn. Trk.Layer  controls                         
914
  // G1T1 Note  256   4     8  IIC2  12  Inst  D    CC #001 (ModWheel)  PRESETS  INIT
319 tk 915
 
916
  // Track Type "Note", Chord" and "CC":
917
  // Note: Parameter Layer A/B/C statically assigned to Note Number/Velocity/Length
918
  //       Parameter Layer D..P can be mapped to
919
  //       - additional Notes (e.g. for poly recording)
920
  //       - Base note (directly forwarded to Transposer, e.g. for Force-to-Scale or Chords)
921
  //       - CC (Number 000..127 assignable, GM controller name will be displayed)
922
  //       - Pitch Bender
923
  //       - Loopback (Number 000..127 assignable, name will be displayed)
338 tk 924
  //       - Delay (0..95 ticks @384 ppqn)
319 tk 925
  //       - Probability (100%..0%)
327 tk 926
  //       - "Roll/Flam Effect" (a selection of up to 128 different effects selectable for each step separately)
319 tk 927
  // Chord: same like Note, but predefined Chords will be played
928
  // CC: Layer A/B/C play CCs (or other parameters) as well - no note number, no velocity, no length
929
 
930
  // Available Layer Constraints (Partitioning for 1024 bytes Par. memory, 2048 bits Trg. memory)
931
  //    - 256 Steps with  4 Parameter Layers A-D and 8 Trigger Layers A-H
932
  //    - 128 Steps with  8 Parameter Layers A-H and 8 Trigger Layers A-H
933
  //    -  64 Steps with 16 Parameter Layers A-P and 8 Trigger Layers A-H
934
 
935
 
936
  // layout:
937
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
938
  // 01234567890123456789012345678901234567890123456789012345678901234567890123456789
939
  // <--------------------------------------><-------------------------------------->
2092 tk 940
  // Trk. Type StepsP/T  Drums Port Chn. Trk.LayA LayB  Drum Note VelN VelA PRE-    
941
  // G1T1 Drum  (64/2*64) 16   USB1  10  InstPrb. ----   BD   C-1  100  127 SETS INIT
319 tk 942
 
2092 tk 943
  // Trk. Type StepsP/T  Drums Port Chn. Trk.LayA LayB  Drum Note VelN VelA PRE-         
944
  // G1T1 Drum  (2*64/256) 8   USB1  12  InstVel. Len.   SD   D-1  ---  --- SETS INIT
319 tk 945
 
946
 
947
  // Track Type "Drums":
327 tk 948
  //    1 or 2 parameter layers for each trigger layer (drum instrument).
949
  //    If parameters layers consist of more than 1024 steps in total, steps > 1024 will be mirrored
950
  //    assignable to Velocity/Gatelength/Delay/Probability/Roll/Flam only
319 tk 951
  //    (no CC, no Pitch Bender, no Loopback, as they don't work note-wise, but 
952
  //     only channel wise
953
  //     just send them from a different track)
954
 
955
  // Each drum instrument provides 4 constant parameters for:
956
  //   - Note Number
472 tk 957
  //   - MIDI Channel (1-16) for all drum instruments (TODO: optionally allow to use a "local" channel, edit parameter right of VelA)
319 tk 958
  //   - Velocity Normal (if not taken from Parameter Layer)
959
  //   - Velocity Accented (if not taken from Parameter Layer)
960
 
961
 
962
  // Available Layer Constraints (Partitioning for 1024 bytes Par. memory, 2048 bits Trg. memory)
327 tk 963
  //    - 16 Parameter Layers with 64 steps and 2*16 Trigger Layers A-P with 64 steps taken for Gate and Accent
964
  //    - 2*16 Parameter Layer with 32 steps and 16 Trigger Layers A-P with 128 steps taken for Gate
965
  //    - 8 Parameter Layer with 128 steps and 2*8 Trigger Layers A-P with 128 steps taken for Gate and Accent
966
  //    - 2*8 Parameter Layer with 64 steps and 8 Trigger Layers A-P with 256 steps taken for Gate
319 tk 967
 
472 tk 968
 
969
 
766 tk 970
  // Preset dialogs:
971
  // Load Preset File (10 files found)       Trk.      SAVE AS                       
972
  //  xxxxxxxx  xxxxxxxx  xxxxxxxx  xxxxxxxx G1T1     NEW PRESET                 EXIT
973
 
974
  // Import selections:
956 tk 975
  // Importing /PRESETS/xxxxx.V4T to G1T1    Name Chn. Maps Cfg. Steps
766 tk 976
  // Please select track sections:           yes  yes  yes  yes   yes     IMPORT EXIT
977
 
978
  // "Save as new preset"
956 tk 979
  // Please enter Filename:                  /PRESETS/<xxxxxxxx>.V4T                 
766 tk 980
  // .,!1 ABC2 DEF3 GHI4 JKL5 MNO6 PQRS7 TUV8WXYZ9 -_ 0  Char <>  Del Ins   SAVE EXIT
981
 
982
  // File exists
956 tk 983
  //                                         File '/PRESETS/xxx.V4T' already exists     
766 tk 984
  //                                         Overwrite? YES  NO                  EXIT
985
 
986
 
987
 
988
 
174 tk 989
  u8 visible_track = SEQ_UI_VisibleTrackGet();
472 tk 990
 
991
  // if track has changed, switch layer config:
992
  if( visible_track != selected_layer_config_track ) {
993
    selected_layer_config_track = visible_track;
994
    selected_layer_config = GetLayerConfig(selected_layer_config_track);
995
  }
996
 
323 tk 997
  u8 event_mode = layer_config[selected_layer_config].event_mode;
174 tk 998
 
472 tk 999
 
766 tk 1000
  switch( pr_dialog ) {
1001
    ///////////////////////////////////////////////////////////////////////////
1002
    case PR_DIALOG_PRESETS: {
1003
      SEQ_LCD_CursorSet(0, 0);
1004
      SEQ_LCD_PrintSpaces(40);
1005
 
1006
      SEQ_LCD_CursorSet(0, 0);
1007
      if( dir_num_items < 0 ) {
1261 tk 1008
    if( dir_num_items == FILE_ERR_NO_DIR )
956 tk 1009
      SEQ_LCD_PrintString("/PRESETS directory not found on SD Card!");
766 tk 1010
    else
1011
      SEQ_LCD_PrintFormattedString("SD Card Access Error: %d", dir_num_items);
1012
      } else if( dir_num_items == 0 ) {
956 tk 1013
    SEQ_LCD_PrintFormattedString("No files found under /PRESETS!");
752 tk 1014
      } else {
766 tk 1015
    SEQ_LCD_PrintFormattedString("Select Preset File (%d files found)", dir_num_items);
729 tk 1016
      }
1017
 
766 tk 1018
      ///////////////////////////////////////////////////////////////////////////
1019
      SEQ_LCD_CursorSet(40, 0);
1020
      SEQ_LCD_PrintString("Trk.      SAVE AS");
1021
      SEQ_LCD_PrintSpaces(40-23);
752 tk 1022
 
766 tk 1023
      ///////////////////////////////////////////////////////////////////////////
1024
      SEQ_LCD_CursorSet(0, 1);
752 tk 1025
 
766 tk 1026
      SEQ_LCD_PrintList((char *)ui_global_dir_list, LIST_ENTRY_WIDTH, dir_num_items, NUM_LIST_DISPLAYED_ITEMS, ui_selected_item, dir_view_offset);
752 tk 1027
 
766 tk 1028
      SEQ_LCD_PrintGxTy(ui_selected_group, ui_selected_tracks);
1029
      SEQ_LCD_PrintString("     NEW PRESET                 EXIT");
1030
    } break;
752 tk 1031
 
1032
 
766 tk 1033
    case PR_DIALOG_IMPORT: {
1034
      ///////////////////////////////////////////////////////////////////////////
1035
      SEQ_LCD_CursorSet(0, 0);
956 tk 1036
      SEQ_LCD_PrintFormattedString("Importing /PRESETS/%s.V4T to ", dir_name);
766 tk 1037
      SEQ_LCD_PrintGxTy(ui_selected_group, ui_selected_tracks);
1038
      SEQ_LCD_PrintSpaces(10);
752 tk 1039
 
766 tk 1040
      SEQ_LCD_CursorSet(40, 0);
1041
      SEQ_LCD_PrintString("Name Chn. Maps Cfg. Steps");
1042
      SEQ_LCD_PrintSpaces(15);
752 tk 1043
 
766 tk 1044
      SEQ_LCD_CursorSet(0, 1);
1045
      SEQ_LCD_PrintFormattedString("Please select track sections:");
1046
      SEQ_LCD_PrintSpaces(11);
174 tk 1047
 
766 tk 1048
      if( ui_selected_item == IMPORT_ITEM_NAME && ui_cursor_flash ) {
1049
    SEQ_LCD_PrintSpaces(3);
1050
      } else {
1051
    SEQ_LCD_PrintString(import_flags.NAME ? "yes" : " no");
1052
      }
1053
      SEQ_LCD_PrintSpaces(2);
174 tk 1054
 
766 tk 1055
      if( ui_selected_item == IMPORT_ITEM_CHN && ui_cursor_flash ) {
1056
    SEQ_LCD_PrintSpaces(3);
1057
      } else {
1058
    SEQ_LCD_PrintString(import_flags.CHN ? "yes" : " no");
1059
      }
1060
      SEQ_LCD_PrintSpaces(2);
174 tk 1061
 
766 tk 1062
      if( ui_selected_item == IMPORT_ITEM_MAPS && ui_cursor_flash ) {
1063
    SEQ_LCD_PrintSpaces(3);
1064
      } else {
1065
    SEQ_LCD_PrintString(import_flags.MAPS ? "yes" : " no");
1066
      }
1067
      SEQ_LCD_PrintSpaces(2);
174 tk 1068
 
766 tk 1069
      if( ui_selected_item == IMPORT_ITEM_CFG && ui_cursor_flash ) {
1070
    SEQ_LCD_PrintSpaces(3);
1071
      } else {
1072
    SEQ_LCD_PrintString(import_flags.CFG ? "yes" : " no");
1073
      }
1074
      SEQ_LCD_PrintSpaces(2);
174 tk 1075
 
766 tk 1076
      if( ui_selected_item == IMPORT_ITEM_STEPS && ui_cursor_flash ) {
1077
    SEQ_LCD_PrintSpaces(3);
1078
      } else {
1079
    SEQ_LCD_PrintString(import_flags.STEPS ? "yes" : " no");
1080
      }
327 tk 1081
 
766 tk 1082
      SEQ_LCD_PrintSpaces(6);
327 tk 1083
 
766 tk 1084
      SEQ_LCD_PrintString("IMPORT EXIT");
1085
    } break;
327 tk 1086
 
174 tk 1087
 
766 tk 1088
    case PR_DIALOG_EXPORT_FNAME: {
1089
      int i;
174 tk 1090
 
766 tk 1091
      SEQ_LCD_CursorSet(0, 0);
1092
      SEQ_LCD_PrintString("Please enter Filename:");
1093
      SEQ_LCD_PrintSpaces(18);
174 tk 1094
 
956 tk 1095
      SEQ_LCD_PrintString("/PRESETS/<");
766 tk 1096
      for(i=0; i<8; ++i)
1097
    SEQ_LCD_PrintChar(dir_name[i]);
1098
      SEQ_LCD_PrintString(">.V4T");
1099
      SEQ_LCD_PrintSpaces(20);
472 tk 1100
 
766 tk 1101
      // insert flashing cursor
1102
      if( ui_cursor_flash ) {
1103
    SEQ_LCD_CursorSet(50 + ui_edit_name_cursor, 0);
1104
    SEQ_LCD_PrintChar('*');
1105
      }
472 tk 1106
 
766 tk 1107
      SEQ_UI_KeyPad_LCD_Msg();
1108
      SEQ_LCD_PrintString("  SAVE EXIT");
1109
    } break;
174 tk 1110
 
1111
 
766 tk 1112
    case PR_DIALOG_EXPORT_FEXISTS: {
1113
      SEQ_LCD_CursorSet(0, 0);
1114
      SEQ_LCD_PrintSpaces(40);
1115
 
956 tk 1116
      SEQ_LCD_PrintFormattedString("File '/PRESETS/%s.V4T' already exists!", dir_name);
766 tk 1117
      SEQ_LCD_PrintSpaces(10);
1118
 
1119
      SEQ_LCD_CursorSet(0, 1);
1120
      SEQ_LCD_PrintSpaces(40);
1121
 
1122
      SEQ_LCD_PrintString("Overwrite? YES  NO");
1123
      SEQ_LCD_PrintSpaces(18);
1124
      SEQ_LCD_PrintString("EXIT");
1125
    } break;
1126
 
1127
 
1128
 
1129
    ///////////////////////////////////////////////////////////////////////////
1130
    default:
1131
 
1132
      SEQ_LCD_CursorSet(0, 0);
1133
 
1134
      SEQ_LCD_PrintString("Trk. Type ");
1135
      SEQ_LCD_PrintString((event_mode == SEQ_EVENT_MODE_Drum) ? "StepsP/T  Drums " : "Steps/ParL/TrgL ");
1136
      SEQ_LCD_PrintString("Port Chn. ");
1137
 
2092 tk 1138
      if( ui_selected_item == ITEM_TRKINST && ui_cursor_flash ) {
766 tk 1139
    SEQ_LCD_PrintSpaces(4);
472 tk 1140
      } else {
2092 tk 1141
    SEQ_LCD_PrintFormattedString("Trk.");
472 tk 1142
      }
319 tk 1143
 
766 tk 1144
      if( selected_layer_config != GetLayerConfig(visible_track) ) {
1145
    SEQ_LCD_PrintString("    Please initialize the track         ");
1146
      } else if( event_mode == SEQ_EVENT_MODE_Drum ) {
2444 tk 1147
    if( layer_config[selected_layer_config].par_layers > 2 ) {
1148
      SEQ_LCD_PrintString("Layer Asg. ");
1149
    } else {
1150
      SEQ_LCD_PrintString("LayA ");
1151
      SEQ_LCD_PrintString((layer_config[selected_layer_config].par_layers >= 2) ? "LayB " : "     ");
1152
    }
2041 tk 1153
    if( SEQ_CC_TrackHasAccentTrgLayer(visible_track) && !SEQ_CC_TrackHasVelocityParLayer(visible_track) ) {
1154
      SEQ_LCD_PrintString(" Drum Note VelN VelA PRE-    ");
2042 tk 1155
    } else if( SEQ_CC_TrackHasAccentTrgLayer(visible_track) ) {
1156
      SEQ_LCD_PrintString(" Drum Note      VelA PRE-    ");
2041 tk 1157
    } else {
1158
      SEQ_LCD_PrintString(" Drum Note           PRE-    ");
1159
    }
766 tk 1160
      } else {
1161
    SEQ_LCD_PrintString("Layer  controls                         ");
1162
      }
319 tk 1163
 
766 tk 1164
      ///////////////////////////////////////////////////////////////////////////
1165
      SEQ_LCD_CursorSet(0, 1);
319 tk 1166
 
766 tk 1167
      if( ui_selected_item == ITEM_GXTY && ui_cursor_flash ) {
1168
    SEQ_LCD_PrintSpaces(5);
1169
      } else {
1170
    SEQ_LCD_PrintGxTy(ui_selected_group, ui_selected_tracks);
1171
    SEQ_LCD_PrintSpaces(1);
1172
      }
319 tk 1173
 
766 tk 1174
      ///////////////////////////////////////////////////////////////////////////
319 tk 1175
 
766 tk 1176
      if( ui_selected_item == ITEM_EVENT_MODE && ui_cursor_flash ) {
1177
    SEQ_LCD_PrintSpaces(21);
1178
      } else {
1179
    SEQ_LCD_PrintString((char *)SEQ_LAYER_GetEvntModeName(event_mode));
323 tk 1180
 
766 tk 1181
    layer_config_t *lc = (layer_config_t *)&layer_config[selected_layer_config];
1182
    if( event_mode == SEQ_EVENT_MODE_Drum ) {
1183
      SEQ_LCD_PrintChar(' ');
1184
      SEQ_LCD_PrintChar('(');
1185
      SEQ_LCD_PrintSpaces(14); // for easier handling
1186
      SEQ_LCD_CursorSet(12, 1);
1187
 
1188
      if( lc->par_layers > 1 )
1189
        SEQ_LCD_PrintFormattedString("%d*", lc->par_layers);
1190
      SEQ_LCD_PrintFormattedString("%d/", lc->par_steps);
1191
      if( lc->trg_layers > 1 )
1192
        SEQ_LCD_PrintFormattedString("%d*", lc->trg_layers);
1193
      SEQ_LCD_PrintFormattedString("%d", lc->trg_steps);
1194
 
1195
      SEQ_LCD_PrintFormattedString(") %d", lc->instruments);
1196
      SEQ_LCD_CursorSet(26, 1);
1197
    } else {
1198
      SEQ_LCD_PrintFormattedString("  %3d %3d  %3d  ", lc->par_steps, lc->par_layers, lc->trg_layers);
1199
    }
333 tk 1200
      }
174 tk 1201
 
766 tk 1202
      ///////////////////////////////////////////////////////////////////////////
1203
      mios32_midi_port_t port = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_PORT);
1204
      if( ui_selected_item == ITEM_MIDI_PORT && ui_cursor_flash ) {
1205
    SEQ_LCD_PrintSpaces(5);
1206
      } else {
1207
    SEQ_LCD_PrintMIDIOutPort(port);
1208
    SEQ_LCD_PrintChar(SEQ_MIDI_PORT_OutCheckAvailable(port) ? ' ' : '*');
1209
      }
178 tk 1210
 
766 tk 1211
      ///////////////////////////////////////////////////////////////////////////
1212
      if( ui_selected_item == ITEM_MIDI_CHANNEL && ui_cursor_flash ) {
1213
    SEQ_LCD_PrintSpaces(5);
1214
      } else {
1215
    SEQ_LCD_PrintFormattedString("%3d  ", SEQ_CC_Get(visible_track, SEQ_CC_MIDI_CHANNEL)+1);
1216
      }
323 tk 1217
 
766 tk 1218
      ///////////////////////////////////////////////////////////////////////////
2092 tk 1219
      if( ui_selected_item == ITEM_TRKINST && ui_cursor_flash ) {
766 tk 1220
    SEQ_LCD_PrintSpaces(4);
1221
      } else {
2092 tk 1222
    SEQ_LCD_PrintFormattedString("Inst");
766 tk 1223
      }
1224
 
1225
      ///////////////////////////////////////////////////////////////////////////
1226
      if( selected_layer_config != GetLayerConfig(visible_track) ) {
1227
    SEQ_LCD_PrintString(" ---------------------------------> ");
1228
    if( (ui_cursor_flash_overrun_ctr & 1) ) {
1229
      SEQ_LCD_PrintSpaces(4);
1230
    } else {
1231
      SEQ_LCD_PrintString("INIT");
1232
    }
1233
 
1234
        ///////////////////////////////////////////////////////////////////////////
1235
      } else if( event_mode == SEQ_EVENT_MODE_Drum ) {
1236
    /////////////////////////////////////////////////////////////////////////
1237
    if( ui_selected_item == ITEM_LAYER_A_SELECT && ui_cursor_flash ) {
1238
      SEQ_LCD_PrintSpaces(5);
1239
    } else {
2444 tk 1240
      if( layer_config[selected_layer_config].par_layers > 2 ) {
1241
        SEQ_LCD_PrintSpaces(2);
1242
        SEQ_LCD_PrintChar('A' + selected_drum_par_layer);
1243
        SEQ_LCD_PrintSpaces(2);
2389 tk 1244
      } else {
2444 tk 1245
        seq_par_layer_type_t asg = SEQ_PAR_AssignmentGet(visible_track, 0);
2551 tk 1246
#ifdef MBSEQV4P
1247
        SEQ_LCD_PrintString(SEQ_PAR_TypeStr(asg));
1248
#else
2444 tk 1249
        if( asg == SEQ_PAR_Type_CC ) {
2551 tk 1250
          SEQ_LCD_PrintString("NoV4+"); // CC not supported for drum tracks
2444 tk 1251
        } else {
1252
          SEQ_LCD_PrintString(SEQ_PAR_TypeStr(asg));
1253
        }
2551 tk 1254
#endif
2389 tk 1255
      }
766 tk 1256
    }
1257
 
1258
    /////////////////////////////////////////////////////////////////////////
2444 tk 1259
    if( layer_config[selected_layer_config].par_layers > 2 ) {
1260
      if( ui_selected_item == ITEM_LAYER_B_SELECT && ui_cursor_flash ) {
1261
        SEQ_LCD_PrintSpaces(6);
1262
      } else {
1263
        SEQ_LCD_PrintSpaces(1);
1264
 
1265
        seq_par_layer_type_t asg = SEQ_PAR_AssignmentGet(visible_track, selected_drum_par_layer);
2551 tk 1266
#ifdef MBSEQV4P
1267
        SEQ_LCD_PrintString(SEQ_PAR_TypeStr(asg));
1268
#else
2389 tk 1269
        if( asg == SEQ_PAR_Type_CC ) {
2551 tk 1270
          SEQ_LCD_PrintString("NoV4+"); // CC not supported for drum tracks
2389 tk 1271
        } else {
1272
          SEQ_LCD_PrintString(SEQ_PAR_TypeStr(asg));
1273
        }
2551 tk 1274
#endif
2444 tk 1275
      }
1276
    } else {
1277
      if( ui_selected_item == ITEM_LAYER_B_SELECT && ui_cursor_flash ) {
1278
        SEQ_LCD_PrintSpaces(5);
766 tk 1279
      } else {
2444 tk 1280
        if( layer_config[selected_layer_config].par_layers >= 2 ) {
1281
          seq_par_layer_type_t asg = SEQ_PAR_AssignmentGet(visible_track, 1);
2551 tk 1282
#ifdef MBSEQV4P
1283
        SEQ_LCD_PrintString(SEQ_PAR_TypeStr(asg));
1284
#else
2444 tk 1285
          if( asg == SEQ_PAR_Type_CC ) {
2551 tk 1286
        SEQ_LCD_PrintString("NoV4+"); // CC not supported for drum tracks
2444 tk 1287
          } else {
1288
        SEQ_LCD_PrintString(SEQ_PAR_TypeStr(asg));
1289
          }
2551 tk 1290
#endif
2444 tk 1291
        } else {
1292
          if( ui_selected_item == ITEM_LAYER_B_SELECT )
1293
        SEQ_LCD_PrintString(" --- "); // not a bug, but a feature - highlight, that layer not configurable
1294
          else
1295
        SEQ_LCD_PrintSpaces(5);
1296
        }
766 tk 1297
      }
2444 tk 1298
      SEQ_LCD_PrintSpaces(1);
766 tk 1299
    }
1300
 
1301
    /////////////////////////////////////////////////////////////////////////
1302
    if( ui_selected_item == ITEM_DRUM_SELECT && ui_cursor_flash ) {
1303
      SEQ_LCD_PrintSpaces(5);
1304
    } else {
1305
      SEQ_LCD_PrintTrackDrum(visible_track, ui_selected_instrument, (char *)seq_core_trk[visible_track].name);
1306
    }
1307
 
1308
    /////////////////////////////////////////////////////////////////////////
1309
    SEQ_LCD_PrintSpaces(1);
1310
    if( ui_selected_item == ITEM_DRUM_NOTE && ui_cursor_flash ) {
1311
      SEQ_LCD_PrintSpaces(3);
1312
    } else {
1313
      SEQ_LCD_PrintNote(SEQ_CC_Get(visible_track, SEQ_CC_LAY_CONST_A1 + ui_selected_instrument));
1314
    }
1315
    SEQ_LCD_PrintSpaces(1);
1316
 
1317
    /////////////////////////////////////////////////////////////////////////
1318
    if( ui_selected_item == ITEM_DRUM_VEL_N && ui_cursor_flash ) {
1319
      SEQ_LCD_PrintSpaces(5);
1320
    } else {
2041 tk 1321
      if( SEQ_CC_TrackHasAccentTrgLayer(visible_track) && !SEQ_CC_TrackHasVelocityParLayer(visible_track) ) {
1322
        SEQ_LCD_PrintFormattedString(" %3d ", SEQ_CC_Get(visible_track, SEQ_CC_LAY_CONST_B1 + ui_selected_instrument));
1323
      } else {
1324
        SEQ_LCD_PrintString(" --- ");
1325
      }
766 tk 1326
    }
1327
 
1328
    /////////////////////////////////////////////////////////////////////////
1329
    if( ui_selected_item == ITEM_DRUM_VEL_A && ui_cursor_flash ) {
1330
      SEQ_LCD_PrintSpaces(5);
1331
    } else {
2042 tk 1332
      if( SEQ_CC_TrackHasAccentTrgLayer(visible_track) ) {
2041 tk 1333
        SEQ_LCD_PrintFormattedString(" %3d ", SEQ_CC_Get(visible_track, SEQ_CC_LAY_CONST_C1 + ui_selected_instrument));
1334
      } else {
1335
        SEQ_LCD_PrintString(" --- ");
1336
      }
766 tk 1337
    }
1338
 
1339
    SEQ_LCD_PrintString("SETS INIT");
1340
      } else {
1341
    /////////////////////////////////////////////////////////////////////////
1342
    SEQ_LCD_PrintSpaces(2);
1343
    if( ui_selected_item == ITEM_LAYER_SELECT && ui_cursor_flash ) {
1344
      SEQ_LCD_PrintChar(' ');
1345
    } else {
1346
      SEQ_LCD_PrintChar('A' + ui_selected_par_layer);
1347
    }
1635 tk 1348
    SEQ_LCD_PrintSpaces(3);
766 tk 1349
 
1350
    /////////////////////////////////////////////////////////////////////////
1351
    if( ui_selected_item == ITEM_LAYER_CONTROL && ui_cursor_flash ) {
1635 tk 1352
      SEQ_LCD_PrintSpaces(6);
766 tk 1353
    } else {
1635 tk 1354
      u8 current_value = SEQ_CC_Get(visible_track, SEQ_CC_LAY_CONST_A1 + ui_selected_par_layer);
1355
      if( ui_selected_item == ITEM_LAYER_CONTROL && edit_layer_type != current_value ) {
1356
        SEQ_LCD_PrintChar('!');
1357
        SEQ_LCD_PrintString(SEQ_PAR_TypeStr(edit_layer_type));
1358
      } else {
1359
        SEQ_LCD_PrintChar(' ');
2294 tk 1360
        SEQ_LCD_PrintString(SEQ_PAR_TypeStr(SEQ_PAR_AssignmentGet(visible_track, ui_selected_par_layer)));
1635 tk 1361
      }
766 tk 1362
    }
1363
 
1364
    /////////////////////////////////////////////////////////////////////////
1365
    if( ui_selected_item == ITEM_LAYER_PAR && ui_cursor_flash ) {
1366
      SEQ_LCD_PrintSpaces(15);
1367
    } else {
1635 tk 1368
      u8 assignment = SEQ_PAR_AssignmentGet(visible_track, ui_selected_par_layer);
1369
      if( ui_selected_item == ITEM_LAYER_CONTROL )
1370
        assignment = edit_layer_type;
1371
 
1372
      switch( assignment ) {
766 tk 1373
            case SEQ_PAR_Type_CC: {
1374
          mios32_midi_port_t port = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_PORT);
1375
          u8 current_value = SEQ_CC_Get(visible_track, SEQ_CC_LAY_CONST_B1 + ui_selected_par_layer);
1376
          u8 edit_value = ui_selected_item == ITEM_LAYER_PAR ? edit_cc_number : current_value;
1811 tk 1377
 
1378
          if( edit_value >= 0x80 ) {
1379
        SEQ_LCD_PrintFormattedString("off%c(no CC   ) ", (current_value != edit_value) ? '!' : ' ');
1380
          } else {
1381
        SEQ_LCD_PrintFormattedString("%03d%c(%s) ", edit_value,
1382
                         (current_value != edit_value) ? '!' : ' ',
1383
                         SEQ_CC_LABELS_Get(port, edit_value));
1384
          }
766 tk 1385
        } break;
1386
 
1387
            default:
1388
          SEQ_LCD_PrintSpaces(15);
1389
      }
1390
    }
1391
 
1392
    SEQ_LCD_PrintString("PRESETS  INIT");
1393
      }
1394
  }
1395
 
174 tk 1396
  return 0; // no error
1397
}
1398
 
1399
 
1400
/////////////////////////////////////////////////////////////////////////////
2041 tk 1401
// MIDI IN
1402
/////////////////////////////////////////////////////////////////////////////
2047 tk 1403
static s32 MIDI_IN_Handler(mios32_midi_port_t port, mios32_midi_package_t p)
2041 tk 1404
{
1405
  if( midi_learn_mode == MIDI_LEARN_MODE_DRUM_NOTE ) {
2043 tk 1406
    if( p.type == NoteOn && p.velocity > 0 ) {
1407
      SEQ_UI_CC_Set(SEQ_CC_LAY_CONST_A1 + ui_selected_instrument, p.note);
1408
      seq_ui_display_update_req = 1;
1409
    }
2041 tk 1410
  }
1411
 
1412
  return 0;
1413
}
1414
 
1415
 
1416
/////////////////////////////////////////////////////////////////////////////
174 tk 1417
// Initialisation
1418
/////////////////////////////////////////////////////////////////////////////
1419
s32 SEQ_UI_TRKEVNT_Init(u32 mode)
1420
{
1421
  // install callback routines
1422
  SEQ_UI_InstallButtonCallback(Button_Handler);
1423
  SEQ_UI_InstallEncoderCallback(Encoder_Handler);
1424
  SEQ_UI_InstallLEDCallback(LED_Handler);
1425
  SEQ_UI_InstallLCDCallback(LCD_Handler);
2041 tk 1426
  SEQ_UI_InstallMIDIINCallback(MIDI_IN_Handler);
174 tk 1427
 
2041 tk 1428
  // disable MIDI learn mode by default
1429
  midi_learn_mode = MIDI_LEARN_MODE_OFF;
1430
 
766 tk 1431
  // load charset (if this hasn't been done yet)
1432
  SEQ_LCD_InitSpecialChars(SEQ_LCD_CHARSET_Menu);
178 tk 1433
 
472 tk 1434
  selected_layer_config_track = SEQ_UI_VisibleTrackGet();
1435
  selected_layer_config = GetLayerConfig(selected_layer_config_track);
1436
 
2092 tk 1437
  dir_name[0] = 0;
1438
  pr_dialog = 0;
1439
 
472 tk 1440
  // initialize edit label vars (name is modified directly, not via ui_edit_name!)
1441
  ui_edit_name_cursor = 0;
1442
  ui_edit_preset_num_category = 0;
1443
  ui_edit_preset_num_label = 0;
1444
 
766 tk 1445
  import_flags.ALL = 0xff;
1446
 
174 tk 1447
  return 0; // no error
1448
}
176 tk 1449
 
1450
 
1451
/////////////////////////////////////////////////////////////////////////////
323 tk 1452
// Copies preset
176 tk 1453
/////////////////////////////////////////////////////////////////////////////
323 tk 1454
static s32 CopyPreset(u8 track, u8 config)
176 tk 1455
{
323 tk 1456
  // exit if invalid config
1457
  if( config >= (sizeof(layer_config)/sizeof(layer_config_t)) )
1458
    return -1; // invalid config
176 tk 1459
 
328 tk 1460
  layer_config_t *lc = (layer_config_t *)&layer_config[selected_layer_config];
1461
 
323 tk 1462
  // partitionate layers and clear all steps
328 tk 1463
  SEQ_PAR_TrackInit(track, lc->par_steps, lc->par_layers, lc->instruments);
1464
  SEQ_TRG_TrackInit(track, lc->trg_steps, lc->trg_layers, lc->instruments);
176 tk 1465
 
472 tk 1466
#if 0
1467
  // confusing if assignments are not changed under such a condition
336 tk 1468
  u8 init_assignments = lc->event_mode != SEQ_CC_Get(track, SEQ_CC_MIDI_EVENT_MODE);
472 tk 1469
#else
1470
  u8 init_assignments = 1;
1471
#endif
336 tk 1472
 
328 tk 1473
  SEQ_CC_Set(track, SEQ_CC_MIDI_EVENT_MODE, lc->event_mode);
176 tk 1474
 
326 tk 1475
  // BEGIN TMP
328 tk 1476
  if( lc->event_mode == SEQ_EVENT_MODE_Drum ) {
729 tk 1477
    int i;
1478
 
1479
    for(i=0; i<16; ++i)
1480
      SEQ_LABEL_CopyPresetDrum(i, (char *)&seq_core_trk[track].name[5*i]);
326 tk 1481
  } else {
1482
    memset((char *)seq_core_trk[track].name, ' ', 80);
1483
  }
1484
  // END TMP
1485
 
324 tk 1486
  u8 only_layers = 0;
1487
  u8 all_triggers_cleared = 0;
335 tk 1488
  return SEQ_LAYER_CopyPreset(track, only_layers, all_triggers_cleared, init_assignments);
323 tk 1489
}
176 tk 1490
 
1491
 
323 tk 1492
/////////////////////////////////////////////////////////////////////////////
1493
// Determines current layer config
1494
/////////////////////////////////////////////////////////////////////////////
1495
static s32 GetLayerConfig(u8 track)
1496
{
1497
  int i;
1498
 
1499
  u8 event_mode = SEQ_CC_Get(track, SEQ_CC_MIDI_EVENT_MODE);
1500
  u8 par_layers = SEQ_PAR_NumLayersGet(track);
1501
  u16 par_steps = SEQ_PAR_NumStepsGet(track);
1502
  u8 trg_layers = SEQ_TRG_NumLayersGet(track);
1503
  u16 trg_steps = SEQ_TRG_NumStepsGet(track);
328 tk 1504
  u8 num_instruments = SEQ_PAR_NumInstrumentsGet(track);
323 tk 1505
 
1506
  for(i=0; i<(sizeof(layer_config)/sizeof(layer_config_t)); ++i) {
1507
    layer_config_t *lc = (layer_config_t *)&layer_config[i];
1508
    if( lc->event_mode == event_mode &&
1509
    lc->par_layers == par_layers && lc->par_steps == par_steps &&
325 tk 1510
    lc->trg_layers == trg_layers && lc->trg_steps == trg_steps &&
328 tk 1511
    lc->instruments == num_instruments ) {
323 tk 1512
      return i;
176 tk 1513
    }
1514
  }
1515
 
323 tk 1516
  return 0; // not found, return index to first config
176 tk 1517
}
178 tk 1518
 
756 tk 1519
/////////////////////////////////////////////////////////////////////////////
1520
// help function for Init button function
1521
/////////////////////////////////////////////////////////////////////////////
1522
static void InitReq(u32 dummy)
1523
{
1524
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1525
 
1526
  // TODO: copy preset for all selected tracks!
1527
  CopyPreset(visible_track, selected_layer_config);
1528
 
1529
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "Track has been", "initialized!");
1530
}
766 tk 1531
 
1532
 
1533
/////////////////////////////////////////////////////////////////////////////
1534
// help function to scan presets directory
1535
/////////////////////////////////////////////////////////////////////////////
1536
static s32 SEQ_UI_TRKEVNT_UpdateDirList(void)
1537
{
1538
  int item;
1539
 
1540
  MUTEX_SDCARD_TAKE;
1261 tk 1541
  dir_num_items = FILE_GetFiles("/PRESETS", "V4T", (char *)&ui_global_dir_list[0], NUM_LIST_DISPLAYED_ITEMS, dir_view_offset);
766 tk 1542
  MUTEX_SDCARD_GIVE;
1543
 
1544
  if( dir_num_items < 0 )
1545
    item = 0;
1546
  else if( dir_num_items < NUM_LIST_DISPLAYED_ITEMS )
1547
    item = dir_num_items;
1548
  else
1549
    item = NUM_LIST_DISPLAYED_ITEMS;
1550
 
1551
  while( item < NUM_LIST_DISPLAYED_ITEMS ) {
1552
    ui_global_dir_list[LIST_ENTRY_WIDTH*item] = 0;
1553
    ++item;
1554
  }
1555
 
1556
  return 0; // no error
1557
}
1558
 
1559
 
1560
/////////////////////////////////////////////////////////////////////////////
1561
// help function to start Track preset file export
1562
// returns 0 on success
1563
// returns != 0 on errors (dialog page will be changed accordingly)
1564
/////////////////////////////////////////////////////////////////////////////
1565
static s32 DoExport(u8 force_overwrite)
1566
{
1567
  s32 status;
1568
  int i;
1023 tk 1569
  char path[30];
766 tk 1570
 
1571
  // if an error is detected, we jump back to FNAME page
1572
  ui_selected_item = 0;
1573
  pr_dialog = PR_DIALOG_EXPORT_FNAME;
1574
 
1575
  u8 filename_valid = 1;
1576
  for(i=0; i<8; ++i)
1577
    if( dir_name[i] == '.' || dir_name[i] == '?' || dir_name[i] == ',' || dir_name[i] == '!' )
1578
      filename_valid = 0;
1579
 
1580
  if( !filename_valid ) {
1581
    SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 2000, "Filename not valid!", "(remove . ? , !)");
1582
    return -1;
1583
  }
1584
 
1585
  if( dir_name[0] == ' ') {
1586
    SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 2000, "Please enter", "Filename!");
1587
    return -2;
1588
  }
1589
 
956 tk 1590
  strcpy(path, "/PRESETS");
766 tk 1591
  MUTEX_SDCARD_TAKE;
1261 tk 1592
  status = FILE_MakeDir(path); // create directory if it doesn't exist
1593
  status = FILE_DirExists(path);
766 tk 1594
  MUTEX_SDCARD_GIVE;
1595
 
1596
  if( status < 0 ) {
1597
    SEQ_UI_SDCardErrMsg(2000, status);
1598
    return -3;
1599
  }
1600
 
1601
  if( status == 0 ) {
959 tk 1602
    SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 2000, "/PRESETS directory", "cannot be created!");
766 tk 1603
    return -4;
1604
  }
1605
 
1023 tk 1606
  char v4t_file[30];
956 tk 1607
  char *p = (char *)&v4t_file[0];
1608
  for(i=0; i<8; ++i) {
1609
    char c = dir_name[i];
1610
    if( c != ' ' )
1611
      *p++ = c;
1612
  }
1613
  *p++ = 0;
766 tk 1614
 
956 tk 1615
  sprintf(path, "/PRESETS/%s.v4t", v4t_file);
1616
 
766 tk 1617
  MUTEX_SDCARD_TAKE;
1261 tk 1618
  status = FILE_FileExists(path);
766 tk 1619
  MUTEX_SDCARD_GIVE;
1620
 
1621
  if( status < 0 ) {
1622
    SEQ_UI_SDCardErrMsg(2000, status);
1623
    return -5;
1624
  }
1625
 
1626
 
1627
  if( !force_overwrite && status == 1) {
1628
    // file exists - ask if it should be overwritten in a special dialog page
1629
    pr_dialog = PR_DIALOG_EXPORT_FEXISTS;
1630
    return 1;
1631
  }
1632
 
1633
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 2000, "Exporting", path);
1634
 
769 tk 1635
  MUTEX_SDCARD_TAKE;
1636
  status=SEQ_FILE_T_Write(path, SEQ_UI_VisibleTrackGet());
1637
  MUTEX_SDCARD_GIVE;
1638
 
1639
  if( status < 0 ) {
766 tk 1640
    SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 2000, "Error during Export!", "see MIOS Terminal!");
1641
    return -6;
1642
  }
1643
 
1644
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 2000, "Export", "successfull!");
1645
 
1646
  return 0; // no error
1647
}
1648
 
1649
 
1650
/////////////////////////////////////////////////////////////////////////////
1651
// help function to start Track preset file export
1652
// returns 0 on success
1653
// returns != 0 on errors (dialog page will be changed accordingly)
1654
/////////////////////////////////////////////////////////////////////////////
1655
static s32 DoImport(void)
1656
{
1657
  s32 status;
1023 tk 1658
  char path[30];
766 tk 1659
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1660
 
956 tk 1661
  sprintf(path, "/PRESETS/%s.V4T", dir_name);
766 tk 1662
 
769 tk 1663
  // mute track to avoid random effects while loading the file
1664
  MIOS32_IRQ_Disable(); // this operation should be atomic!
1015 tk 1665
  u8 muted = seq_core_trk_muted & (1 << visible_track);
769 tk 1666
  if( !muted )
1015 tk 1667
    seq_core_trk_muted |= (1 << visible_track);
769 tk 1668
  MIOS32_IRQ_Enable();
1669
 
1670
  // read file
766 tk 1671
  MUTEX_SDCARD_TAKE;
2524 tk 1672
  status = SEQ_FILE_T_Read(path, visible_track, import_flags, 0);
766 tk 1673
  MUTEX_SDCARD_GIVE;
1674
 
769 tk 1675
  // unmute track if it wasn't muted before
1676
  MIOS32_IRQ_Disable(); // this operation should be atomic!
1677
  if( !muted )
1015 tk 1678
    seq_core_trk_muted &= ~(1 << visible_track);
769 tk 1679
  MIOS32_IRQ_Enable();
1680
 
766 tk 1681
  if( status < 0 ) {
1682
    SEQ_UI_SDCardErrMsg(2000, status);
1683
  } else {
1684
    SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 2000, path, "imported!");
1685
 
1686
    // fix layer config
1687
    selected_layer_config_track = visible_track;
1688
    selected_layer_config = GetLayerConfig(selected_layer_config_track);
1689
  }
1690
 
1691
  return 0; // no error
1692
}