Subversion Repositories svn.mios32

Rev

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