Subversion Repositories svn.mios32

Rev

Rev 959 | Rev 987 | 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 984 2010-04-01 22:32:42Z 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
      int i;
472 tk 446
 
766 tk 447
      // SAVE only via button
448
      if( incrementer != 0 )
449
        return 0;
472 tk 450
 
766 tk 451
      if( DoExport(0) == 0 ) { // don't force overwrite
452
        // exit keypad editor
453
        ui_selected_item = 0;
454
        pr_dialog = PR_DIALOG_NONE;
455
      }
174 tk 456
 
766 tk 457
      return 1;
458
    } break;
472 tk 459
 
766 tk 460
        case SEQ_UI_ENCODER_GP16: {
461
      // EXIT only via button
462
      if( incrementer == 0 ) {
463
        ui_selected_item = 0;
464
        pr_dialog = PR_DIALOG_NONE;
465
      }
466
      return 1;
467
    } break;
285 tk 468
      }
472 tk 469
 
766 tk 470
      return SEQ_UI_KeyPad_Handler(encoder, incrementer, (char *)&dir_name[0], 8);
471
    }
472 tk 472
 
174 tk 473
 
766 tk 474
    ///////////////////////////////////////////////////////////////////////////
475
    case PR_DIALOG_EXPORT_FEXISTS: {
476
      switch( encoder ) {
477
        case SEQ_UI_ENCODER_GP11: {
478
      // YES only via button
479
      if( incrementer != 0 )
480
        return 0;
481
 
482
      // YES: overwrite file
483
      if( DoExport(1) == 0 ) { // force overwrite
484
        // exit keypad editor
485
        ui_selected_item = 0;
486
        pr_dialog = PR_DIALOG_NONE;
487
      }
335 tk 488
      return 1;
766 tk 489
    } break;
490
 
491
        case SEQ_UI_ENCODER_GP12: {
492
      // NO only via button
493
      if( incrementer != 0 )
494
        return 0;
495
 
496
      // NO: don't overwrite file - back to filename entry
497
 
498
      ui_selected_item = 0;
499
      pr_dialog = PR_DIALOG_EXPORT_FNAME;
335 tk 500
      return 1;
766 tk 501
    } break;
502
 
503
        case SEQ_UI_ENCODER_GP16: {
504
      // EXIT only via button
505
      if( incrementer == 0 ) {
506
        ui_selected_item = 0;
507
        pr_dialog = PR_DIALOG_NONE;
508
      }
509
      return 1;
510
    } break;
511
      }
512
 
513
      return -1; // not mapped
514
    }
515
 
516
 
517
    ///////////////////////////////////////////////////////////////////////////
518
    default:
519
 
520
      if( encoder >= SEQ_UI_ENCODER_GP9 && encoder <= SEQ_UI_ENCODER_GP16 ) {
521
    if( selected_layer_config != GetLayerConfig(visible_track) ) {
522
      // ENC function disabled so long pattern hasn't been initialized
523
      return -1;
335 tk 524
    }
766 tk 525
 
752 tk 526
    if( event_mode == SEQ_EVENT_MODE_Drum ) {
766 tk 527
      switch( encoder ) {
528
        case SEQ_UI_ENCODER_GP9:
529
          ui_selected_item = ITEM_LAYER_A_SELECT;
530
          break;
531
 
532
        case SEQ_UI_ENCODER_GP10:
533
          ui_selected_item = ITEM_LAYER_B_SELECT;
534
          break;
535
 
536
        case SEQ_UI_ENCODER_GP11:
537
          ui_selected_item = ITEM_DRUM_SELECT;
538
          break;
539
 
540
        case SEQ_UI_ENCODER_GP12:
541
          ui_selected_item = ITEM_DRUM_NOTE;
542
          break;
543
 
544
        case SEQ_UI_ENCODER_GP13:
545
          ui_selected_item = ITEM_DRUM_VEL_N;
546
          break;
547
 
548
        case SEQ_UI_ENCODER_GP14:
549
          ui_selected_item = ITEM_DRUM_VEL_A;
550
          break;
551
 
552
        case SEQ_UI_ENCODER_GP15:
553
          // change to preset page (only via button)
554
          if( incrementer == 0 ) {
555
        ui_selected_item = 0;
556
        pr_dialog = PR_DIALOG_PRESETS;
557
        SEQ_UI_TRKEVNT_UpdateDirList();
558
          }
559
          return 1;
560
 
561
        case SEQ_UI_ENCODER_GP16:
562
          return -1; // EXIT not mapped to encoder
563
      }
752 tk 564
    } else {
766 tk 565
      switch( encoder ) {
566
        case SEQ_UI_ENCODER_GP9:
567
          ui_selected_item = ITEM_LAYER_SELECT;
568
          break;
569
 
570
        case SEQ_UI_ENCODER_GP10:
571
          ui_selected_item = ITEM_LAYER_CONTROL;
572
          break;
573
 
574
        case SEQ_UI_ENCODER_GP11:
575
        case SEQ_UI_ENCODER_GP12:
576
        case SEQ_UI_ENCODER_GP13:
577
          // CC number selection now has to be confirmed with GP button
578
          if( ui_selected_item != ITEM_LAYER_PAR ) {
579
        edit_cc_number = SEQ_CC_Get(visible_track, SEQ_CC_LAY_CONST_B1 + ui_selected_par_layer);
580
        ui_selected_item = ITEM_LAYER_PAR;
581
        SEQ_UI_Msg(SEQ_UI_MSG_USER, 2000, "Please confirm CC", "with GP button!");
582
          } else if( incrementer == 0 ) {
583
        if( edit_cc_number != SEQ_CC_Get(visible_track, SEQ_CC_LAY_CONST_B1 + ui_selected_par_layer) ) {
584
          SEQ_CC_Set(visible_track, SEQ_CC_LAY_CONST_B1 + ui_selected_par_layer, edit_cc_number);
585
          SEQ_UI_Msg(SEQ_UI_MSG_USER, 2000, "CC number", "has been changed.");
586
        }
587
          }
588
          break;
589
 
590
        case SEQ_UI_ENCODER_GP14:
591
        case SEQ_UI_ENCODER_GP15:
592
          // change to preset page (only via button)
593
          if( incrementer == 0 ) {
594
        ui_selected_item = 0;
595
        pr_dialog = PR_DIALOG_PRESETS;
596
        SEQ_UI_TRKEVNT_UpdateDirList();
597
          }
598
          return 1;
599
 
600
        case SEQ_UI_ENCODER_GP16:
601
          return -1; // not mapped to encoder
602
      }
752 tk 603
    }
766 tk 604
      }
752 tk 605
 
766 tk 606
      switch( encoder ) {
607
        case SEQ_UI_ENCODER_GP1:
608
      ui_selected_item = ITEM_GXTY;
609
      break;
610
 
611
        case SEQ_UI_ENCODER_GP2:
612
        case SEQ_UI_ENCODER_GP3:
613
        case SEQ_UI_ENCODER_GP4:
614
        case SEQ_UI_ENCODER_GP5:
615
      ui_selected_item = ITEM_EVENT_MODE;
616
      break;
617
 
618
        case SEQ_UI_ENCODER_GP6:
619
      ui_selected_item = ITEM_MIDI_PORT;
620
      break;
621
 
622
        case SEQ_UI_ENCODER_GP7:
623
      ui_selected_item = ITEM_MIDI_CHANNEL;
624
      break;
625
 
626
        case SEQ_UI_ENCODER_GP8:
627
      ui_selected_item = ITEM_EDIT_NAME;
628
      break;
629
      }
