Subversion Repositories svn.mios32

Rev

Rev 2449 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
180 tk 1
// $Id: seq_ui_trkmode.c 2465 2016-12-20 18:54:40Z tk $
2
/*
3
 * Track mode page
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
#include "seq_lcd.h"
20
#include "seq_ui.h"
21
#include "seq_cc.h"
22
 
23
 
24
/////////////////////////////////////////////////////////////////////////////
25
// Local definitions
26
/////////////////////////////////////////////////////////////////////////////
27
 
2465 tk 28
#define NUM_OF_ITEMS       10
180 tk 29
#define ITEM_GXTY          0
30
#define ITEM_MODE          1
1023 tk 31
#define ITEM_BUS           2
2449 tk 32
#define ITEM_FIRST_NOTE    3
33
#define ITEM_HOLD          4
34
#define ITEM_SORT          5
35
#define ITEM_RESTART       6
2465 tk 36
#define ITEM_STEP_TRG      7
37
#define ITEM_FORCE_SCALE   8
38
#define ITEM_SUSTAIN       9
180 tk 39
 
40
 
41
/////////////////////////////////////////////////////////////////////////////
42
// Local LED handler function
43
/////////////////////////////////////////////////////////////////////////////
44
static s32 LED_Handler(u16 *gp_leds)
45
{
46
  if( ui_cursor_flash ) // if flashing flag active: no LED flag set
47
    return 0;
48
 
49
  switch( ui_selected_item ) {
50
    case ITEM_GXTY: *gp_leds = 0x0001; break;
51
    case ITEM_MODE: {
52
      int selected_mode = SEQ_CC_Get(SEQ_UI_VisibleTrackGet(), SEQ_CC_MODE);
53
      *gp_leds = (1 << (selected_mode+1));
54
      }
55
      break;
1023 tk 56
    case ITEM_BUS:         *gp_leds = 0x0080; break;
2449 tk 57
    case ITEM_FIRST_NOTE:  *gp_leds = 0x0100; break;
58
    case ITEM_HOLD:        *gp_leds = 0x0200; break;
59
    case ITEM_SORT:        *gp_leds = 0x0400; break;
60
    case ITEM_RESTART:     *gp_leds = 0x0800; break;
2465 tk 61
    case ITEM_STEP_TRG:    *gp_leds = 0x1000; break;
62
    case ITEM_FORCE_SCALE: *gp_leds = 0x2000; break;
180 tk 63
    case ITEM_SUSTAIN:     *gp_leds = 0xc000; break;
64
  }
65
 
66
  return 0; // no error
67
}
68
 
69
 
70
/////////////////////////////////////////////////////////////////////////////
71
// Local encoder callback function
72
// Should return:
73
//   1 if value has been changed
74
//   0 if value hasn't been changed
75
//  -1 if invalid or unsupported encoder
76
/////////////////////////////////////////////////////////////////////////////
77
static s32 Encoder_Handler(seq_ui_encoder_t encoder, s32 incrementer)
78
{
1023 tk 79
  u8 visible_track = SEQ_UI_VisibleTrackGet();
80
 
180 tk 81
  switch( encoder ) {
82
    case SEQ_UI_ENCODER_GP1:
83
      ui_selected_item = ITEM_GXTY;
84
      break;
85
 
86
    case SEQ_UI_ENCODER_GP2:
87
    case SEQ_UI_ENCODER_GP3:
88
    case SEQ_UI_ENCODER_GP4:
89
    case SEQ_UI_ENCODER_GP5:
90
      ui_selected_item = ITEM_MODE;
91
      SEQ_UI_CC_Set(SEQ_CC_MODE, encoder-1);
92
      return 1;
93
 
94
    case SEQ_UI_ENCODER_GP6:
95
    case SEQ_UI_ENCODER_GP7:
96
      return -1; // not mapped
97
 
1023 tk 98
    case SEQ_UI_ENCODER_GP8:
99
      ui_selected_item = ITEM_BUS;
100
      break;
101
 
180 tk 102
    case SEQ_UI_ENCODER_GP9:
2449 tk 103
      ui_selected_item = ITEM_FIRST_NOTE;
104
      break;
105
 
106
    case SEQ_UI_ENCODER_GP10:
180 tk 107
      ui_selected_item = ITEM_HOLD;
108
      break;
109
 
2449 tk 110
    case SEQ_UI_ENCODER_GP11:
180 tk 111
      ui_selected_item = ITEM_SORT;
112
      break;
113
 
114
    case SEQ_UI_ENCODER_GP12:
115
      ui_selected_item = ITEM_RESTART;
116
      break;
117
 
118
    case SEQ_UI_ENCODER_GP13:
2465 tk 119
      ui_selected_item = ITEM_STEP_TRG;
120
      break;
121
 
180 tk 122
    case SEQ_UI_ENCODER_GP14:
123
      ui_selected_item = ITEM_FORCE_SCALE;
124
      break;
125
 
126
    case SEQ_UI_ENCODER_GP15:
127
    case SEQ_UI_ENCODER_GP16:
128
      ui_selected_item = ITEM_SUSTAIN;
129
      break;
130
  }
131
 
132
  // for GP encoders and Datawheel
133
  switch( ui_selected_item ) {
1023 tk 134
    case ITEM_GXTY:
135
      return SEQ_UI_GxTyInc(incrementer);
136
 
137
    case ITEM_MODE:
138
      return SEQ_UI_CC_Inc(SEQ_CC_MODE, 0, 3, incrementer);
139
 
140
    case ITEM_BUS:
141
      return SEQ_UI_CC_Inc(SEQ_CC_BUSASG, 0, 3, incrementer);
142
 
2449 tk 143
    case ITEM_FIRST_NOTE:
144
      if( !incrementer ) // toggle flag
145
    incrementer = (SEQ_CC_Get(visible_track, SEQ_CC_MODE_FLAGS) & (1<<5)) ? -1 : 1;
146
      return SEQ_UI_CC_SetFlags(SEQ_CC_MODE_FLAGS, (1<<5), (incrementer >= 0) ? (1<<5) : 0);
147
 
1023 tk 148
    case ITEM_HOLD:
149
      if( !incrementer ) // toggle flag
150
    incrementer = (SEQ_CC_Get(visible_track, SEQ_CC_MODE_FLAGS) & (1<<1)) ? -1 : 1;
151
      return SEQ_UI_CC_SetFlags(SEQ_CC_MODE_FLAGS, (1<<1), (incrementer >= 0) ? (1<<1) : 0);
152
 
153
    case ITEM_SORT:
154
      if( !incrementer ) // toggle flag - SORT is inverted!
155
    incrementer = (SEQ_CC_Get(visible_track, SEQ_CC_MODE_FLAGS) & (1<<0)) ? 1 : -1;
156
      return SEQ_UI_CC_SetFlags(SEQ_CC_MODE_FLAGS, (1<<0), (incrementer >= 0) ? 0 : (1<<0)); // SORT is inverted!
157
 
158
    case ITEM_RESTART:
159
      if( !incrementer ) // toggle flag
160
    incrementer = (SEQ_CC_Get(visible_track, SEQ_CC_MODE_FLAGS) & (1<<2)) ? -1 : 1;
161
      return SEQ_UI_CC_SetFlags(SEQ_CC_MODE_FLAGS, (1<<2), (incrementer >= 0) ? (1<<2) : 0);
162
 
2465 tk 163
    case ITEM_STEP_TRG:
164
      if( !incrementer ) // toggle flag
165
    incrementer = (SEQ_CC_Get(visible_track, SEQ_CC_MODE_FLAGS) & (1<<6)) ? -1 : 1;
166
      return SEQ_UI_CC_SetFlags(SEQ_CC_MODE_FLAGS, (1<<6), (incrementer >= 0) ? (1<<6) : 0);
167
 
1023 tk 168
    case ITEM_FORCE_SCALE:
169
      if( !incrementer ) // toggle flag
170
    incrementer = (SEQ_CC_Get(visible_track, SEQ_CC_MODE_FLAGS) & (1<<3)) ? -1 : 1;
171
      return SEQ_UI_CC_SetFlags(SEQ_CC_MODE_FLAGS, (1<<3), (incrementer >= 0) ? (1<<3) : 0);
172
 
173
    case ITEM_SUSTAIN:
174
      if( !incrementer ) // toggle flag
175
    incrementer = (SEQ_CC_Get(visible_track, SEQ_CC_MODE_FLAGS) & (1<<4)) ? -1 : 1;
176
      return SEQ_UI_CC_SetFlags(SEQ_CC_MODE_FLAGS, (1<<4), (incrementer >= 0) ? (1<<4) : 0);
180 tk 177
  }
178
 
179
  return -1; // invalid or unsupported encoder
180
}
181
 
182
 
183
/////////////////////////////////////////////////////////////////////////////
184
// Local button callback function
185
// Should return:
186
//   1 if value has been changed
187
//   0 if value hasn't been changed
188
//  -1 if invalid or unsupported button
189
/////////////////////////////////////////////////////////////////////////////
190
static s32 Button_Handler(seq_ui_button_t button, s32 depressed)
191
{
192
  if( depressed ) return 0; // ignore when button depressed
193
 
1023 tk 194
  if( button <= SEQ_UI_BUTTON_GP16 ) {
195
    // -> forward to encoder handler
196
    return Encoder_Handler((int)button, 0);
197
  }
180 tk 198
 
199
  switch( button ) {
200
    case SEQ_UI_BUTTON_Select:
201
    case SEQ_UI_BUTTON_Right:
202
      if( ++ui_selected_item >= NUM_OF_ITEMS )
203
    ui_selected_item = 0;
204
      return 1; // value always changed
205
 
206
    case SEQ_UI_BUTTON_Left:
207
      if( ui_selected_item == 0 )
208
    ui_selected_item = NUM_OF_ITEMS-1;
1142 tk 209
      else
210
    --ui_selected_item;
180 tk 211
      return 1; // value always changed
212
 
213
    case SEQ_UI_BUTTON_Up:
214
      return Encoder_Handler(SEQ_UI_ENCODER_Datawheel, 1);
215
 
216
    case SEQ_UI_BUTTON_Down:
217
      return Encoder_Handler(SEQ_UI_ENCODER_Datawheel, -1);
218
  }
219
 
220
  return -1; // invalid or unsupported button
221
}
222
 
223
 
224
/////////////////////////////////////////////////////////////////////////////
225
// Local Display Handler function
226
// IN: <high_prio>: if set, a high-priority LCD update is requested
227
/////////////////////////////////////////////////////////////////////////////
228
static s32 LCD_Handler(u8 high_prio)
229
{
230
  if( high_prio )
231
    return 0; // there are no high-priority updates
232
 
233
  // layout:
234
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
235
  // 01234567890123456789012345678901234567890123456789012345678901234567890123456789
236
  // <--------------------------------------><-------------------------------------->
2465 tk 237
  // Trk. off     Transpose              Bus Note  Hold Sort ReSt. STrg  FTS  Sustain
238
  // G1T1   >Normal<  Arpeggiator         1  First  on   on   on    on   on     on
180 tk 239
 
240
  u8 visible_track = SEQ_UI_VisibleTrackGet();
241
 
242
  ///////////////////////////////////////////////////////////////////////////
278 tk 243
  SEQ_LCD_CursorSet(0, 0);
244
  SEQ_LCD_PrintString("Trk.");
180 tk 245
 
278 tk 246
  SEQ_LCD_CursorSet(0, 1);
180 tk 247
  if( ui_selected_item == ITEM_GXTY && ui_cursor_flash ) {
306 tk 248
    SEQ_LCD_PrintSpaces(9);
180 tk 249
  } else {
250
    SEQ_LCD_PrintGxTy(ui_selected_group, ui_selected_tracks);
306 tk 251
    SEQ_LCD_PrintSpaces(5);
180 tk 252
  }
253
 
254
  ///////////////////////////////////////////////////////////////////////////
255
  const char mode_names[7][14] = {
256
    ">off<        ",
257
    ">Normal<     ",
258
    ">Transpose<  ",
259
    ">Arpeggiator<"
260
  };
261
  int i;
262
  int selected_mode = SEQ_CC_Get(visible_track, SEQ_CC_MODE);
263
  for(i=0; i<4; ++i) {
264
    u8 x = 4 + 5*i;
278 tk 265
    SEQ_LCD_CursorSet(x, i%2);
180 tk 266
 
267
    // print unmodified name if item selected
268
    // replace '>' and '<' by space if item not selected
269
    // flash item (print only '>'/'<' and spaces) if cursor position == 1 and flash flag set by timer
270
    int j;
271
    for(j=0; j<13; ++j) {
272
      u8 c = mode_names[i][j];
273
 
1023 tk 274
      if( ++x > 35 ) // don't print more than 35 characters per line
180 tk 275
    break;
276
 
277
      if( c == '>' || c == '<' ) {
278 tk 278
    SEQ_LCD_PrintChar((i == selected_mode) ? c : ' ');
180 tk 279
      } else {
280
    if( ui_selected_item == ITEM_MODE && i == selected_mode && ui_cursor_flash )
278 tk 281
      SEQ_LCD_PrintChar(' ');
180 tk 282
    else
278 tk 283
      SEQ_LCD_PrintChar(c);
180 tk 284
      }
285
    }
286
  }
287
 
288
  // additional spaces to fill LCD (avoids artefacts on page switches)
278 tk 289
  SEQ_LCD_CursorSet(25, 0);
180 tk 290
  SEQ_LCD_PrintSpaces(15);
278 tk 291
  SEQ_LCD_CursorSet(32, 1);
180 tk 292
  SEQ_LCD_PrintSpaces(8);
293
 
294
  ///////////////////////////////////////////////////////////////////////////
1023 tk 295
  SEQ_LCD_CursorSet(35, 0);
2465 tk 296
  SEQ_LCD_PrintString(" Bus Note  Hold Sort ReSt. STrg  FTS  Sustain");
1023 tk 297
  SEQ_LCD_CursorSet(35, 1);
180 tk 298
 
299
  ///////////////////////////////////////////////////////////////////////////
1023 tk 300
  if( ui_selected_item == ITEM_BUS && ui_cursor_flash ) {
301
    SEQ_LCD_PrintSpaces(3);
302
  } else {
303
    SEQ_LCD_PrintFormattedString("  %d", SEQ_CC_Get(visible_track, SEQ_CC_BUSASG) + 1);
304
  }
2449 tk 305
  SEQ_LCD_PrintSpaces(2);
1023 tk 306
 
307
  ///////////////////////////////////////////////////////////////////////////
2449 tk 308
  if( ui_selected_item == ITEM_FIRST_NOTE && ui_cursor_flash ) {
309
    SEQ_LCD_PrintSpaces(5);
310
  } else {
311
    SEQ_LCD_PrintString((SEQ_CC_Get(visible_track, SEQ_CC_MODE_FLAGS) & (1 << 5)) ? "First" : "Last ");
312
  }
313
  SEQ_LCD_PrintSpaces(2);
314
 
315
  ///////////////////////////////////////////////////////////////////////////
339 tk 316
  if( ui_selected_item == ITEM_HOLD && ui_cursor_flash ) {
317
    SEQ_LCD_PrintSpaces(3);
318
  } else {
319
    SEQ_LCD_PrintString((SEQ_CC_Get(visible_track, SEQ_CC_MODE_FLAGS) & (1 << 1)) ? "on " : "off");
320
  }
321
  SEQ_LCD_PrintSpaces(2);
180 tk 322
 
339 tk 323
  ///////////////////////////////////////////////////////////////////////////
324
  if( ui_selected_item == ITEM_SORT && ui_cursor_flash ) {
325
    SEQ_LCD_PrintSpaces(3);
326
  } else {
327
    SEQ_LCD_PrintString((SEQ_CC_Get(visible_track, SEQ_CC_MODE_FLAGS) & (1 << 0)) ? "off" : "on "); // SORT is inverted!
328
  }
2449 tk 329
  SEQ_LCD_PrintSpaces(2);
339 tk 330
 
331
  ///////////////////////////////////////////////////////////////////////////
332
  if( ui_selected_item == ITEM_RESTART && ui_cursor_flash ) {
333
    SEQ_LCD_PrintSpaces(3);
334
  } else {
335
    SEQ_LCD_PrintString((SEQ_CC_Get(visible_track, SEQ_CC_MODE_FLAGS) & (1 << 2)) ? "on " : "off");
336
  }
2465 tk 337
  SEQ_LCD_PrintSpaces(3);
339 tk 338
 
339
  ///////////////////////////////////////////////////////////////////////////
2465 tk 340
  if( ui_selected_item == ITEM_STEP_TRG && ui_cursor_flash ) {
341
    SEQ_LCD_PrintSpaces(3);
342
  } else {
343
    SEQ_LCD_PrintString((SEQ_CC_Get(visible_track, SEQ_CC_MODE_FLAGS) & (1 << 6)) ? "on " : "off");
344
  }
345
  SEQ_LCD_PrintSpaces(2);
346
 
347
  ///////////////////////////////////////////////////////////////////////////
339 tk 348
  if( ui_selected_item == ITEM_FORCE_SCALE && ui_cursor_flash ) {
349
    SEQ_LCD_PrintSpaces(3);
350
  } else {
351
    SEQ_LCD_PrintString((SEQ_CC_Get(visible_track, SEQ_CC_MODE_FLAGS) & (1 << 3)) ? "on " : "off");
352
  }
2465 tk 353
  SEQ_LCD_PrintSpaces(4);
339 tk 354
 
355
  ///////////////////////////////////////////////////////////////////////////
356
  if( ui_selected_item == ITEM_SUSTAIN && ui_cursor_flash ) {
357
    SEQ_LCD_PrintSpaces(3);
358
  } else {
359
    SEQ_LCD_PrintString((SEQ_CC_Get(visible_track, SEQ_CC_MODE_FLAGS) & (1 << 4)) ? "on " : "off");
360
  }
2449 tk 361
  SEQ_LCD_PrintSpaces(2);
339 tk 362
 
180 tk 363
  return 0; // no error
364
}
365
 
366
 
367
/////////////////////////////////////////////////////////////////////////////
368
// Initialisation
369
/////////////////////////////////////////////////////////////////////////////
370
s32 SEQ_UI_TRKMODE_Init(u32 mode)
371
{
372
  // install callback routines
373
  SEQ_UI_InstallButtonCallback(Button_Handler);
374
  SEQ_UI_InstallEncoderCallback(Encoder_Handler);
375
  SEQ_UI_InstallLEDCallback(LED_Handler);
376
  SEQ_UI_InstallLCDCallback(LCD_Handler);
377
 
378
  return 0; // no error
379
}