Subversion Repositories svn.mios32

Rev

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