630
 
631
      // for GP encoders and Datawheel
632
      switch( ui_selected_item ) {
633
        case ITEM_GXTY: return SEQ_UI_GxTyInc(incrementer);
634
        case ITEM_EVENT_MODE: {
635
      u8 max_layer_config = (sizeof(layer_config)/sizeof(layer_config_t)) - 1;
636
      return SEQ_UI_Var8_Inc(&selected_layer_config, 0, max_layer_config, incrementer);
637
    } break;
638
 
639
        case ITEM_MIDI_PORT: {
640
      mios32_midi_port_t port = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_PORT);
641
      u8 port_ix = SEQ_MIDI_PORT_OutIxGet(port);
642
      if( SEQ_UI_Var8_Inc(&port_ix, 0, SEQ_MIDI_PORT_OutNumGet()-1, incrementer) ) {
643
        mios32_midi_port_t new_port = SEQ_MIDI_PORT_OutPortGet(port_ix);
644
        SEQ_UI_CC_Set(SEQ_CC_MIDI_PORT, new_port);
645
        return 1; // value changed
646
      }
647
      return 0; // value not changed
648
    } break;
649
 
650
        case ITEM_MIDI_CHANNEL: return SEQ_UI_CC_Inc(SEQ_CC_MIDI_CHANNEL, 0, 15, incrementer);
651
 
652
        case ITEM_EDIT_NAME:
653
      // switch to keypad editor if button has been pressed
654
      if( incrementer == 0 ) {
655
        ui_selected_item = 0;
656
        pr_dialog = PR_DIALOG_EDIT_LABEL;
657
        SEQ_UI_KeyPad_Init();
658
      }
333 tk 659
      return 1;
766 tk 660
      }
661
 
662
      if( event_mode == SEQ_EVENT_MODE_Drum ) {
663
    switch( ui_selected_item ) {
664
    case ITEM_DRUM_SELECT: {
665
      u8 num_drums = layer_config[selected_layer_config].instruments;
666
      return SEQ_UI_Var8_Inc(&ui_selected_instrument, 0, num_drums-1, incrementer);
667
    } break;
668
    case ITEM_LAYER_A_SELECT: {
669
      if( SEQ_UI_CC_Inc(SEQ_CC_PAR_ASG_DRUM_LAYER_A, 0, SEQ_PAR_NUM_TYPES-1, incrementer) ) {
670
        SEQ_LAYER_CopyParLayerPreset(visible_track, 0);
671
        return 1;
672
      }
673
      return 0;
674
    } break;
675
    case ITEM_LAYER_B_SELECT: {
676
      if( SEQ_UI_CC_Inc(SEQ_CC_PAR_ASG_DRUM_LAYER_B, 0, SEQ_PAR_NUM_TYPES-1, incrementer) ) {
677
        SEQ_LAYER_CopyParLayerPreset(visible_track, 1);
678
        return 1;
679
      }
680
      return 0;
681
    } break;
682
    case ITEM_DRUM_NOTE:     return SEQ_UI_CC_Inc(SEQ_CC_LAY_CONST_A1 + ui_selected_instrument, 0, 127, incrementer);
683
    case ITEM_DRUM_VEL_N:    return SEQ_UI_CC_Inc(SEQ_CC_LAY_CONST_B1 + ui_selected_instrument, 0, 127, incrementer);
684
    case ITEM_DRUM_VEL_A:    return SEQ_UI_CC_Inc(SEQ_CC_LAY_CONST_C1 + ui_selected_instrument, 0, 127, incrementer);
333 tk 685
    }
766 tk 686
      } else {
687
    switch( ui_selected_item ) {
688
      case ITEM_LAYER_SELECT:  return SEQ_UI_Var8_Inc(&ui_selected_par_layer, 0, 15, incrementer);
689
      case ITEM_LAYER_PAR:
690
        if( event_mode == SEQ_EVENT_MODE_Drum ) {
691
          return SEQ_UI_CC_Inc(SEQ_CC_LAY_CONST_B1 + ui_selected_par_layer, 0, 127, incrementer);
692
        } else {
693
          // CC number selection now has to be confirmed with GP button
694
          return SEQ_UI_Var8_Inc(&edit_cc_number, 0, 127, incrementer);
695
        }
696
 
697
      case ITEM_LAYER_CONTROL: {
698
        // TODO: has to be done for all selected tracks
699
        if( SEQ_UI_CC_Inc(SEQ_CC_LAY_CONST_A1 + ui_selected_par_layer, 0, SEQ_PAR_NUM_TYPES-1, incrementer) ) {
700
          SEQ_LAYER_CopyParLayerPreset(visible_track, ui_selected_par_layer);
701
          return 1;
702
        }
703
        return 0;
704
      } break;
705
    }
706
      }
319 tk 707
  }
708
 
174 tk 709
  return -1; // invalid or unsupported encoder
710
}
711
 
712
 
