Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
7940 leency 1
 
2
 * Author: JohnXenox aka Aleksandr Igorevich.
3
 *
4
 * Programme name: Beat
5
 * Description: A simple metronome.
6
 */
7
8
 
9
#include 
10
#include 
11
12
 
13
14
 
15
16
 
17
unsigned int btn = 0;
18
19
 
20
21
 
22
int stack_size = 0x100;
23
24
 
25
 
26
27
 
28
29
 
30
31
 
32
33
 
34
35
 
36
 
37
38
 
39
40
 
41
 
42
enum EVENT_MASKS
43
{
44
     EVM_REDRAW =        0x00000001,
45
     EVM_KEY =           0x00000002,
46
     EVM_BUTTON =        0x00000004,
47
     EVM_EXIT =          0x00000008,
48
     EVM_BACKGROUND =    0x00000016,
49
     EVM_MOUSE =         0x00000032,
50
     EVM_IPC =           0x00000064,
51
     EVM_STACK =         0x00000128,
52
     EVM_DEBUG =         0x00000256,
53
     EVM_STACK2 =        0x00000512,
54
     EVM_MOUSE_FILTER =  0x80000000,
55
     EVM_CURSOR_FILTER = 0x40000000
56
};
57
58
 
59
 
60
 
61
{
62
     EVENT_REDRAW = 1,   /* Window and window elements should be redrawn */
63
     EVENT_KEY = 2,      /* A key on the keyboard was pressed */
64
     EVENT_BUTTON = 3,   /* A button was clicked with the mouse */
65
     EVENT_MOUSE = 6     /* Mouse activity (movement, button press) was detected */
66
};
67
68
 
69
 
70
{
71
    int frame;             // color of frame.
72
    int grab;              // color of header.
73
    int grab_button;       // color of button on header bar.
74
    int grab_button_text;  // color of text on button on header bar.
75
    int grab_text;         // color of text on header.
76
    int work;              // color of working area.
77
    int work_button;       // color of button in working area.
78
    int work_button_text;  // color of text on button in working area.
79
    int work_text;         // color of text in working area.
80
    int work_graph;        // color of graphics in working area.
81
};
82
83
 
84
 
85
86
 
87
#include "Beat_lib.h"
88
89
 
90
 
91
#define  KEY_ARROW_DOWN   0xB1
92
#define  KEY_ARROW_LEFT   0xB0
93
#define  KEY_ARROW_RIGHT  0xB3
94
95
 
96
#define  KEYS_CTRL_ARROW_DOWN   0x51
97
#define  KEYS_CTRL_ARROW_LEFT   0x50
98
#define  KEYS_CTRL_ARROW_RIGHT  0x53
99
100
 
101
102
 
103
104
 
105
106
 
107
 
108
 
109
 
110
111
 
112
 
113
#define SMPL_NAME2 "Beep2.raw"
114
#define PRG_NAME "PlayNote"
115
116
 
117
char _path_to_a_sample2[4096] = {0};
118
char _path_to_a_playnote[4096] = {0};
119
120
 
121
122
 
123
_path_to_a_playnote,
124
"/sys/"PRG_NAME,
125
"/sys/Media/"PRG_NAME,
126
};
127
128
 
129
130
 
131
 
132
 
