Added a rudimentary karplus-strong string instrument to org.c
[cantaveria.git] / soundtest.c
blob20c45c80dcf2b64fcf31e65e43c22ee2f8583fd3
1 #include <stdio.h>
3 #include <input.h>
4 #include <graphics.h>
5 #include <console.h>
6 #include <transfer.h>
7 #include <seq.h>
8 #include <org.h>
11 int main_note = 0;
13 #define CHANNEL 1
15 void play(int note){
16 seq_instant(EV_NOTEON, CHANNEL, note+main_note, 0);
19 void stop(int note){
20 seq_instant(EV_NOTEOFF, CHANNEL, note+main_note, 0);
23 void bend(int amount){
24 seq_instant(EV_PITCHBEND, CHANNEL, 0, amount);
27 int bend_amount = 64;
28 int bend_v = 0;
30 static void press(input in){
31 if(in.button == ESCAPE_KEY){
32 game_is_over();
35 console_printf("%s", input_str(in));
37 switch(in.button){
38 case LEFT_BUTTON: play(0); break;
39 case RIGHT_BUTTON: play(4); break;
40 case DOWN_BUTTON: play(2); break;
41 case FIRE_BUTTON: play(5); break;
42 case JUMP_BUTTON: play(7); break;
43 case SPECIAL_BUTTON: play(9); break;
44 case L_BUTTON: bend_v = -1; break;
45 case R_BUTTON: bend_v = 1; break;
46 case START_BUTTON: main_note-=12; break;
47 case SELECT_BUTTON: main_note+=12; break;
48 default: break;
52 static void release(input in){
53 switch(in.button){
54 case LEFT_BUTTON: stop(0); break;
55 case RIGHT_BUTTON: stop(4); break;
56 case DOWN_BUTTON: stop(2); break;
57 case FIRE_BUTTON: stop(5); break;
58 case JUMP_BUTTON: stop(7); break;
59 case SPECIAL_BUTTON: stop(9); break;
60 case L_BUTTON: bend_v = 0; break;
61 case R_BUTTON: bend_v = 0; break;
62 default: break;
66 static void update(){
67 console_update();
69 bend_amount += bend_v;
70 if(bend_amount > 0x7f) bend_amount = 0x7f;
71 if(bend_amount < 0x00) bend_amount = 0x00;
72 if(bend_v != 0){
73 bend(bend_amount);
77 static void draw(){
81 void setup_inner(){
82 set_handler(update, draw, press, release);
83 console_clear();