713
/////////////////////////////////////////////////////////////////////////////
714
// Local button callback function
715
// Should return:
716
//   1 if value has been changed
717
//   0 if value hasn't been changed
718
//  -1 if invalid or unsupported button
719
/////////////////////////////////////////////////////////////////////////////
720
static s32 Button_Handler(seq_ui_button_t button, s32 depressed)
721
{
752 tk 722
  u8 event_mode = layer_config[selected_layer_config].event_mode;
472 tk 723
  u8 visible_track = SEQ_UI_VisibleTrackGet();
323 tk 724
 
766 tk 725
  switch( pr_dialog ) {
726
    ///////////////////////////////////////////////////////////////////////////
727
    case PR_DIALOG_EDIT_LABEL:
728
      if( depressed ) return 0; // ignore when button depressed
472 tk 729
 
766 tk 730
      if( button <= SEQ_UI_BUTTON_GP16 )
731
    return Encoder_Handler(button, 0); // re-use encoder handler
752 tk 732
 
766 tk 733
      return -1; // button not mapped
734
 
735
 
736
    case PR_DIALOG_PRESETS:
737
      if( depressed ) return 0; // ignore when button depressed
738
 
739
      if( button >= SEQ_UI_BUTTON_GP9 && button <= SEQ_UI_BUTTON_GP16 )
740
    return Encoder_Handler(button, 0); // re-use encoder handler
741
 
742
      if( button <= SEQ_UI_BUTTON_GP8 || button == SEQ_UI_BUTTON_Select ) {
743
    if( button != SEQ_UI_BUTTON_Select )
744
      ui_selected_item = button / 2;
745
 
746
    if( dir_num_items >= 1 && (ui_selected_item+dir_view_offset) < dir_num_items ) {
747
      // get filename
956 tk 748
      int i;
749
      char *p = (char *)&dir_name[0];
750
      for(i=0; i<8; ++i) {
751
        char c = ui_global_dir_list[LIST_ENTRY_WIDTH*ui_selected_item + i];
752
        if( c != ' ' )
753
          *p++ = c;
754
      }
755
      *p++ = 0;
766 tk 756
      // switch to import page
319 tk 757
      ui_selected_item = 0;
766 tk 758
      pr_dialog = PR_DIALOG_IMPORT;
759
    }
319 tk 760
      }
766 tk 761
      return 1;
319 tk 762
 
174 tk 763
 
766 tk 764
    ///////////////////////////////////////////////////////////////////////////
765
    case PR_DIALOG_IMPORT:
766
      if( depressed ) return 0; // ignore when button depressed
767
 
768
      if( button <= SEQ_UI_BUTTON_GP16 )
769
    return Encoder_Handler(button, 0); // re-use encoder handler
770
 
771
      switch( button ) {
772
        case SEQ_UI_BUTTON_Select:
773
        case SEQ_UI_BUTTON_Right:
774
          if( ++ui_selected_item >= IMPORT_NUM_OF_ITEMS )
775
        ui_selected_item = 0;
776
 
777
          return 1; // value always changed
778
 
779
        case SEQ_UI_BUTTON_Left:
780
          if( ui_selected_item == 0 )
781
        ui_selected_item = IMPORT_NUM_OF_ITEMS-1;
782
 
783
          return 1; // value always changed
784
 
785
        case SEQ_UI_BUTTON_Up:
786
          return Encoder_Handler(SEQ_UI_ENCODER_Datawheel, 1);
787
 
788
        case SEQ_UI_BUTTON_Down:
789
          return Encoder_Handler(SEQ_UI_ENCODER_Datawheel, -1);
319 tk 790
      }
174 tk 791
 
766 tk 792
      return -1; // invalid or unsupported button
174 tk 793
 
766 tk 794
 
795
    ///////////////////////////////////////////////////////////////////////////
796
    case PR_DIALOG_EXPORT_FNAME:
797
    case PR_DIALOG_EXPORT_FEXISTS: {
798
      if( depressed ) return 0; // ignore when button depressed
799
 
800
      return Encoder_Handler((seq_ui_encoder_t)button, 0);
801
    }
802
 
803
 
804
    ///////////////////////////////////////////////////////////////////////////
805
    default:
806
      if( button == SEQ_UI_BUTTON_GP16 ) {
807
    if( depressed )
808
      SEQ_UI_UnInstallDelayedActionCallback(InitReq);
809
    else {
810
      SEQ_UI_InstallDelayedActionCallback(InitReq, 2000, 0);
811
      SEQ_UI_Msg(SEQ_UI_MSG_DELAYED_ACTION_R, 2001, "", "to initialize Track!");
812
    }
813
    return 1; // value has been changed
814
      }
815
 
816
      if( depressed ) return 0; // ignore when button depressed
817
 
818
      if( button <= SEQ_UI_BUTTON_GP15 )
819
    return Encoder_Handler((seq_ui_encoder_t)button, 0);
820
 
821
      switch( button ) {
822
        case SEQ_UI_BUTTON_Select:
823
        case SEQ_UI_BUTTON_Right:
824
      if( event_mode == SEQ_EVENT_MODE_Drum ) {
825
        if( ++ui_selected_item >= NUM_OF_ITEMS_DRUM )
826
          ui_selected_item = 0;
827
      } else {
828
        if( ++ui_selected_item >= NUM_OF_ITEMS_NORMAL )
829
          ui_selected_item = 0;
830
      }
831
 
832
      return 1; // value always changed
833
 
834
        case SEQ_UI_BUTTON_Left:
835
      if( event_mode == SEQ_EVENT_MODE_Drum ) {
836
        if( ui_selected_item == 0 )
837
          ui_selected_item = NUM_OF_ITEMS_DRUM-1;
838
      } else {
839
        if( ui_selected_item == 0 )
840
          ui_selected_item = NUM_OF_ITEMS_NORMAL-1;
841
      }
842
      return 1; // value always changed
843
 
844
        case SEQ_UI_BUTTON_Up:
845
      return Encoder_Handler(SEQ_UI_ENCODER_Datawheel, 1);
846
 
847
        case SEQ_UI_BUTTON_Down:
848
      return Encoder_Handler(SEQ_UI_ENCODER_Datawheel, -1);
849
      }
174 tk 850
  }
851
 
852
  return -1; // invalid or unsupported button
853
}
854
 
855
 
