Subversion Repositories svn.mios32

Rev

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