Subversion Repositories svn.mios32

Rev

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