856
/////////////////////////////////////////////////////////////////////////////
857
// Local Display Handler function
858
// IN: <high_prio>: if set, a high-priority LCD update is requested
859
/////////////////////////////////////////////////////////////////////////////
860
static s32 LCD_Handler(u8 high_prio)
861
{
862
  if( high_prio )
863
    return 0; // there are no high-priority updates
864
 
865
  // layout:
866
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
867
  // 01234567890123456789012345678901234567890123456789012345678901234567890123456789
868
  // <--------------------------------------><-------------------------------------->
472 tk 869
  // Trk. Type Steps/ParL/TrgL Port Chn. EditLayer  controls                         
766 tk 870
  // G1T1 Note  256   4     8  IIC2  12  Name  D    Prob                PRESETS  INIT
174 tk 871
 
472 tk 872
  // Trk. Type Steps/ParL/TrgL Port Chn. EditLayer  controls                         
766 tk 873
  // G1T1 Note  256   4     8  IIC2  12  Name  D    CC #001 (ModWheel)  PRESETS  INIT
319 tk 874
 
875
  // Track Type "Note", Chord" and "CC":
876
  // Note: Parameter Layer A/B/C statically assigned to Note Number/Velocity/Length
877
  //       Parameter Layer D..P can be mapped to
878
  //       - additional Notes (e.g. for poly recording)
879
  //       - Base note (directly forwarded to Transposer, e.g. for Force-to-Scale or Chords)
880
  //       - CC (Number 000..127 assignable, GM controller name will be displayed)
881
  //       - Pitch Bender
882
  //       - Loopback (Number 000..127 assignable, name will be displayed)
338 tk 883
  //       - Delay (0..95 ticks @384 ppqn)
319 tk 884
  //       - Probability (100%..0%)
327 tk 885
  //       - "Roll/Flam Effect" (a selection of up to 128 different effects selectable for each step separately)
319 tk 886
  // Chord: same like Note, but predefined Chords will be played
887
  // CC: Layer A/B/C play CCs (or other parameters) as well - no note number, no velocity, no length
888
 
889
  // Available Layer Constraints (Partitioning for 1024 bytes Par. memory, 2048 bits Trg. memory)
890
  //    - 256 Steps with  4 Parameter Layers A-D and 8 Trigger Layers A-H
891
  //    - 128 Steps with  8 Parameter Layers A-H and 8 Trigger Layers A-H
892
  //    -  64 Steps with 16 Parameter Layers A-P and 8 Trigger Layers A-H
893
 
894
 
895
  // layout:
896
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
897
  // 01234567890123456789012345678901234567890123456789012345678901234567890123456789
898
  // <--------------------------------------><-------------------------------------->
766 tk 899
  // Trk. Type StepsP/T  Drums Port Chn. EditLayA LayB  Drum Note VelN VelA PRE-    
900
  // G1T1 Drum  (64/2*64) 16   USB1  10  NamePrb. ----   BD   C-1  100  127 SETS INIT
319 tk 901
 
766 tk 902
  // Trk. Type StepsP/T  Drums Port Chn. EditLayA LayB  Drum Note VelN VelA PRE-         
903
  // G1T1 Drum  (2*64/256) 8   USB1  12  NameVel. Len.   SD   D-1  ---  --- SETS INIT
319 tk 904
 
905
 
906
  // Track Type "Drums":
327 tk 907
  //    1 or 2 parameter layers for each trigger layer (drum instrument).
908
  //    If parameters layers consist of more than 1024 steps in total, steps > 1024 will be mirrored
909
  //    assignable to Velocity/Gatelength/Delay/Probability/Roll/Flam only
319 tk 910
  //    (no CC, no Pitch Bender, no Loopback, as they don't work note-wise, but 
911
  //     only channel wise
912
  //     just send them from a different track)
913
 
914
  // Each drum instrument provides 4 constant parameters for:
915
  //   - Note Number
472 tk 916
  //   - MIDI Channel (1-16) for all drum instruments (TODO: optionally allow to use a "local" channel, edit parameter right of VelA)
319 tk 917
  //   - Velocity Normal (if not taken from Parameter Layer)
918
  //   - Velocity Accented (if not taken from Parameter Layer)
919
 
920
 
921
  // Available Layer Constraints (Partitioning for 1024 bytes Par. memory, 2048 bits Trg. memory)
327 tk 922
  //    - 16 Parameter Layers with 64 steps and 2*16 Trigger Layers A-P with 64 steps taken for Gate and Accent
923
  //    - 2*16 Parameter Layer with 32 steps and 16 Trigger Layers A-P with 128 steps taken for Gate
924
  //    - 8 Parameter Layer with 128 steps and 2*8 Trigger Layers A-P with 128 steps taken for Gate and Accent
925
  //    - 2*8 Parameter Layer with 64 steps and 8 Trigger Layers A-P with 256 steps taken for Gate
319 tk 926
 
472 tk 927
 
928
 
929
  // "Edit Name" layout:
930
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
931
  // 01234567890123456789012345678901234567890123456789012345678901234567890123456789
932
  // <--------------------------------------><-------------------------------------->
752 tk 933
  // Please enter Track Category for G1T1    <xxxxx-xxxxxxxxxxxxxxx>                 
759 tk 934
  // .,!1 ABC2 DEF3 GHI4 JKL5 MNO6 PQRS7 TUV8WXYZ9 -_ 0  Char <>  Del Ins Preset DONE
472 tk 935
 
729 tk 936
  // "Edit Drum Name" layout:
937
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
938
  // 01234567890123456789012345678901234567890123456789012345678901234567890123456789
939
  // <--------------------------------------><-------------------------------------->
752 tk 940
  // Please enter Drum Label for G1T1- 1:C-1 <xxxxx>                                 
759 tk 941
  // .,!1 ABC2 DEF3 GHI4 JKL5 MNO6 PQRS7 TUV8WXYZ9 -_ 0  Char <>  Del Ins Preset DONE
729 tk 942
 
766 tk 943
 
944
  // Preset dialogs:
945
  // Load Preset File (10 files found)       Trk.      SAVE AS                       
946
  //  xxxxxxxx  xxxxxxxx  xxxxxxxx  xxxxxxxx G1T1     NEW PRESET                 EXIT
947
 
948
  // Import selections:
956 tk 949
  // Importing /PRESETS/xxxxx.V4T to G1T1    Name Chn. Maps Cfg. Steps
766 tk 950
  // Please select track sections:           yes  yes  yes  yes   yes     IMPORT EXIT
951
 
952
  // "Save as new preset"
956 tk 953
  // Please enter Filename:                  /PRESETS/<xxxxxxxx>.V4T                 
766 tk 954
  // .,!1 ABC2 DEF3 GHI4 JKL5 MNO6 PQRS7 TUV8WXYZ9 -_ 0  Char <>  Del Ins   SAVE EXIT
955
 
956
  // File exists
956 tk 957
  //                                         File '/PRESETS/xxx.V4T' already exists     
766 tk 958
  //                                         Overwrite? YES  NO                  EXIT
959
 
960
 
961
 
962
 
174 tk 963
  u8 visible_track = SEQ_UI_VisibleTrackGet();
472 tk 964
 
965
  // if track has changed, switch layer config:
966
  if( visible_track != selected_layer_config_track ) {
967
    selected_layer_config_track = visible_track;
968
    selected_layer_config = GetLayerConfig(selected_layer_config_track);
969
  }
970
 
323 tk 971
  u8 event_mode = layer_config[selected_layer_config].event_mode;
174 tk 972
 
472 tk 973
 
766 tk 974
  switch( pr_dialog ) {
975
    ///////////////////////////////////////////////////////////////////////////
976
    case PR_DIALOG_EDIT_LABEL: {
977
      int i;
319 tk 978
 
766 tk 979
      SEQ_LCD_CursorSet(0, 0);
980
      if( event_mode == SEQ_EVENT_MODE_Drum ) {
981
    SEQ_LCD_PrintString("Please enter Drum Label for ");
982
    SEQ_LCD_PrintGxTy(ui_selected_group, ui_selected_tracks);
983
    SEQ_LCD_PrintFormattedString("-%2d:", ui_selected_instrument + 1);
984
    SEQ_LCD_PrintNote(SEQ_CC_Get(visible_track, SEQ_CC_LAY_CONST_A1 + ui_selected_instrument));
985
    SEQ_LCD_PrintSpaces(1);
472 tk 986
 
766 tk 987
    SEQ_LCD_PrintChar('<');
988
    for(i=0; i<5; ++i)
989
      SEQ_LCD_PrintChar(seq_core_trk[visible_track].name[5*ui_selected_instrument + i]);
990
    SEQ_LCD_PrintChar('>');
991
    SEQ_LCD_PrintSpaces(33);
472 tk 992
 
766 tk 993
    // insert flashing cursor
994
    if( ui_cursor_flash ) {
995
      if( ui_edit_name_cursor >= 5 ) // correct cursor position if it is outside the 5 char label space
996
        ui_edit_name_cursor = 0;
997
      SEQ_LCD_CursorSet(41 + ui_edit_name_cursor, 0);
998
      SEQ_LCD_PrintChar('*');
999
    }
1000
      } else {
1001
    if( ui_edit_name_cursor < 5 ) {
1002
      SEQ_LCD_PrintString("Please enter Track Category for ");
1003
      SEQ_LCD_PrintGxTy(ui_selected_group, ui_selected_tracks);
1004
      SEQ_LCD_PrintSpaces(4);
1005
    } else {
1006
      SEQ_LCD_PrintString("Please enter Track Label for ");
1007
      SEQ_LCD_PrintGxTy(ui_selected_group, ui_selected_tracks);
1008
      SEQ_LCD_PrintSpaces(7);
1009
    }
1010
    SEQ_LCD_PrintChar('<');
1011
    for(i=0; i<5; ++i)
1012
      SEQ_LCD_PrintChar(seq_core_trk[visible_track].name[i]);
1013
    SEQ_LCD_PrintChar('-');
1014
    for(i=5; i<20; ++i)
1015
      SEQ_LCD_PrintChar(seq_core_trk[visible_track].name[i]);
1016
    SEQ_LCD_PrintChar('>');
1017
    SEQ_LCD_PrintSpaces(17);
1018
      }
1019
 
1020
 
729 tk 1021
      // insert flashing cursor
1022
      if( ui_cursor_flash ) {
766 tk 1023
    SEQ_LCD_CursorSet(40 + ((ui_edit_name_cursor < 5) ? 1 : 2) + ui_edit_name_cursor, 0);
729 tk 1024
    SEQ_LCD_PrintChar('*');
1025
      }
766 tk 1026
 
1027
      SEQ_UI_KeyPad_LCD_Msg();
1028
      SEQ_LCD_PrintString("Preset DONE");
1029
    } break;
1030
 
1031
 
1032
    ///////////////////////////////////////////////////////////////////////////
1033
    case PR_DIALOG_PRESETS: {
1034
      SEQ_LCD_CursorSet(0, 0);
1035
      SEQ_LCD_PrintSpaces(40);
1036
 
1037
      SEQ_LCD_CursorSet(0, 0);
1038
      if( dir_num_items < 0 ) {
1039
    if( dir_num_items == SEQ_FILE_ERR_NO_DIR )
956 tk 1040
      SEQ_LCD_PrintString("/PRESETS directory not found on SD Card!");
766 tk 1041
    else
1042
      SEQ_LCD_PrintFormattedString("SD Card Access Error: %d", dir_num_items);
1043
      } else if( dir_num_items == 0 ) {
956 tk 1044
    SEQ_LCD_PrintFormattedString("No files found under /PRESETS!");
752 tk 1045
      } else {
766 tk 1046
    SEQ_LCD_PrintFormattedString("Select Preset File (%d files found)", dir_num_items);
729 tk 1047
      }
1048
 
766 tk 1049
      ///////////////////////////////////////////////////////////////////////////
1050
      SEQ_LCD_CursorSet(40, 0);
1051
      SEQ_LCD_PrintString("Trk.      SAVE AS");
1052
      SEQ_LCD_PrintSpaces(40-23);
752 tk 1053
 
766 tk 1054
      ///////////////////////////////////////////////////////////////////////////
1055
      SEQ_LCD_CursorSet(0, 1);
752 tk 1056
 
766 tk 1057
      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 1058
 
766 tk 1059
      SEQ_LCD_PrintGxTy(ui_selected_group, ui_selected_tracks);
1060
      SEQ_LCD_PrintString("     NEW PRESET                 EXIT");
1061
    } break;
752 tk 1062
 
1063
 
766 tk 1064
    case PR_DIALOG_IMPORT: {
1065
      ///////////////////////////////////////////////////////////////////////////
1066
      SEQ_LCD_CursorSet(0, 0);
956 tk 1067
      SEQ_LCD_PrintFormattedString("Importing /PRESETS/%s.V4T to ", dir_name);
766 tk 1068
      SEQ_LCD_PrintGxTy(ui_selected_group, ui_selected_tracks);
1069
      SEQ_LCD_PrintSpaces(10);
752 tk 1070
 
766 tk 1071
      SEQ_LCD_CursorSet(40, 0);
1072
      SEQ_LCD_PrintString("Name Chn. Maps Cfg. Steps");
1073
      SEQ_LCD_PrintSpaces(15);
752 tk 1074
 
766 tk 1075
      SEQ_LCD_CursorSet(0, 1);
1076
      SEQ_LCD_PrintFormattedString("Please select track sections:");
1077
      SEQ_LCD_PrintSpaces(11);
174 tk 1078
 
766 tk 1079
      if( ui_selected_item == IMPORT_ITEM_NAME && ui_cursor_flash ) {
1080
    SEQ_LCD_PrintSpaces(3);
1081
      } else {
1082
    SEQ_LCD_PrintString(import_flags.NAME ? "yes" : " no");
1083
      }
1084
      SEQ_LCD_PrintSpaces(2);
174 tk 1085
 
766 tk 1086
      if( ui_selected_item == IMPORT_ITEM_CHN && ui_cursor_flash ) {
1087
    SEQ_LCD_PrintSpaces(3);
1088
      } else {
1089
    SEQ_LCD_PrintString(import_flags.CHN ? "yes" : " no");
1090
      }
1091
      SEQ_LCD_PrintSpaces(2);
174 tk 1092
 
766 tk 1093
      if( ui_selected_item == IMPORT_ITEM_MAPS && ui_cursor_flash ) {
1094
    SEQ_LCD_PrintSpaces(3);
1095
      } else {
1096
    SEQ_LCD_PrintString(import_flags.MAPS ? "yes" : " no");
1097
      }
1098
      SEQ_LCD_PrintSpaces(2);
174 tk 1099
 
766 tk 1100
      if( ui_selected_item == IMPORT_ITEM_CFG && ui_cursor_flash ) {
1101
    SEQ_LCD_PrintSpaces(3);
1102
      } else {
1103
    SEQ_LCD_PrintString(import_flags.CFG ? "yes" : " no");
1104
      }
1105
      SEQ_LCD_PrintSpaces(2);
174 tk 1106
 
766 tk 1107
      if( ui_selected_item == IMPORT_ITEM_STEPS && ui_cursor_flash ) {
1108
    SEQ_LCD_PrintSpaces(3);
1109
      } else {
1110
    SEQ_LCD_PrintString(import_flags.STEPS ? "yes" : " no");
1111
      }
327 tk 1112
 
766 tk 1113
      SEQ_LCD_PrintSpaces(6);
327 tk 1114
 
766 tk 1115
      SEQ_LCD_PrintString("IMPORT EXIT");
1116
    } break;
327 tk 1117
 
174 tk 1118
 
766 tk 1119
    case PR_DIALOG_EXPORT_FNAME: {
1120
      int i;
174 tk 1121
 
766 tk 1122
      SEQ_LCD_CursorSet(0, 0);
1123
      SEQ_LCD_PrintString("Please enter Filename:");
1124
      SEQ_LCD_PrintSpaces(18);
174 tk 1125
 
956 tk 1126
      SEQ_LCD_PrintString("/PRESETS/<");
766 tk 1127
      for(i=0; i<8; ++i)
1128
    SEQ_LCD_PrintChar(dir_name[i]);
1129
      SEQ_LCD_PrintString(">.V4T");
1130
      SEQ_LCD_PrintSpaces(20);
472 tk 1131
 
766 tk 1132
      // insert flashing cursor
1133
      if( ui_cursor_flash ) {
1134
    SEQ_LCD_CursorSet(50 + ui_edit_name_cursor, 0);
1135
    SEQ_LCD_PrintChar('*');
1136
      }
472 tk 1137
 
766 tk 1138
      SEQ_UI_KeyPad_LCD_Msg();
1139
      SEQ_LCD_PrintString("  SAVE EXIT");
1140
    } break;
174 tk 1141
 
1142
 
766 tk 1143
    case PR_DIALOG_EXPORT_FEXISTS: {
1144
      SEQ_LCD_CursorSet(0, 0);
1145
      SEQ_LCD_PrintSpaces(40);
1146
 
956 tk 1147
      SEQ_LCD_PrintFormattedString("File '/PRESETS/%s.V4T' already exists!", dir_name);
766 tk 1148
      SEQ_LCD_PrintSpaces(10);
1149
 
1150
      SEQ_LCD_CursorSet(0, 1);
1151
      SEQ_LCD_PrintSpaces(40);
1152
 
1153
      SEQ_LCD_PrintString("Overwrite? YES  NO");
1154
      SEQ_LCD_PrintSpaces(18);
1155
      SEQ_LCD_PrintString("EXIT");
1156
    } break;
1157
 
1158
 
1159
 
1160
    ///////////////////////////////////////////////////////////////////////////
1161
    default:
1162
 
1163
      SEQ_LCD_CursorSet(0, 0);
1164
 
1165
      SEQ_LCD_PrintString("Trk. Type ");
1166
      SEQ_LCD_PrintString((event_mode == SEQ_EVENT_MODE_Drum) ? "StepsP/T  Drums " : "Steps/ParL/TrgL ");
1167
      SEQ_LCD_PrintString("Port Chn. ");
1168
 
1169
      if( ui_selected_item == ITEM_EDIT_NAME && ui_cursor_flash ) {
1170
    SEQ_LCD_PrintSpaces(4);
472 tk 1171
      } else {
766 tk 1172
    SEQ_LCD_PrintFormattedString("Edit");
472 tk 1173
      }
319 tk 1174
 
766 tk 1175
      if( selected_layer_config != GetLayerConfig(visible_track) ) {
1176
    SEQ_LCD_PrintString("    Please initialize the track         ");
1177
      } else if( event_mode == SEQ_EVENT_MODE_Drum ) {
1178
    SEQ_LCD_PrintString("LayA ");
1179
    SEQ_LCD_PrintString((layer_config[selected_layer_config].par_layers >= 2) ? "LayB " : "     ");
1180
    SEQ_LCD_PrintString(" Drum Note VelN VelA PRE-    ");
1181
      } else {
1182
    SEQ_LCD_PrintString("Layer  controls                         ");
1183
      }
319 tk 1184
 
766 tk 1185
      ///////////////////////////////////////////////////////////////////////////
1186
      SEQ_LCD_CursorSet(0, 1);
319 tk 1187
 
766 tk 1188
      if( ui_selected_item == ITEM_GXTY && ui_cursor_flash ) {
1189
    SEQ_LCD_PrintSpaces(5);
1190
      } else {
1191
    SEQ_LCD_PrintGxTy(ui_selected_group, ui_selected_tracks);
1192
    SEQ_LCD_PrintSpaces(1);
1193
      }
319 tk 1194
 
766 tk 1195
      ///////////////////////////////////////////////////////////////////////////
319 tk 1196
 
766 tk 1197
      if( ui_selected_item == ITEM_EVENT_MODE && ui_cursor_flash ) {
1198
    SEQ_LCD_PrintSpaces(21);
1199
      } else {
1200
    SEQ_LCD_PrintString((char *)SEQ_LAYER_GetEvntModeName(event_mode));
323 tk 1201
 
766 tk 1202
    layer_config_t *lc = (layer_config_t *)&layer_config[selected_layer_config];
1203
    if( event_mode == SEQ_EVENT_MODE_Drum ) {
1204
      SEQ_LCD_PrintChar(' ');
1205
      SEQ_LCD_PrintChar('(');
1206
      SEQ_LCD_PrintSpaces(14); // for easier handling
1207
      SEQ_LCD_CursorSet(12, 1);
1208
 
1209
      if( lc->par_layers > 1 )
1210
        SEQ_LCD_PrintFormattedString("%d*", lc->par_layers);
1211
      SEQ_LCD_PrintFormattedString("%d/", lc->par_steps);
1212
      if( lc->trg_layers > 1 )
1213
        SEQ_LCD_PrintFormattedString("%d*", lc->trg_layers);
1214
      SEQ_LCD_PrintFormattedString("%d", lc->trg_steps);
1215
 
1216
      SEQ_LCD_PrintFormattedString(") %d", lc->instruments);
1217
      SEQ_LCD_CursorSet(26, 1);
1218
    } else {
1219
      SEQ_LCD_PrintFormattedString("  %3d %3d  %3d  ", lc->par_steps, lc->par_layers, lc->trg_layers);
1220
    }
333 tk 1221
      }
174 tk 1222
 
766 tk 1223
      ///////////////////////////////////////////////////////////////////////////
1224
      mios32_midi_port_t port = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_PORT);
1225
      if( ui_selected_item == ITEM_MIDI_PORT && ui_cursor_flash ) {
1226
    SEQ_LCD_PrintSpaces(5);
1227
      } else {
1228
    SEQ_LCD_PrintMIDIOutPort(port);
1229
    SEQ_LCD_PrintChar(SEQ_MIDI_PORT_OutCheckAvailable(port) ? ' ' : '*');
1230
      }
178 tk 1231
 
766 tk 1232
      ///////////////////////////////////////////////////////////////////////////
1233
      if( ui_selected_item == ITEM_MIDI_CHANNEL && ui_cursor_flash ) {
1234
    SEQ_LCD_PrintSpaces(5);
1235
      } else {
1236
    SEQ_LCD_PrintFormattedString("%3d  ", SEQ_CC_Get(visible_track, SEQ_CC_MIDI_CHANNEL)+1);
1237
      }
323 tk 1238
 
766 tk 1239
      ///////////////////////////////////////////////////////////////////////////
1240
      if( ui_selected_item == ITEM_EDIT_NAME && ui_cursor_flash ) {
1241
    SEQ_LCD_PrintSpaces(4);
1242
      } else {
1243
    SEQ_LCD_PrintFormattedString("Name");
1244
      }
1245
 
1246
      ///////////////////////////////////////////////////////////////////////////
1247
      if( selected_layer_config != GetLayerConfig(visible_track) ) {
1248
    SEQ_LCD_PrintString(" ---------------------------------> ");
1249
    if( (ui_cursor_flash_overrun_ctr & 1) ) {
1250
      SEQ_LCD_PrintSpaces(4);
1251
    } else {
1252
      SEQ_LCD_PrintString("INIT");
1253
    }
1254
 
1255
        ///////////////////////////////////////////////////////////////////////////
1256
      } else if( event_mode == SEQ_EVENT_MODE_Drum ) {
1257
    /////////////////////////////////////////////////////////////////////////
1258
    if( ui_selected_item == ITEM_LAYER_A_SELECT && ui_cursor_flash ) {
1259
      SEQ_LCD_PrintSpaces(5);
1260
    } else {
1261
      SEQ_LCD_PrintString(SEQ_PAR_AssignedTypeStr(visible_track, 0));
1262
    }
1263
 
1264
    /////////////////////////////////////////////////////////////////////////
1265
    if( ui_selected_item == ITEM_LAYER_B_SELECT && ui_cursor_flash ) {
1266
      SEQ_LCD_PrintSpaces(5);
1267
    } else {
1268
      if( layer_config[selected_layer_config].par_layers >= 2 ) {
1269
        SEQ_LCD_PrintString(SEQ_PAR_AssignedTypeStr(visible_track, 1));
1270
      } else {
1271
        if( ui_selected_item == ITEM_LAYER_B_SELECT )
1272
          SEQ_LCD_PrintString("---- "); // not a bug, but a feature - highlight, that layer not configurable
1273
        else
1274
          SEQ_LCD_PrintSpaces(5);
1275
      }
1276
    }
1277
    SEQ_LCD_PrintSpaces(1);
1278
 
1279
    /////////////////////////////////////////////////////////////////////////
1280
    if( ui_selected_item == ITEM_DRUM_SELECT && ui_cursor_flash ) {
1281
      SEQ_LCD_PrintSpaces(5);
1282
    } else {
1283
      SEQ_LCD_PrintTrackDrum(visible_track, ui_selected_instrument, (char *)seq_core_trk[visible_track].name);
1284
    }
1285
 
1286
    /////////////////////////////////////////////////////////////////////////
1287
    SEQ_LCD_PrintSpaces(1);
1288
    if( ui_selected_item == ITEM_DRUM_NOTE && ui_cursor_flash ) {
1289
      SEQ_LCD_PrintSpaces(3);
1290
    } else {
1291
      SEQ_LCD_PrintNote(SEQ_CC_Get(visible_track, SEQ_CC_LAY_CONST_A1 + ui_selected_instrument));
1292
    }
1293
    SEQ_LCD_PrintSpaces(1);
1294
 
1295
    /////////////////////////////////////////////////////////////////////////
1296
    if( ui_selected_item == ITEM_DRUM_VEL_N && ui_cursor_flash ) {
1297
      SEQ_LCD_PrintSpaces(5);
1298
    } else {
1299
      SEQ_LCD_PrintFormattedString(" %3d ", SEQ_CC_Get(visible_track, SEQ_CC_LAY_CONST_B1 + ui_selected_instrument));
1300
    }
1301
 
1302
    /////////////////////////////////////////////////////////////////////////
1303
    if( ui_selected_item == ITEM_DRUM_VEL_A && ui_cursor_flash ) {
1304
      SEQ_LCD_PrintSpaces(5);
1305
    } else {
1306
      SEQ_LCD_PrintFormattedString(" %3d ", SEQ_CC_Get(visible_track, SEQ_CC_LAY_CONST_C1 + ui_selected_instrument));
1307
    }
1308
 
1309
    SEQ_LCD_PrintString("SETS INIT");
1310
      } else {
1311
    /////////////////////////////////////////////////////////////////////////
1312
    SEQ_LCD_PrintSpaces(2);
1313
    if( ui_selected_item == ITEM_LAYER_SELECT && ui_cursor_flash ) {
1314
      SEQ_LCD_PrintChar(' ');
1315
    } else {
1316
      SEQ_LCD_PrintChar('A' + ui_selected_par_layer);
1317
    }
1318
    SEQ_LCD_PrintSpaces(4);
1319
 
1320
    /////////////////////////////////////////////////////////////////////////
1321
    if( ui_selected_item == ITEM_LAYER_CONTROL && ui_cursor_flash ) {
1322
      SEQ_LCD_PrintSpaces(5);
1323
    } else {
1324
      SEQ_LCD_PrintString(SEQ_PAR_AssignedTypeStr(visible_track, ui_selected_par_layer));
1325
    }
1326
 
1327
    /////////////////////////////////////////////////////////////////////////
1328
    if( ui_selected_item == ITEM_LAYER_PAR && ui_cursor_flash ) {
1329
      SEQ_LCD_PrintSpaces(15);
1330
    } else {
1331
      switch( SEQ_PAR_AssignmentGet(visible_track, ui_selected_par_layer) ) {
1332
            case SEQ_PAR_Type_CC: {
1333
          mios32_midi_port_t port = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_PORT);
1334
          u8 current_value = SEQ_CC_Get(visible_track, SEQ_CC_LAY_CONST_B1 + ui_selected_par_layer);
1335
          u8 edit_value = ui_selected_item == ITEM_LAYER_PAR ? edit_cc_number : current_value;
1336
          SEQ_LCD_PrintFormattedString("%03d%c(%s)     ",
1337
                       edit_value,
1338
                       (current_value != edit_value) ? '!' : ' ',
1339
                       SEQ_CC_LABELS_Get(port, edit_value));
1340
        } break;
1341
 
1342
            default:
1343
          SEQ_LCD_PrintSpaces(15);
1344
      }
1345
    }
1346
 
1347
    SEQ_LCD_PrintString("PRESETS  INIT");
1348
      }
