Subversion Repositories svn.mios32

Rev

Rev 137 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
134 tk 1
// $Id: seq_ui.c 134 2008-11-29 21:29:58Z tk $
2
/*
3
 * User Interface Routines
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>
19
 
20
#if DEFAULT_SRM_ENABLED
21
#include <blm8x8.h>
22
#endif
23
 
24
#include "seq_ui.h"
25
#include "seq_lcd.h"
26
#include "seq_led.h"
27
#include "seq_midi.h"
28
#include "seq_core.h"
29
#include "seq_par.h"
30
#include "seq_trg.h"
31
 
32
 
33
/////////////////////////////////////////////////////////////////////////////
34
// Local types
35
/////////////////////////////////////////////////////////////////////////////
36
 
37
 
38
/////////////////////////////////////////////////////////////////////////////
39
// Local prototypes
40
/////////////////////////////////////////////////////////////////////////////
41
 
42
 
43
/////////////////////////////////////////////////////////////////////////////
44
// Global variables
45
/////////////////////////////////////////////////////////////////////////////
46
 
47
ui_display_t ui_display;
48
 
49
u8 ui_selected_group;
50
u8 ui_selected_tracks;
51
u8 ui_selected_par_layer;
52
u8 ui_selected_trg_layer;
53
u8 ui_selected_step_view;
54
u8 ui_selected_step;
55
 
56
u16 ui_gp_leds;
57
 
58
 
59
/////////////////////////////////////////////////////////////////////////////
60
// Local variables
61
/////////////////////////////////////////////////////////////////////////////
62
 
63
 
64
/////////////////////////////////////////////////////////////////////////////
65
// Initialisation
66
/////////////////////////////////////////////////////////////////////////////
67
s32 SEQ_UI_Init(u32 mode)
68
{
69
  // init selection variables
70
  ui_selected_group = 0;
71
  ui_selected_tracks = (1 << 0);
72
  ui_selected_par_layer = 0;
73
  ui_selected_trg_layer = 0;
74
  ui_selected_step_view = 0;
75
  ui_selected_step = 0;
76
 
77
  // visible GP pattern
78
  ui_gp_leds = 0x0000;
79
 
80
  // request display initialisation
81
  ui_display.ALL = 0;
82
  ui_display.INIT_REQ = 1;
83
 
84
  return 0; // no error
85
}
86
 
87
 
88
/////////////////////////////////////////////////////////////////////////////
89
// Dedicated button functions
90
// Mapped to physical buttons in SEQ_UI_Button_Handler()
91
// Will also be mapped to MIDI keys later (for MIDI remote function)
92
/////////////////////////////////////////////////////////////////////////////
93
static s32 SEQ_UI_Button_GP(s32 depressed, u32 gp)
94
{
95
  if( depressed ) return -1; // ignore when button depressed
96
 
97
  // toggle trigger layer
98
  u8 visible_track = SEQ_UI_VisibleTrackGet();
99
  u8 step = gp + ui_selected_step_view*16;
100
  trg_layer_value[visible_track][ui_selected_trg_layer][step>>3] ^= (1 << (step&7));
101
 
102
  return 0; // no error
103
}
104
 
105
static s32 SEQ_UI_Button_Left(s32 depressed)
106
{
107
  if( depressed ) return -1; // ignore when button depressed
108
 
109
  if( played_step ) // tmp.
110
    --played_step;
111
 
112
  return 0; // no error
113
}
114
 
115
static s32 SEQ_UI_Button_Right(s32 depressed)
116
{
117
  if( depressed ) return -1; // ignore when button depressed
118
 
119
  if( ++played_step >= SEQ_CORE_NUM_STEPS ) // tmp.
120
    played_step = 0;
121
 
122
  return 0; // no error
123
}
124
 
125
static s32 SEQ_UI_Button_Scrub(s32 depressed)
126
{
127
  if( depressed ) return -1; // ignore when button depressed
128
 
129
  return 0; // no error
130
}
131
 
132
static s32 SEQ_UI_Button_Metronome(s32 depressed)
133
{
134
  if( depressed ) return -1; // ignore when button depressed
135
 
136
  return 0; // no error
137
}
138
 
139
static s32 SEQ_UI_Button_Stop(s32 depressed)
140
{
141
  if( depressed ) return -1; // ignore when button depressed
142
 
143
  return 0; // no error
144
}
145
 
146
static s32 SEQ_UI_Button_Pause(s32 depressed)
147
{
148
  if( depressed ) return -1; // ignore when button depressed
149
 
150
  return 0; // no error
151
}
152
 
153
static s32 SEQ_UI_Button_Play(s32 depressed)
154
{
155
  if( depressed ) return -1; // ignore when button depressed
156
 
157
  return 0; // no error
158
}
159
 
160
static s32 SEQ_UI_Button_Rew(s32 depressed)
161
{
162
  if( depressed ) return -1; // ignore when button depressed
163
 
164
  return 0; // no error
165
}
166
 
167
static s32 SEQ_UI_Button_Fwd(s32 depressed)
168
{
169
  if( depressed ) return -1; // ignore when button depressed
170
 
171
  return 0; // no error
172
}
173
 
174
static s32 SEQ_UI_Button_F1(s32 depressed)
175
{
176
  if( depressed ) return -1; // ignore when button depressed
177
 
178
  return 0; // no error
179
}
180
 
181
static s32 SEQ_UI_Button_F2(s32 depressed)
182
{
183
  if( depressed ) return -1; // ignore when button depressed
184
 
185
  return 0; // no error
186
}
187
 
188
static s32 SEQ_UI_Button_F3(s32 depressed)
189
{
190
  if( depressed ) return -1; // ignore when button depressed
191
 
192
  return 0; // no error
193
}
194
 
195
static s32 SEQ_UI_Button_F4(s32 depressed)
196
{
197
  if( depressed ) return -1; // ignore when button depressed
198
 
199
  return 0; // no error
200
}
201
 
202
static s32 SEQ_UI_Button_Utility(s32 depressed)
203
{
204
  if( depressed ) return -1; // ignore when button depressed
205
 
206
  return 0; // no error
207
}
208
 
209
static s32 SEQ_UI_Button_Copy(s32 depressed)
210
{
211
  if( depressed ) return -1; // ignore when button depressed
212
 
213
  return 0; // no error
214
}
215
 
216
static s32 SEQ_UI_Button_Paste(s32 depressed)
217
{
218
  if( depressed ) return -1; // ignore when button depressed
219
 
220
  return 0; // no error
221
}
222
 
223
static s32 SEQ_UI_Button_Clear(s32 depressed)
224
{
225
  if( depressed ) return -1; // ignore when button depressed
226
 
227
  return 0; // no error
228
}
229
 
230
static s32 SEQ_UI_Button_Menu(s32 depressed)
231
{
232
  if( depressed ) return -1; // ignore when button depressed
233
 
234
  return 0; // no error
235
}
236
 
237
static s32 SEQ_UI_Button_Select(s32 depressed)
238
{
239
  if( depressed ) return -1; // ignore when button depressed
240
 
241
  return 0; // no error
242
}
243
 
244
static s32 SEQ_UI_Button_Exit(s32 depressed)
245
{
246
  if( depressed ) return -1; // ignore when button depressed
247
 
248
  return 0; // no error
249
}
250
 
251
static s32 SEQ_UI_Button_Edit(s32 depressed)
252
{
253
  if( depressed ) return -1; // ignore when button depressed
254
 
255
  return 0; // no error
256
}
257
 
258
static s32 SEQ_UI_Button_Mute(s32 depressed)
259
{
260
  if( depressed ) return -1; // ignore when button depressed
261
 
262
  return 0; // no error
263
}
264
 
265
static s32 SEQ_UI_Button_Pattern(s32 depressed)
266
{
267
  if( depressed ) return -1; // ignore when button depressed
268
 
269
  return 0; // no error
270
}
271
 
272
static s32 SEQ_UI_Button_Song(s32 depressed)
273
{
274
  if( depressed ) return -1; // ignore when button depressed
275
 
276
  return 0; // no error
277
}
278
 
279
static s32 SEQ_UI_Button_Solo(s32 depressed)
280
{
281
  if( depressed ) return -1; // ignore when button depressed
282
 
283
  return 0; // no error
284
}
285
 
286
static s32 SEQ_UI_Button_Fast(s32 depressed)
287
{
288
  if( depressed ) return -1; // ignore when button depressed
289
 
290
  return 0; // no error
291
}
292
 
293
static s32 SEQ_UI_Button_All(s32 depressed)
294
{
295
  if( depressed ) return -1; // ignore when button depressed
296
 
297
  return 0; // no error
298
}
299
 
300
static s32 SEQ_UI_Button_StepView(s32 depressed)
301
{
302
  if( depressed ) return -1; // ignore when button depressed
303
 
304
  ui_selected_step_view = ui_selected_step_view ? 0 : 1;
305
 
306
  return 0; // no error
307
}
308
 
309
static s32 SEQ_UI_Button_TapTempo(s32 depressed)
310
{
311
  if( depressed ) return -1; // ignore when button depressed
312
 
313
  return 0; // no error
314
}
315
 
316
static s32 SEQ_UI_Button_Track(s32 depressed, u32 track)
317
{
318
  if( depressed ) return -1; // ignore when button depressed
319
 
320
  if( track >= 4 ) return -2; // max. 4 track buttons
321
 
322
  ui_selected_tracks = (1 << track); // TODO: multi-selections!
323
 
324
  return 0; // no error
325
}
326
 
327
static s32 SEQ_UI_Button_Group(s32 depressed, u32 group)
328
{
329
  if( depressed ) return -1; // ignore when button depressed
330
 
331
  if( group >= 4 ) return -2; // max. 4 group buttons
332
 
333
  ui_selected_group = group;
334
 
335
  return 0; // no error
336
}
337
 
338
static s32 SEQ_UI_Button_ParLayer(s32 depressed, u32 par_layer)
339
{
340
  if( depressed ) return -1; // ignore when button depressed
341
 
342
  if( par_layer >= 3 ) return -2; // max. 3 parlayer buttons
343
 
344
  ui_selected_par_layer = par_layer;
345
 
346
  return 0; // no error
347
}
348
 
349
static s32 SEQ_UI_Button_TrgLayer(s32 depressed, u32 trg_layer)
350
{
351
  if( depressed ) return -1; // ignore when button depressed
352
 
353
  if( trg_layer >= 3 ) return -2; // max. 3 trglayer buttons
354
 
355
  ui_selected_trg_layer = trg_layer;
356
 
357
  return 0; // no error
358
}
359
 
360
 
361
 
362
/////////////////////////////////////////////////////////////////////////////
363
// Button handler
364
/////////////////////////////////////////////////////////////////////////////
365
s32 SEQ_UI_Button_Handler(u32 pin, u32 pin_value)
366
{
367
  switch( pin ) {
368
#if BUTTON_GP1
369
    case BUTTON_GP1:   SEQ_UI_Button_GP(pin_value, 0); break;
370
#endif
371
#if BUTTON_GP2
372
    case BUTTON_GP2:   SEQ_UI_Button_GP(pin_value, 1); break;
373
#endif
374
#if BUTTON_GP3
375
    case BUTTON_GP3:   SEQ_UI_Button_GP(pin_value, 2); break;
376
#endif
377
#if BUTTON_GP4
378
    case BUTTON_GP4:   SEQ_UI_Button_GP(pin_value, 3); break;
379
#endif
380
#if BUTTON_GP5
381
    case BUTTON_GP5:   SEQ_UI_Button_GP(pin_value, 4); break;
382
#endif
383
#if BUTTON_GP6
384
    case BUTTON_GP6:   SEQ_UI_Button_GP(pin_value, 5); break;
385
#endif
386
#if BUTTON_GP7
387
    case BUTTON_GP7:   SEQ_UI_Button_GP(pin_value, 6); break;
388
#endif
389
#if BUTTON_GP8
390
    case BUTTON_GP8:   SEQ_UI_Button_GP(pin_value, 7); break;
391
#endif
392
#if BUTTON_GP9
393
    case BUTTON_GP9:   SEQ_UI_Button_GP(pin_value, 8); break;
394
#endif
395
#if BUTTON_GP10
396
    case BUTTON_GP10:  SEQ_UI_Button_GP(pin_value, 9); break;
397
#endif
398
#if BUTTON_GP11
399
    case BUTTON_GP11:  SEQ_UI_Button_GP(pin_value, 10); break;
400
#endif
401
#if BUTTON_GP12
402
    case BUTTON_GP12:  SEQ_UI_Button_GP(pin_value, 11); break;
403
#endif
404
#if BUTTON_GP13
405
    case BUTTON_GP13:  SEQ_UI_Button_GP(pin_value, 12); break;
406
#endif
407
#if BUTTON_GP14
408
    case BUTTON_GP14:  SEQ_UI_Button_GP(pin_value, 13); break;
409
#endif
410
#if BUTTON_GP15
411
    case BUTTON_GP15:  SEQ_UI_Button_GP(pin_value, 14); break;
412
#endif
413
#if BUTTON_GP16
414
    case BUTTON_GP16:  SEQ_UI_Button_GP(pin_value, 15); break;
415
#endif
416
 
417
#if BUTTON_LEFT
418
    case BUTTON_LEFT:  SEQ_UI_Button_Left(pin_value); break;
419
#endif
420
#if BUTTON_RIGHT
421
    case BUTTON_RIGHT: SEQ_UI_Button_Right(pin_value); break;
422
#endif
423
 
424
#if BUTTON_SCRUB
425
    case BUTTON_SCRUB: SEQ_UI_Button_Scrub(pin_value); break;
426
#endif
427
#if BUTTON_METRONOME
428
    case BUTTON_METRONOME: SEQ_UI_Button_Metronome(pin_value); break;
429
#endif
430
 
431
#if BUTTON_STOP
432
    case BUTTON_STOP:  SEQ_UI_Button_Stop(pin_value); break;
433
#endif
434
#if BUTTON_PAUSE
435
    case BUTTON_PAUSE: SEQ_UI_Button_Pause(pin_value); break;
436
#endif
437
#if BUTTON_PLAY
438
    case BUTTON_PLAY:  SEQ_UI_Button_Play(pin_value); break;
439
#endif
440
#if BUTTON_REW
441
    case BUTTON_REW:   SEQ_UI_Button_Rew(pin_value); break;
442
#endif
443
#if BUTTON_FWD
444
    case BUTTON_FWD:   SEQ_UI_Button_Fwd(pin_value); break;
445
#endif
446
 
447
#if BUTTON_F1
448
    case BUTTON_F1:    SEQ_UI_Button_F1(pin_value); break;
449
#endif
450
#if BUTTON_F2
451
    case BUTTON_F2:    SEQ_UI_Button_F2(pin_value); break;
452
#endif
453
#if BUTTON_F3
454
    case BUTTON_F3:    SEQ_UI_Button_F3(pin_value); break;
455
#endif
456
#if BUTTON_F4
457
    case BUTTON_F4:    SEQ_UI_Button_F4(pin_value); break;
458
#endif
459
 
460
#if BUTTON_UTILITY
461
    case BUTTON_UTILITY: SEQ_UI_Button_Utility(pin_value); break;
462
#endif
463
#if BUTTON_COPY
464
    case BUTTON_COPY:  SEQ_UI_Button_Copy(pin_value); break;
465
#endif
466
#if BUTTON_PASTE
467
    case BUTTON_PASTE: SEQ_UI_Button_Paste(pin_value); break;
468
#endif
469
#if BUTTON_CLEAR
470
    case BUTTON_CLEAR: SEQ_UI_Button_Clear(pin_value); break;
471
#endif
472
 
473
#if BUTTON_MENU
474
    case BUTTON_MENU:  SEQ_UI_Button_Menu(pin_value); break;
475
#endif
476
#if BUTTON_SELECT
477
    case BUTTON_SELECT:SEQ_UI_Button_Select(pin_value); break;
478
#endif
479
#if BUTTON_EXIT
480
    case BUTTON_EXIT:  SEQ_UI_Button_Exit(pin_value); break;
481
#endif
482
 
483
#if BUTTON_TRACK1
484
    case BUTTON_TRACK1: SEQ_UI_Button_Track(pin_value, 0); break;
485
#endif
486
#if BUTTON_TRACK2
487
    case BUTTON_TRACK2: SEQ_UI_Button_Track(pin_value, 1); break;
488
#endif
489
#if BUTTON_TRACK3
490
    case BUTTON_TRACK3: SEQ_UI_Button_Track(pin_value, 2); break;
491
#endif
492
#if BUTTON_TRACK4
493
    case BUTTON_TRACK4: SEQ_UI_Button_Track(pin_value, 3); break;
494
#endif
495
 
496
#if BUTTON_PAR_LAYER_A
497
    case BUTTON_PAR_LAYER_A: SEQ_UI_Button_ParLayer(pin_value, 0); break;
498
#endif
499
#if BUTTON_PAR_LAYER_B
500
    case BUTTON_PAR_LAYER_B: SEQ_UI_Button_ParLayer(pin_value, 1); break;
501
#endif
502
#if BUTTON_PAR_LAYER_C
503
    case BUTTON_PAR_LAYER_C: SEQ_UI_Button_ParLayer(pin_value, 2); break;
504
#endif
505
 
506
#if BUTTON_EDIT
507
    case BUTTON_EDIT:   SEQ_UI_Button_Edit(pin_value); break;
508
#endif
509
#if BUTTON_MUTE
510
    case BUTTON_MUTE:   SEQ_UI_Button_Mute(pin_value); break;
511
#endif
512
#if BUTTON_PATTERN
513
    case BUTTON_PATTERN:SEQ_UI_Button_Pattern(pin_value); break;
514
#endif
515
#if BUTTON_SONG
516
    case BUTTON_SONG:   SEQ_UI_Button_Song(pin_value); break;
517
#endif
518
 
519
#if BUTTON_SOLO
520
    case BUTTON_SOLO:   SEQ_UI_Button_Solo(pin_value); break;
521
#endif
522
#if BUTTON_FAST
523
    case BUTTON_FAST:   SEQ_UI_Button_Fast(pin_value); break;
524
#endif
525
#if BUTTON_ALL
526
    case BUTTON_ALL:    SEQ_UI_Button_All(pin_value); break;
527
#endif
528
 
529
#if BUTTON_GROUP1
530
    case BUTTON_GROUP1: SEQ_UI_Button_Group(pin_value, 0); break;
531
#endif
532
#if BUTTON_GROUP2
533
    case BUTTON_GROUP2: SEQ_UI_Button_Group(pin_value, 1); break;
534
#endif
535
#if BUTTON_GROUP3
536
    case BUTTON_GROUP3: SEQ_UI_Button_Group(pin_value, 2); break;
537
#endif
538
#if BUTTON_GROUP4
539
    case BUTTON_GROUP4: SEQ_UI_Button_Group(pin_value, 3); break;
540
#endif
541
 
542
#if BUTTON_TRG_LAYER_A
543
    case BUTTON_TRG_LAYER_A: SEQ_UI_Button_TrgLayer(pin_value, 0); break;
544
#endif
545
#if BUTTON_TRG_LAYER_B
546
    case BUTTON_TRG_LAYER_B: SEQ_UI_Button_TrgLayer(pin_value, 1); break;
547
#endif
548
#if BUTTON_TRG_LAYER_C
549
    case BUTTON_TRG_LAYER_C: SEQ_UI_Button_TrgLayer(pin_value, 2); break;
550
#endif
551
 
552
#if BUTTON_STEP_VIEW
553
    case BUTTON_STEP_VIEW: SEQ_UI_Button_StepView(pin_value); break;
554
#endif
555
 
556
#if BUTTON_TAP_TEMPO
557
    case BUTTON_TAP_TEMPO:   SEQ_UI_Button_TapTempo(pin_value); break;
558
#endif
559
 
560
    default:
561
      return -1; // button function not mapped to physical button
562
  }
563
 
564
  // request display update
565
  ui_display.UPDATE_REQ = 1;
566
 
567
  return 0; // no error
568
}
569
 
570
 
571
/////////////////////////////////////////////////////////////////////////////
572
// Encoder handler
573
/////////////////////////////////////////////////////////////////////////////
574
s32 SEQ_UI_Encoder_Handler(u32 encoder, s32 incrementer)
575
{
576
  if( encoder > 16 )
577
    return -1; // encoder doesn't exist
578
 
579
  // limit incrementer
580
  if( incrementer > 3 )
581
    incrementer = 3;
582
  else if( incrementer < -3 )
583
    incrementer = -3;
584
 
585
  if( encoder == 0 ) {
586
    s32 value = played_step + incrementer;
587
    if( value < 0 )
588
      value = 0;
589
    if( value > SEQ_CORE_NUM_STEPS-1 )
590
      value = SEQ_CORE_NUM_STEPS-1;
591
    played_step = (u8)value;
592
  } else {
593
    u8 visible_track = SEQ_UI_VisibleTrackGet();
594
    u8 step = encoder-1 + ui_selected_step_view*16;
595
 
596
    // select step
597
    ui_selected_step = step;
598
 
599
    // add to absolute value
600
    s32 value = (s32)par_layer_value[visible_track][ui_selected_par_layer][step] + incrementer;
601
    if( value < 0 )
602
      value = 0;
603
    else if( value >= 128 )
604
      value = 127;
605
 
606
    // take over if changed
607
    if( (u8)value != par_layer_value[visible_track][ui_selected_par_layer][step] ) {
608
      par_layer_value[visible_track][ui_selected_par_layer][step] = (u8)value;
609
      // here we could do more on changes - important for mixer function (event only sent on changes)
610
    }
611
 
612
    // (de)activate gate depending on value
613
    if( value )
614
      trg_layer_value[visible_track][0][step>>3] |= (1 << (step&7));
615
    else
616
      trg_layer_value[visible_track][0][step>>3] &= ~(1 << (step&7));
617
  }
618
 
619
  // request display update
620
  ui_display.UPDATE_REQ = 1;
621
 
622
  return 0; // no error
623
}
624
 
625
 
626
/////////////////////////////////////////////////////////////////////////////
627
// Update LCD messages
628
// Usually called from background task
629
/////////////////////////////////////////////////////////////////////////////
630
s32 SEQ_UI_LCD_Handler(void)
631
{
632
  if( ui_display.INIT_REQ ) {
633
    ui_display.INIT_REQ = 0; // clear request
634
 
635
    // clear both LCDs
636
    int i;
637
    for(i=0; i<2; ++i) {
638
      MIOS32_LCD_DeviceSet(i);
639
      SEQ_LCD_Clear();
640
    }
641
 
642
    // initialise charset
643
    SEQ_LCD_InitSpecialChars(SEQ_LCD_CHARSET_VBARS);
644
 
645
    // request display update
646
    ui_display.UPDATE_REQ = 1;
647
  }
648
 
649
  if( ui_display.UPDATE_REQ ) {
650
    ui_display.UPDATE_REQ = 0; // clear request
651
 
652
    char tmp[128];
653
    u8 step;
654
    u8 visible_track = SEQ_UI_VisibleTrackGet();
655
 
656
    ///////////////////////////////////////////////////////////////////////////
657
    MIOS32_LCD_DeviceSet(0);
658
    MIOS32_LCD_CursorSet(0, 0);
659
 
660
    SEQ_LCD_PrintGxTy(ui_selected_group, ui_selected_tracks);
661
    SEQ_LCD_PrintSpaces(2);
662
 
663
    SEQ_LCD_PrintParLayer(ui_selected_par_layer);
664
    SEQ_LCD_PrintSpaces(1);
665
 
666
    MIOS32_LCD_PrintFormattedString("Chn%2d", midi_channel+1);
667
    MIOS32_LCD_PrintChar('/');
668
    SEQ_LCD_PrintMIDIPort(midi_port);
669
    SEQ_LCD_PrintSpaces(1);
670
 
671
    SEQ_LCD_PrintTrgLayer(ui_selected_trg_layer);
672
 
673
    SEQ_LCD_PrintStepView(ui_selected_step_view);
674
 
675
 
676
    ///////////////////////////////////////////////////////////////////////////
677
    MIOS32_LCD_DeviceSet(1);
678
    MIOS32_LCD_CursorSet(0, 0);
679
 
680
    MIOS32_LCD_PrintFormattedString("Step");
681
    SEQ_LCD_PrintSelectedStep(ui_selected_step, 15);
682
    MIOS32_LCD_PrintChar(':');
683
 
684
    SEQ_LCD_PrintNote(par_layer_value[visible_track][0][ui_selected_step]);
685
    MIOS32_LCD_PrintChar((char)par_layer_value[visible_track][1][ui_selected_step] >> 4);
686
    SEQ_LCD_PrintSpaces(1);
687
 
688
    MIOS32_LCD_PrintFormattedString("Vel:%3d", par_layer_value[visible_track][1][ui_selected_step]);
689
    SEQ_LCD_PrintSpaces(1);
690
 
691
    MIOS32_LCD_PrintFormattedString("Len:");
692
    SEQ_LCD_PrintGatelength(par_layer_value[visible_track][2][ui_selected_step]);
693
    SEQ_LCD_PrintSpaces(1);
694
 
695
    MIOS32_LCD_PrintFormattedString("G-a-r--");
696
 
697
    ///////////////////////////////////////////////////////////////////////////
698
    MIOS32_LCD_DeviceSet(0);
699
    MIOS32_LCD_CursorSet(0, 1);
700
 
701
    for(step=0; step<16; ++step) {
702
      // 9th step reached: switch to second LCD
703
      if( step == 8 ) {
704
        MIOS32_LCD_DeviceSet(1);
705
        MIOS32_LCD_CursorSet(0, 1);
706
      }
707
 
708
      u8 visible_step = step + 16*ui_selected_step_view;
709
      u8 note = par_layer_value[visible_track][0][visible_step];
710
      u8 vel = par_layer_value[visible_track][1][visible_step];
711
      u8 len = par_layer_value[visible_track][2][visible_step];
712
      u8 gate = trg_layer_value[visible_track][0][visible_step>>3] & (1 << (visible_step&7));
713
 
714
      switch( ui_selected_par_layer ) {
715
        case 0: // Note
716
        case 1: // Velocity
717
 
718
    if( gate ) {
719
      SEQ_LCD_PrintNote(note);
720
      MIOS32_LCD_PrintChar((char)vel >> 4);
721
    } else {
722
      MIOS32_LCD_PrintFormattedString("----");
723
    }
724
    break;
725
 
726
        case 2: // Gatelength
727
      // TODO: print length like on real hardware (length bars)
728
      SEQ_LCD_PrintGatelength(len);
729
      break;
730
        default:
731
      MIOS32_LCD_PrintFormattedString("????");
732
      }
733
 
734
      MIOS32_LCD_PrintChar(
735
          (visible_step == ui_selected_step) ? '<'
736
    : ((visible_step == ui_selected_step-1) ? '>' : ' '));
737
    }
738
  }
739
 
740
  return 0; // no error
741
}
742
 
743
 
744
 
745
/////////////////////////////////////////////////////////////////////////////
746
// Update all LEDs
747
// Usually called from background task
748
/////////////////////////////////////////////////////////////////////////////
749
s32 SEQ_UI_LED_Handler(void)
750
{
751
  u8 visible_track = SEQ_UI_VisibleTrackGet();
752
 
753
  // track LEDs
754
  SEQ_LED_PinSet(LED_TRACK1, (ui_selected_tracks & (1 << 0)) ? 1 : 0);
755
  SEQ_LED_PinSet(LED_TRACK2, (ui_selected_tracks & (1 << 1)) ? 1 : 0);
756
  SEQ_LED_PinSet(LED_TRACK3, (ui_selected_tracks & (1 << 2)) ? 1 : 0);
757
  SEQ_LED_PinSet(LED_TRACK4, (ui_selected_tracks & (1 << 3)) ? 1 : 0);
758
 
759
  // parameter layer LEDs
760
  SEQ_LED_PinSet(LED_PAR_LAYER_A, (ui_selected_par_layer == 0) ? 1 : 0);
761
  SEQ_LED_PinSet(LED_PAR_LAYER_B, (ui_selected_par_layer == 1) ? 1 : 0);
762
  SEQ_LED_PinSet(LED_PAR_LAYER_C, (ui_selected_par_layer == 2) ? 1 : 0);
763
 
764
  // group LEDs
765
  SEQ_LED_PinSet(LED_GROUP1, (ui_selected_group == 0) ? 1 : 0);
766
  SEQ_LED_PinSet(LED_GROUP2, (ui_selected_group == 1) ? 1 : 0);
767
  SEQ_LED_PinSet(LED_GROUP3, (ui_selected_group == 2) ? 1 : 0);
768
  SEQ_LED_PinSet(LED_GROUP4, (ui_selected_group == 3) ? 1 : 0);
769
 
770
  // trigger layer LEDs
771
  SEQ_LED_PinSet(LED_TRG_LAYER_A, (ui_selected_trg_layer == 0) ? 1 : 0);
772
  SEQ_LED_PinSet(LED_TRG_LAYER_B, (ui_selected_trg_layer == 1) ? 1 : 0);
773
  SEQ_LED_PinSet(LED_TRG_LAYER_C, (ui_selected_trg_layer == 2) ? 1 : 0);
774
 
775
  // remaining LEDs
776
  SEQ_LED_PinSet(LED_EDIT, 1);
777
  SEQ_LED_PinSet(LED_MUTE, 0);
778
  SEQ_LED_PinSet(LED_PATTERN, 0);
779
  SEQ_LED_PinSet(LED_SONG, 0);
780
 
781
  SEQ_LED_PinSet(LED_SOLO, 0);
782
  SEQ_LED_PinSet(LED_FAST, 0);
783
  SEQ_LED_PinSet(LED_ALL, 0);
784
 
785
  SEQ_LED_PinSet(LED_PLAY, 1);
786
  SEQ_LED_PinSet(LED_STOP, 0);
787
  SEQ_LED_PinSet(LED_PAUSE, 0);
788
 
789
  SEQ_LED_PinSet(LED_STEP_1_16, (ui_selected_step_view == 0) ? 1 : 0);
790
  SEQ_LED_PinSet(LED_STEP_17_32, (ui_selected_step_view == 1) ? 1 : 0); // will be obsolete in MBSEQ V4
791
 
792
  // write GP LED values into ui_gp_leds variable
793
  // will be transfered to DOUT registers in SEQ_UI_LED_Handler_Periodic
794
  ui_gp_leds =
795
    (trg_layer_value[visible_track][ui_selected_trg_layer][2*ui_selected_step_view+1] << 8) |
796
     trg_layer_value[visible_track][ui_selected_trg_layer][2*ui_selected_step_view+0];
797
 
798
  return 0; // no error
799
}
800
 
801
 
802
/////////////////////////////////////////////////////////////////////////////
803
// updates high-prio LED functions (GP LEDs and Beat LED)
804
// Called before SRIO update
805
/////////////////////////////////////////////////////////////////////////////
806
s32 SEQ_UI_LED_Handler_Periodic()
807
{
808
  // GP LEDs are only updated when ui_gp_leds or pos_marker_mask has changed
809
  static u16 prev_ui_gp_leds = 0x0000;
810
  static u16 prev_pos_marker_mask = 0x0000;
811
 
812
 
813
  // beat LED: tmp. for demo w/o real sequencer
814
  SEQ_LED_PinSet(LED_BEAT, ((played_step & 3) == 0) ? 1 : 0);
815
 
816
  // for song position marker (supports 16 LEDs, check for selected step view)
817
  u16 pos_marker_mask = 0x0000;
818
  if( (played_step >> 4) == ui_selected_step_view )
819
    pos_marker_mask = 1 << (played_step & 0xf);
820
 
821
  // exit of pattern hasn't changed
822
  if( prev_ui_gp_leds == ui_gp_leds && prev_pos_marker_mask == pos_marker_mask )
823
    return 0;
824
  prev_ui_gp_leds = ui_gp_leds;
825
  prev_pos_marker_mask = pos_marker_mask;
826
 
827
  // transfer to GP LEDs
828
 
829
#ifdef DEFAULT_GP_DOUT_SR_L
830
# ifdef DEFAULT_GP_DOUT_SR_L2
831
  SEQ_LED_SRSet(DEFAULT_GP_DOUT_SR_L-1, (ui_gp_leds >> 0) & 0xff);
832
# else
833
  SEQ_LED_SRSet(DEFAULT_GP_DOUT_SR_L-1, ((ui_gp_leds ^ pos_marker_mask) >> 0) & 0xff);
834
# endif
835
#endif
836
#ifdef DEFAULT_GP_DOUT_SR_R
837
# ifdef DEFAULT_GP_DOUT_SR_R2
838
  SEQ_LED_SRSet(DEFAULT_GP_DOUT_SR_R-1, (ui_gp_leds >> 8) & 0xff);
839
#else
840
  SEQ_LED_SRSet(DEFAULT_GP_DOUT_SR_R-1, ((ui_gp_leds ^ pos_marker_mask) >> 8) & 0xff);
841
#endif
842
#endif
843
 
844
#ifdef DEFAULT_GP_DOUT_SR_L2
845
  SEQ_LED_SRSet(DEFAULT_GP_DOUT_SR_L2-1, (pos_marker_mask >> 0) & 0xff);
846
#endif
847
#ifdef DEFAULT_GP_DOUT_SR_R2
848
  SEQ_LED_SRSet(DEFAULT_GP_DOUT_SR_R2-1, (pos_marker_mask >> 8) & 0xff);
849
#endif
850
 
851
#if DEFAULT_SRM_ENABLED && DEFAULT_SRM_DOUT_M_MAPPING == 1
852
  // for wilba's frontpanel
853
 
854
  // BLM8X8 DOUT -> GP LED mapping
855
  // 0 = 15,16  1 = 13,14   2 = 11,12   3 = 9,10
856
  // 4 = 1,2    5 = 3,4     6 = 5,6     7 = 7,8
857
 
858
  // bit 7: first green (i.e. GP1-G)
859
  // bit 6: first red (i.e. GP1-R)
860
  // bit 5: second green (i.e. GP2-G)
861
  // bit 4: second red (i.e. GP2-R)
862
 
863
  // this mapping routine takes ca. 5 uS
864
  // since it's only executed when ui_gp_leds or gp_mask has changed, it doesn't really hurt
865
 
866
  u16 modified_gp_leds = ui_gp_leds;
867
#if 1
868
  // extra: red LED is lit exclusively for higher contrast
869
  modified_gp_leds &= ~pos_marker_mask;
870
#endif
871
 
872
  int sr;
873
  const u8 blm8x8_sr_map[8] = {4, 5, 6, 7, 3, 2, 1, 0};
874
  u16 gp_mask = 1 << 0;
875
  for(sr=0; sr<8; ++sr) {
876
    u8 pattern = 0;
877
 
878
    if( modified_gp_leds & gp_mask )
879
      pattern |= 0x80;
880
    if( pos_marker_mask & gp_mask )
881
      pattern |= 0x40;
882
    gp_mask <<= 1;
883
    if( modified_gp_leds & gp_mask )
884
      pattern |= 0x20;
885
    if( pos_marker_mask & gp_mask )
886
      pattern |= 0x10;
887
    gp_mask <<= 1;
888
 
889
    u8 mapped_sr = blm8x8_sr_map[sr];
890
    blm8x8_led_row[mapped_sr] = (blm8x8_led_row[mapped_sr] & 0x0f) | pattern;
891
  }
892
#endif
893
 
894
}
895
 
896
 
897
/////////////////////////////////////////////////////////////////////////////
898
// Returns the currently visible track
899
/////////////////////////////////////////////////////////////////////////////
900
u8 SEQ_UI_VisibleTrackGet(void)
901
{
902
  u8 offset = 0;
903
 
904
  if( ui_selected_tracks & (1 << 3) )
905
    offset = 3;
906
  if( ui_selected_tracks & (1 << 2) )
907
    offset = 2;
908
  if( ui_selected_tracks & (1 << 1) )
909
    offset = 1;
910
  if( ui_selected_tracks & (1 << 0) )
911
    offset = 0;
912
 
913
  return 4*ui_selected_group + offset;
914
}
915