Subversion Repositories svn.mios32

Rev

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

Rev Author Line No. Line
174 tk 1
// $Id: seq_ui_trkevnt.c 174 2008-12-11 23:57:23Z tk $
2
/*
3
 * Track clock divider 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
#include "seq_layer.h"
23
 
24
 
25
/////////////////////////////////////////////////////////////////////////////
26
// Local definitions
27
/////////////////////////////////////////////////////////////////////////////
28
 
29
#define NUM_OF_ITEMS       8
30
#define ITEM_GXTY          0
31
#define ITEM_EVNT_MODE     1
32
#define ITEM_EVNT_CONST1   2
33
#define ITEM_EVNT_CONST2   3
34
#define ITEM_EVNT_CONST3   4
35
#define ITEM_MIDI_CHANNEL  5
36
#define ITEM_MIDI_PORT     6
37
#define ITEM_PRESET        7
38
 
39
 
40
/////////////////////////////////////////////////////////////////////////////
41
// Local LED handler function
42
/////////////////////////////////////////////////////////////////////////////
43
static s32 LED_Handler(u16 *gp_leds)
44
{
45
  if( ui_cursor_flash ) // if flashing flag active: no LED flag set
46
    return 0;
47
 
48
  switch( ui_selected_item ) {
49
    case ITEM_GXTY: *gp_leds = 0x0001; break;
50
    case ITEM_EVNT_MODE: *gp_leds = 0x001e; break;
51
    case ITEM_EVNT_CONST1: *gp_leds = 0x0020; break;
52
    case ITEM_EVNT_CONST2: *gp_leds = 0x0040; break;
53
    case ITEM_EVNT_CONST3: *gp_leds = 0x0080; break;
54
    case ITEM_MIDI_CHANNEL: *gp_leds = 0x0100; break;
55
    case ITEM_MIDI_PORT: *gp_leds = 0x0200; break;
56
    case ITEM_PRESET: *gp_leds = 0xc000; break;
57
  }
58
 
59
  return 0; // no error
60
}
61
 
62
 
63
/////////////////////////////////////////////////////////////////////////////
64
// Local encoder callback function
65
// Should return:
66
//   1 if value has been changed
67
//   0 if value hasn't been changed
68
//  -1 if invalid or unsupported encoder
69
/////////////////////////////////////////////////////////////////////////////
70
static s32 Encoder_Handler(seq_ui_encoder_t encoder, s32 incrementer)
71
{
72
  switch( encoder ) {
73
    case SEQ_UI_ENCODER_GP1:
74
      ui_selected_item = ITEM_GXTY;
75
      break;
76
 
77
    case SEQ_UI_ENCODER_GP2:
78
    case SEQ_UI_ENCODER_GP3:
79
    case SEQ_UI_ENCODER_GP4:
80
    case SEQ_UI_ENCODER_GP5:
81
      ui_selected_item = ITEM_EVNT_MODE;
82
      break;
83
 
84
    case SEQ_UI_ENCODER_GP6:
85
      ui_selected_item = ITEM_EVNT_CONST1;
86
      break;
87
 
88
    case SEQ_UI_ENCODER_GP7:
89
      ui_selected_item = ITEM_EVNT_CONST2;
90
      break;
91
 
92
    case SEQ_UI_ENCODER_GP8:
93
      ui_selected_item = ITEM_EVNT_CONST3;
94
      break;
95
 
96
    case SEQ_UI_ENCODER_GP9:
97
      ui_selected_item = ITEM_MIDI_CHANNEL;
98
      break;
99
 
100
    case SEQ_UI_ENCODER_GP10:
101
      ui_selected_item = ITEM_MIDI_PORT;
102
      break;
103
 
104
    case SEQ_UI_ENCODER_GP11:
105
    case SEQ_UI_ENCODER_GP12:
106
    case SEQ_UI_ENCODER_GP13:
107
    case SEQ_UI_ENCODER_GP14:
108
      return -1; // not mapped
109
 
110
    case SEQ_UI_ENCODER_GP15:
111
    case SEQ_UI_ENCODER_GP16:
112
      ui_selected_item = ITEM_PRESET;
113
      break;
114
  }
115
 
116
  // for GP encoders and Datawheel
117
  switch( ui_selected_item ) {
118
    case ITEM_GXTY:          return SEQ_UI_GxTyInc(incrementer);
119
    case ITEM_EVNT_MODE:     return SEQ_UI_CCInc(SEQ_CC_MIDI_EVNT_MODE, 0, SEQ_LAYER_EVNTMODE_NUM-1, incrementer);
120
    case ITEM_EVNT_CONST1:   return SEQ_UI_CCInc(SEQ_CC_MIDI_EVNT_CONST1, 0, 127, incrementer);
121
    case ITEM_EVNT_CONST2:   return SEQ_UI_CCInc(SEQ_CC_MIDI_EVNT_CONST2, 0, 127, incrementer);
122
    case ITEM_EVNT_CONST3:   return SEQ_UI_CCInc(SEQ_CC_MIDI_EVNT_CONST3, 0, 127, incrementer);
123
    case ITEM_MIDI_CHANNEL: return SEQ_UI_CCInc(SEQ_CC_MIDI_CHANNEL, 0, 15, incrementer);
124
    case ITEM_MIDI_PORT: return SEQ_UI_CCInc(SEQ_CC_MIDI_PORT, 0, 3, incrementer); // TODO: use global define for number of MIDI ports!
125
    case ITEM_PRESET: return -1; // TODO
126
  }
127
 
128
  return -1; // invalid or unsupported encoder
129
}
130
 
131
 
132
/////////////////////////////////////////////////////////////////////////////
133
// Local button callback function
134
// Should return:
135
//   1 if value has been changed
136
//   0 if value hasn't been changed
137
//  -1 if invalid or unsupported button
138
/////////////////////////////////////////////////////////////////////////////
139
static s32 Button_Handler(seq_ui_button_t button, s32 depressed)
140
{
141
  if( depressed ) return 0; // ignore when button depressed
142
 
143
  u8 visible_track = SEQ_UI_VisibleTrackGet();
144
 
145
  switch( button ) {
146
    case SEQ_UI_BUTTON_GP1:
147
      ui_selected_item = ITEM_GXTY;
148
      return 0; // value hasn't been changed
149
 
150
    case SEQ_UI_BUTTON_GP2:
151
    case SEQ_UI_BUTTON_GP3:
152
    case SEQ_UI_BUTTON_GP4:
153
    case SEQ_UI_BUTTON_GP5:
154
      ui_selected_item = ITEM_EVNT_MODE;
155
      return 0; // value hasn't been changed
156
 
157
    case SEQ_UI_BUTTON_GP6:
158
      ui_selected_item = ITEM_EVNT_CONST1;
159
      return 0; // value hasn't been changed
160
 
161
    case SEQ_UI_BUTTON_GP7:
162
      ui_selected_item = ITEM_EVNT_CONST2;
163
      return 0; // value hasn't been changed
164
 
165
    case SEQ_UI_BUTTON_GP8:
166
      ui_selected_item = ITEM_EVNT_CONST3;
167
      return 0; // value hasn't been changed
168
 
169
    case SEQ_UI_BUTTON_GP9:
170
      ui_selected_item = ITEM_MIDI_CHANNEL;
171
      return 0; // value hasn't been changed
172
 
173
    case SEQ_UI_BUTTON_GP10:
174
      ui_selected_item = ITEM_MIDI_CHANNEL;
175
      return 0; // value hasn't been changed
176
 
177
    case SEQ_UI_BUTTON_GP11:
178
    case SEQ_UI_BUTTON_GP12:
179
    case SEQ_UI_BUTTON_GP13:
180
    case SEQ_UI_BUTTON_GP14:
181
      return -1;
182
 
183
    case SEQ_UI_BUTTON_GP15:
184
    case SEQ_UI_BUTTON_GP16:
185
      return -1; // TODO: copy preset!
186
 
187
    case SEQ_UI_BUTTON_Select:
188
    case SEQ_UI_BUTTON_Right:
189
      if( ++ui_selected_item >= NUM_OF_ITEMS )
190
    ui_selected_item = 0;
191
      return 1; // value always changed
192
 
193
    case SEQ_UI_BUTTON_Left:
194
      if( ui_selected_item == 0 )
195
    ui_selected_item = NUM_OF_ITEMS-1;
196
      return 1; // value always changed
197
 
198
    case SEQ_UI_BUTTON_Up:
199
      return Encoder_Handler(SEQ_UI_ENCODER_Datawheel, 1);
200
 
201
    case SEQ_UI_BUTTON_Down:
202
      return Encoder_Handler(SEQ_UI_ENCODER_Datawheel, -1);
203
  }
204
 
205
  return -1; // invalid or unsupported button
206
}
207
 
208
 
209
/////////////////////////////////////////////////////////////////////////////
210
// Local Display Handler function
211
// IN: <high_prio>: if set, a high-priority LCD update is requested
212
/////////////////////////////////////////////////////////////////////////////
213
static s32 LCD_Handler(u8 high_prio)
214
{
215
  if( high_prio )
216
    return 0; // there are no high-priority updates
217
 
218
  // layout:
219
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
220
  // 01234567890123456789012345678901234567890123456789012345678901234567890123456789
221
  // <--------------------------------------><-------------------------------------->
222
  // Trk. Layer Assignments:xx Val1 Val2 Val3Chn. Port                     >> COPY <<
223
  // G1T1 A:Chrd B:Vel. C:Len.  127  127  127 16  IIC2 (not available)     > PRESET <
224
 
225
  u8 visible_track = SEQ_UI_VisibleTrackGet();
226
  u8 evnt_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVNT_MODE);
227
 
228
  ///////////////////////////////////////////////////////////////////////////
229
  MIOS32_LCD_DeviceSet(0);
230
  MIOS32_LCD_CursorSet(0, 0);
231
  MIOS32_LCD_PrintString("Trk. Layer Assignments:");
232
  ///
233
  if( ui_selected_item == ITEM_EVNT_MODE && ui_cursor_flash ) {
234
    SEQ_LCD_PrintSpaces(2);
235
  } else {
236
    MIOS32_LCD_PrintFormattedString("%2d", evnt_mode + 1);
237
  }
238
  MIOS32_LCD_PrintFormattedString(" %s %s %s",
239
                  SEQ_LAYER_CTypeStr(evnt_mode, 0),
240
                  SEQ_LAYER_CTypeStr(evnt_mode, 1),
241
                  SEQ_LAYER_CTypeStr(evnt_mode, 2));
242
  ///
243
  MIOS32_LCD_PrintString(" Val1 Val2 Val3");
244
  MIOS32_LCD_DeviceSet(1);
245
  MIOS32_LCD_CursorSet(0, 0);
246
  MIOS32_LCD_PrintString("Chn. Port                     >> COPY <<");
247
 
248
 
249
  ///////////////////////////////////////////////////////////////////////////
250
  MIOS32_LCD_DeviceSet(0);
251
  MIOS32_LCD_CursorSet(0, 1);
252
 
253
  if( ui_selected_item == ITEM_GXTY && ui_cursor_flash ) {
254
    SEQ_LCD_PrintSpaces(5);
255
  } else {
256
    SEQ_LCD_PrintGxTy(ui_selected_group, ui_selected_tracks);
257
    SEQ_LCD_PrintSpaces(1);
258
  }
259
 
260
  ///////////////////////////////////////////////////////////////////////////
261
  MIOS32_LCD_PrintString((ui_selected_item == ITEM_EVNT_MODE && ui_cursor_flash) ? "  " : "A:");
262
  MIOS32_LCD_PrintString(SEQ_LAYER_VTypeStr(evnt_mode, 0));
263
  SEQ_LCD_PrintSpaces(1);
264
 
265
  MIOS32_LCD_PrintString((ui_selected_item == ITEM_EVNT_MODE && ui_cursor_flash) ? "  " : "B:");
266
  MIOS32_LCD_PrintString(SEQ_LAYER_VTypeStr(evnt_mode, 1));
267
  SEQ_LCD_PrintSpaces(1);
268
 
269
  MIOS32_LCD_PrintString((ui_selected_item == ITEM_EVNT_MODE && ui_cursor_flash) ? "  " : "C:");
270
  MIOS32_LCD_PrintString(SEQ_LAYER_VTypeStr(evnt_mode, 2));
271
 
272
 
273
  ///////////////////////////////////////////////////////////////////////////
274
  if( ui_selected_item == ITEM_EVNT_CONST1 && ui_cursor_flash ) {
275
    SEQ_LCD_PrintSpaces(5);
276
  } else {
277
    MIOS32_LCD_PrintFormattedString("  %3d", SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVNT_CONST1));
278
  }
279
 
280
  ///////////////////////////////////////////////////////////////////////////
281
  if( ui_selected_item == ITEM_EVNT_CONST2 && ui_cursor_flash ) {
282
    SEQ_LCD_PrintSpaces(5);
283
  } else {
284
    MIOS32_LCD_PrintFormattedString("  %3d", SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVNT_CONST2));
285
  }
286
 
287
  ///////////////////////////////////////////////////////////////////////////
288
  if( ui_selected_item == ITEM_EVNT_CONST3 && ui_cursor_flash ) {
289
    SEQ_LCD_PrintSpaces(5);
290
  } else {
291
    MIOS32_LCD_PrintFormattedString("  %3d", SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVNT_CONST3));
292
  }
293
 
294
  ///////////////////////////////////////////////////////////////////////////
295
  MIOS32_LCD_DeviceSet(1);
296
  MIOS32_LCD_CursorSet(0, 1);
297
  if( ui_selected_item == ITEM_MIDI_CHANNEL && ui_cursor_flash ) {
298
    SEQ_LCD_PrintSpaces(5);
299
  } else {
300
    MIOS32_LCD_PrintFormattedString("%3d  ", SEQ_CC_Get(visible_track, SEQ_CC_MIDI_CHANNEL)+1);
301
  }
302
 
303
  ///////////////////////////////////////////////////////////////////////////
304
  if( ui_selected_item == ITEM_MIDI_PORT && ui_cursor_flash ) {
305
    SEQ_LCD_PrintSpaces(5);
306
  } else {
307
    MIOS32_LCD_PrintFormattedString("0x%02x ", SEQ_CC_Get(visible_track, SEQ_CC_MIDI_PORT)); // TODO: get MIDI port name from SEQ_MIDI
308
  }
309
#if 0
310
  MIOS32_LCD_PrintString(1 ? "(not available)" : "(available)    "); // TODO: get MIDI port availability from SEQ_MIDI
311
#else
312
  SEQ_LCD_PrintSpaces(15);
313
#endif
314
 
315
  ///////////////////////////////////////////////////////////////////////////
316
  MIOS32_LCD_PrintString("     > PRESET <");
317
 
318
 
319
  return 0; // no error
320
}
321
 
322
 
323
/////////////////////////////////////////////////////////////////////////////
324
// Initialisation
325
/////////////////////////////////////////////////////////////////////////////
326
s32 SEQ_UI_TRKEVNT_Init(u32 mode)
327
{
328
  // install callback routines
329
  SEQ_UI_InstallButtonCallback(Button_Handler);
330
  SEQ_UI_InstallEncoderCallback(Encoder_Handler);
331
  SEQ_UI_InstallLEDCallback(LED_Handler);
332
  SEQ_UI_InstallLCDCallback(LCD_Handler);
333
 
334
  return 0; // no error
335
}