1349
  }
1350
 
174 tk 1351
  return 0; // no error
1352
}
1353
 
1354
 
1355
/////////////////////////////////////////////////////////////////////////////
1356
// Initialisation
1357
/////////////////////////////////////////////////////////////////////////////
1358
s32 SEQ_UI_TRKEVNT_Init(u32 mode)
1359
{
1360
  // install callback routines
1361
  SEQ_UI_InstallButtonCallback(Button_Handler);
1362
  SEQ_UI_InstallEncoderCallback(Encoder_Handler);
1363
  SEQ_UI_InstallLEDCallback(LED_Handler);
1364
  SEQ_UI_InstallLCDCallback(LCD_Handler);
1365
 
766 tk 1366
  // load charset (if this hasn't been done yet)
1367
  SEQ_LCD_InitSpecialChars(SEQ_LCD_CHARSET_Menu);
178 tk 1368
 
472 tk 1369
  selected_layer_config_track = SEQ_UI_VisibleTrackGet();
1370
  selected_layer_config = GetLayerConfig(selected_layer_config_track);
1371
 
1372
  // initialize edit label vars (name is modified directly, not via ui_edit_name!)
1373
  ui_edit_name_cursor = 0;
1374
  ui_edit_preset_num_category = 0;
1375
  ui_edit_preset_num_label = 0;
1376
 
766 tk 1377
  dir_name[0] = 0;
1378
  pr_dialog = 0;
1379
 
1380
  import_flags.ALL = 0xff;
1381
 
174 tk 1382
  return 0; // no error
1383
}
176 tk 1384
 