133
{
134
    setCurrentPathToARawFile(_path_to_a_sample1, argv[0], SMPL_NAME1);
135
    setCurrentPathToARawFile(_path_to_a_sample2, argv[0], SMPL_NAME2);
136
    setCurrentPathToARawFile(_path_to_a_playnote, argv[0], PRG_NAME);
137
138
 
139
    for(char i = 0; (i < SEARCH_PATHES_NUMBER); i++)
140
    {
141
        if(startApp("/sys/loool.raw", 0, search_pathes_to_a_playnote[i]) > 0)
142
        {
143
            path_to_a_playnote = search_pathes_to_a_playnote[i];
144
        }
145
    }
146
147
 
148
    {
149
        #if defined (lang_en)
150
            startApp("\"Can't find a PlayNote programme!\" -W", 0, "/sys/@notify");
151
        #elif defined (lang_ru)
152
            startApp("\"Не могу найти программу PlayNote!\" -W", 0, "/sys/@notify");
153
        #endif
154
155
 
156
    }
157
158
 
159
160
 
161
 
162
 
163
 
164
 
165
166
 
167
    {
168
169
 
170
        {
171
172
 
173
            {
174
175
 
176
177
 
178
                    counter++;
179
                else if(counter == meter)
180
                    counter = 1;
181
182
 
183
 
184
 
185
                {
186
                    // play a beep sound.
187
                    startApp(_path_to_a_sample2, 0, path_to_a_playnote);
188
                }
189
                else
190
                {
191
                    // play a beep sound.
192
                    startApp(_path_to_a_sample1, 0, path_to_a_playnote);
193
                }
194
195
 
196
 
197
 
198
 
199
200
 
201
 
202
203
 
204
            else
205
            {
206
                redraw_flag = 0;
207
            }
208
209
 
210
211
 
212
        {
213
            case EVENT_REDRAW:
214
215
 
216
217
 
218
                   break;
219
220
 
221
                   ctrl_keys_state = getControlKeysOnAKeyboard();
222
223
 
224
                   key = _ksys_get_key();
225
226
 
227
228
 
229
 
230
231
 
232
                   if(key == KEY_ESCAPE) return 0;
233
234
 
235
                   if(key == KEY_SPACE)
236
                   {
237
                       if(startButtonBit == 0)
238
                           startButtonBit = 1;
239
                       else
240
                           startButtonBit = 0;
241
242
 
243
                   }
244
245
 
246
 
247
                   if(key == KEY_ARROW_LEFT)
248
                   {
249
                       if(tempo != 1)
250
                       {
251
                           showTempoBar2(--tempo);
252
                           setTempoSelectorByTempo(&tempo, &tempoSelector);
253
254
 
255
                   }
256
257
 
258
                   if(key == KEY_ARROW_RIGHT)
259
                   {
260
                       if(tempo != 320)
261
                       {
262
                           showTempoBar2(++tempo);
263
                           setTempoSelectorByTempo(&tempo, &tempoSelector);
264
                       }
265
                   }
266
267
 
268
 
269
                   if(key == KEYS_CTRL_ARROW_LEFT)
270
                   {
271
                       if ((ctrl_keys_state == 4) || (ctrl_keys_state == 8))
272
                       {
273
                           if(tempoSelector != 0)
274
                           {
275
                               showTempoBar1(--tempoSelector);
276
                               setTempoByTempoSelector(&tempo, tempoSelector);
277
                               showTempoBar2(tempo);
278
                           }
279
                       }
280
                   }
281
282
 
283
 
284
                   if(key == KEYS_CTRL_ARROW_RIGHT)
285
                   {
286
                       if ((ctrl_keys_state == 4) || (ctrl_keys_state == 8))
287
                       {
288
                           if(tempoSelector != 9)
289
                           {
290
                               showTempoBar1(++tempoSelector);
291
                               setTempoByTempoSelector(&tempo, tempoSelector);
292
                               showTempoBar2(tempo);
293
                           }
294
                       }
295
                   }
296
297
 
298
 
299
                   {
300
                       if(meter > 1)
301
                       {
302
                            showMeterBar(--meter);
303
                            showMeterIndicator();
304
                       }
305
306
 
307
308
 
309
                   {
310
                       if(meter < 12)
311
                       {
312
                            showMeterBar(++meter);
313
                            showMeterIndicator();
314
                       }
315
                   }
316
317
 
318
 
319
                   {
320
                       if(key == (0x31 + i))
321
                       {
322
                               if(accentBeatFlags[i] == 0)
323
                               {
324
                                   accentBeatFlags[i] = 1;
325
                               }
326
                               else if (accentBeatFlags[i] != 0)
327
                               {
328
                                   accentBeatFlags[i] = 0;
329
                               }
330
331
 
332
 
333
                       }
334
                   }
335
336
 
337
                   {
338
                       if(accentBeatFlags[9] == 0)
339
                           accentBeatFlags[9] = 1;
340
                       else if (accentBeatFlags[9] != 0)
341
                           accentBeatFlags[9] = 0;
342
343
 
344
                   }
345
346
 
347
                   {
348
                       if(accentBeatFlags[10] == 0)
349
                           accentBeatFlags[10] = 1;
350
                       else if (accentBeatFlags[10] != 0)
351
                           accentBeatFlags[10] = 0;
352
353
 
354
                   }
355
356
 
357
                   {
358
                       if(accentBeatFlags[11] == 0)
359
                           accentBeatFlags[11] = 1;
360
                       else if (accentBeatFlags[11] != 0)
361
                           accentBeatFlags[11] = 0;
362
363
 
364
                   }
365
366
 
367
 
368
 
369
 
370
                   if(key == KEY_SLASH)
371
                   {
372
                       if(counterIndicatorFlag != 0)
373
                           counterIndicatorFlag = 0;
374
                       else if (counterIndicatorFlag == 0)
375
                           counterIndicatorFlag = 1;
376
377
 
378
                   }
379
380
 
381
 
382
383
 
384
                   // button pressed; we have only one button, close
385
                   btn = _ksys_get_button_id();
386
387
 
388
389
 
390
                   {
391
392
 
393
                           startButtonBit = 1;
394
                       else
395
                           startButtonBit = 0;
396
397
 
398
                  }
399
400
 
401
 
402
                   if(btn == 10)
403
                   {
404
                       if(tempoSelector != 0)
405
                       {
406
                           showTempoBar1(--tempoSelector);
407
                           setTempoByTempoSelector(&tempo, tempoSelector);
408
                           showTempoBar2(tempo);
409
                       }
410
                   }
411
412
 
413
 
414
                   if(btn == 11)
415
                   {
416
                       if(tempoSelector != 9)
417
                       {
418
                           showTempoBar1(++tempoSelector);
419
                           setTempoByTempoSelector(&tempo, tempoSelector);
420
                           showTempoBar2(tempo);
421
                       }
422
                   }
423
424
 
425
 
426
                   if(btn == 12)
427
                   {
428
                       if(tempo != 1)
429
                       {
430
                           showTempoBar2(--tempo);
431
                           setTempoSelectorByTempo(&tempo, &tempoSelector);
432
433
 
434
                   }
435
436
 
437
 
438
                   if(btn == 13)
439
                   {
440
                       if(tempo < 320)
441
                       {
442
                           showTempoBar2(++tempo);
443
                           setTempoSelectorByTempo(&tempo, &tempoSelector);
444
                       }
445
                   }
446
447
 
448
 
449
                   {
450
                       if(meter > 1)
451
                       {
452
                            showMeterBar(--meter);
453
454
 
455
                            for(unsigned char i = meter; i < 11; i++)
456
                            {
457
                                accentBeatFlags[i] = 0;
458
                            }
459
460
 
461
462
 
463
 
464
                       }
465
466
 
467
468
 
469
                   {
470
                       if(meter < 12)
471
                       {
472
                            showMeterBar(++meter);
473
474
 
475
                            for(unsigned char i = meter; i < 11; i++)
476
                            {
477
                                accentBeatFlags[i] = 0;
478
                            }
479
480
 
481
                       }
482
483
 
484
485
 
486
 
487
                   {
488
                       if(btn == (100 + i))
489
                       {
490
                           //if(meter > 1)
491
                           //{
492
                               if(accentBeatFlags[i] == 0)
493
                               {
494
                                   accentBeatFlags[i] = 1;
495
                               }
496
                               else if (accentBeatFlags[i] != 0)
497
                               {
498
                                   accentBeatFlags[i] = 0;
499
                               }
500
                           //}
501
                           //else if(meter == 1) accentBeatFlags[i] = 0;
502
503
 
504
                       }
505
                   }
506
507
 
508
 
509
                   {
510
                       if(counterIndicatorFlag != 0)
511
                           counterIndicatorFlag = 0;
512
                       else if (counterIndicatorFlag == 0)
513
                           counterIndicatorFlag = 1;
514
515
 
516
                   }
517
518
 
519
 
520
 
521
522
 
523
    }
524
}
525