1385
 
1386
/////////////////////////////////////////////////////////////////////////////
323 tk 1387
// Copies preset
176 tk 1388
/////////////////////////////////////////////////////////////////////////////
323 tk 1389
static s32 CopyPreset(u8 track, u8 config)
176 tk 1390
{
323 tk 1391
  // exit if invalid config
1392
  if( config >= (sizeof(layer_config)/sizeof(layer_config_t)) )
1393
    return -1; // invalid config
176 tk 1394
 
328 tk 1395
  layer_config_t *lc = (layer_config_t *)&layer_config[selected_layer_config];
1396
 
323 tk 1397
  // partitionate layers and clear all steps
328 tk 1398
  SEQ_PAR_TrackInit(track, lc->par_steps, lc->par_layers, lc->instruments);
1399
  SEQ_TRG_TrackInit(track, lc->trg_steps, lc->trg_layers, lc->instruments);
176 tk 1400
 
472 tk 1401
#if 0
1402
  // confusing if assignments are not changed under such a condition
336 tk 1403
  u8 init_assignments = lc->event_mode != SEQ_CC_Get(track, SEQ_CC_MIDI_EVENT_MODE);
472 tk 1404
#else
1405
  u8 init_assignments = 1;
1406
#endif
336 tk 1407
 
328 tk 1408
  SEQ_CC_Set(track, SEQ_CC_MIDI_EVENT_MODE, lc->event_mode);
176 tk 1409
 
326 tk 1410
  // BEGIN TMP
328 tk 1411
  if( lc->event_mode == SEQ_EVENT_MODE_Drum ) {
729 tk 1412
    int i;
1413
 
1414
    for(i=0; i<16; ++i)
1415
      SEQ_LABEL_CopyPresetDrum(i, (char *)&seq_core_trk[track].name[5*i]);
326 tk 1416
  } else {
1417
    memset((char *)seq_core_trk[track].name, ' ', 80);
1418
  }
1419
  // END TMP
1420
 
324 tk 1421
  u8 only_layers = 0;
1422
  u8 all_triggers_cleared = 0;
335 tk 1423
  return SEQ_LAYER_CopyPreset(track, only_layers, all_triggers_cleared, init_assignments);
323 tk 1424
}
176 tk 1425
 
1426
 
323 tk 1427
/////////////////////////////////////////////////////////////////////////////
1428
// Determines current layer config
1429
/////////////////////////////////////////////////////////////////////////////
1430
static s32 GetLayerConfig(u8 track)
1431
{
1432
  int i;
1433
 
1434
  u8 event_mode = SEQ_CC_Get(track, SEQ_CC_MIDI_EVENT_MODE);
1435
  u8 par_layers = SEQ_PAR_NumLayersGet(track);
1436
  u16 par_steps = SEQ_PAR_NumStepsGet(track);
1437
  u8 trg_layers = SEQ_TRG_NumLayersGet(track);
1438
  u16 trg_steps = SEQ_TRG_NumStepsGet(track);
328 tk 1439
  u8 num_instruments = SEQ_PAR_NumInstrumentsGet(track);
323 tk 1440
 
1441
  for(i=0; i<(sizeof(layer_config)/sizeof(layer_config_t)); ++i) {
1442
    layer_config_t *lc = (layer_config_t *)&layer_config[i];
1443
    if( lc->event_mode == event_mode &&
1444
    lc->par_layers == par_layers && lc->par_steps == par_steps &&
325 tk 1445
    lc->trg_layers == trg_layers && lc->trg_steps == trg_steps &&
328 tk 1446
    lc->instruments == num_instruments ) {
323 tk 1447
      return i;
176 tk 1448
    }
1449
  }
1450
 
323 tk 1451
  return 0; // not found, return index to first config
176 tk 1452
}
178 tk 1453
 
756 tk 1454
/////////////////////////////////////////////////////////////////////////////
1455
// help function for Init button function
1456
/////////////////////////////////////////////////////////////////////////////
1457
static void InitReq(u32 dummy)
1458
{
1459
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1460
 
1461
  // TODO: copy preset for all selected tracks!
1462
  CopyPreset(visible_track, selected_layer_config);
1463
 
1464
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "Track has been", "initialized!");
1465
}
766 tk 1466
 
1467
 
1468
/////////////////////////////////////////////////////////////////////////////
1469
// help function to scan presets directory
1470
/////////////////////////////////////////////////////////////////////////////
1471
static s32 SEQ_UI_TRKEVNT_UpdateDirList(void)
1472
{
1473
  int item;
1474
 
1475
  MUTEX_SDCARD_TAKE;
956 tk 1476
  dir_num_items = SEQ_FILE_GetFiles("/PRESETS", "V4T", (char *)&ui_global_dir_list[0], NUM_LIST_DISPLAYED_ITEMS, dir_view_offset);
766 tk 1477
  MUTEX_SDCARD_GIVE;
1478
 
1479
  if( dir_num_items < 0 )
1480
    item = 0;
1481
  else if( dir_num_items < NUM_LIST_DISPLAYED_ITEMS )
1482
    item = dir_num_items;
1483
  else
1484
    item = NUM_LIST_DISPLAYED_ITEMS;
1485
 
1486
  while( item < NUM_LIST_DISPLAYED_ITEMS ) {
1487
    ui_global_dir_list[LIST_ENTRY_WIDTH*item] = 0;
1488
    ++item;
1489
  }
1490
 
1491
  return 0; // no error
1492
}
1493
 
1494
 
1495
/////////////////////////////////////////////////////////////////////////////
1496
// help function to start Track preset file export
1497
// returns 0 on success
1498
// returns != 0 on errors (dialog page will be changed accordingly)
1499
/////////////////////////////////////////////////////////////////////////////
1500
static s32 DoExport(u8 force_overwrite)
1501
{
1502
  s32 status;
1503
  int i;
1504
  char path[20];
1505
 
1506
  // if an error is detected, we jump back to FNAME page
1507
  ui_selected_item = 0;
1508
  pr_dialog = PR_DIALOG_EXPORT_FNAME;
1509
 
1510
  u8 filename_valid = 1;
1511
  for(i=0; i<8; ++i)
1512
    if( dir_name[i] == '.' || dir_name[i] == '?' || dir_name[i] == ',' || dir_name[i] == '!' )
1513
      filename_valid = 0;
1514
 
1515
  if( !filename_valid ) {
1516
    SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 2000, "Filename not valid!", "(remove . ? , !)");
1517
    return -1;
1518
  }
1519
 
1520
  if( dir_name[0] == ' ') {
1521
    SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 2000, "Please enter", "Filename!");
1522
    return -2;
1523
  }
1524
 
956 tk 1525
  strcpy(path, "/PRESETS");
766 tk 1526
  MUTEX_SDCARD_TAKE;
959 tk 1527
  status = SEQ_FILE_MakeDir(path); // create directory if it doesn't exist
766 tk 1528
  status = SEQ_FILE_DirExists(path);
1529
  MUTEX_SDCARD_GIVE;
1530
 
1531
  if( status < 0 ) {
1532
    SEQ_UI_SDCardErrMsg(2000, status);
1533
    return -3;
1534
  }
1535
 
1536
  if( status == 0 ) {
959 tk 1537
    SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 2000, "/PRESETS directory", "cannot be created!");
766 tk 1538
    return -4;
1539
  }
1540
 
956 tk 1541
  char v4t_file[20];
1542
  char *p = (char *)&v4t_file[0];
1543
  for(i=0; i<8; ++i) {
1544
    char c = dir_name[i];
1545
    if( c != ' ' )
1546
      *p++ = c;
1547
  }
1548
  *p++ = 0;
766 tk 1549
 
956 tk 1550
  sprintf(path, "/PRESETS/%s.v4t", v4t_file);
1551
 
766 tk 1552
  MUTEX_SDCARD_TAKE;
1553
  status = SEQ_FILE_FileExists(path);
1554
  MUTEX_SDCARD_GIVE;
1555
 
1556
  if( status < 0 ) {
1557
    SEQ_UI_SDCardErrMsg(2000, status);
1558
    return -5;
1559
  }
1560
 
1561
 
1562
  if( !force_overwrite && status == 1) {
1563
    // file exists - ask if it should be overwritten in a special dialog page
1564
    pr_dialog = PR_DIALOG_EXPORT_FEXISTS;
1565
    return 1;
1566
  }
1567
 
1568
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 2000, "Exporting", path);
1569
 
769 tk 1570
  MUTEX_SDCARD_TAKE;
1571
  status=SEQ_FILE_T_Write(path, SEQ_UI_VisibleTrackGet());
1572
  MUTEX_SDCARD_GIVE;
1573
 
1574
  if( status < 0 ) {
766 tk 1575
    SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 2000, "Error during Export!", "see MIOS Terminal!");
1576
    return -6;
1577
  }
1578
 
1579
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 2000, "Export", "successfull!");
1580
 
1581
  return 0; // no error
1582
}
1583
 
1584
 
1585
/////////////////////////////////////////////////////////////////////////////
1586
// help function to start Track preset file export
1587
// returns 0 on success
1588
// returns != 0 on errors (dialog page will be changed accordingly)
1589
/////////////////////////////////////////////////////////////////////////////
1590
static s32 DoImport(void)
1591
{
1592
  s32 status;
1593
  char path[20];
1594
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1595
 
956 tk 1596
  sprintf(path, "/PRESETS/%s.V4T", dir_name);
766 tk 1597
 
769 tk 1598
  // mute track to avoid random effects while loading the file
1599
  MIOS32_IRQ_Disable(); // this operation should be atomic!
1600
  u8 muted = seq_core_trk[visible_track].state.MUTED;
1601
  if( !muted )
1602
    seq_core_trk[visible_track].state.MUTED = 1;
1603
  MIOS32_IRQ_Enable();
1604
 
1605
  // read file
766 tk 1606
  MUTEX_SDCARD_TAKE;
1607
  status = SEQ_FILE_T_Read(path, visible_track, import_flags);
1608
  MUTEX_SDCARD_GIVE;
1609
 
769 tk 1610
  // unmute track if it wasn't muted before
1611
  MIOS32_IRQ_Disable(); // this operation should be atomic!
1612
  if( !muted )
1613
    seq_core_trk[visible_track].state.MUTED = 0;
1614
  MIOS32_IRQ_Enable();
1615
 
766 tk 1616
  if( status < 0 ) {
1617
    SEQ_UI_SDCardErrMsg(2000, status);
1618
  } else {
1619
    SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 2000, path, "imported!");
1620
 
1621
    // fix layer config
1622
    selected_layer_config_track = visible_track;
1623
    selected_layer_config = GetLayerConfig(selected_layer_config_track);
1624
  }
1625
 
1626
  return 0; // no error
1627
}