-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMidi.h
101 lines (89 loc) · 3.57 KB
/
Midi.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#ifndef MIDI_H
#define MIDI_H
#include <stdio.h>
#include <malloc.h>
#include <jack/midiport.h>
struct Midi_Event {
int note;
int velocity;
char * type;
int channel;
};
struct Midi_Event DataToMidiEvent( jack_midi_event_t in_event)
{
struct Midi_Event midi_event;
if (in_event.buffer[0]<144){
midi_event.type = "NOTE_OFF";
midi_event.channel = in_event.buffer[0] - 127;
}
else if (in_event.buffer[0]>=144)
{
midi_event.type = "NOTE_ON";
midi_event.channel = in_event.buffer[0] - 143;
}
midi_event.note = in_event.buffer[1];
midi_event.velocity= in_event.buffer[2];
return midi_event;
}
int MidiTrigger(struct Midi_Event midievent)
{
struct Slice* currentS = &EmptySlice;
struct Playback * currentP;
while(currentS->next != NULL)
{
currentP = ¤tS->next->playback;
if (currentS->next->key == midievent.note)
{
int playbackleft = 1;
while(playbackleft)
{
if(currentP->state == "playing" && midievent.type == "NOTE_ON")
{
if(currentS->next->playmode == "FW_S") SliceStartPlayback(currentS->next);
if(currentS->next->playmode == "FW_P") currentP->pos = 0;
if(currentS->next->playmode == "FW_U") currentP->state = "playing";
}
else if (currentP->state =="playing" && midievent.type == "NOTE_OFF")
{
if(currentS->next->playmode == "FW_P")
{
currentP->pos =0 ;
currentP->state = "done";
}
if(currentS->next->playmode == "FW_U")
{
currentP->state = "paused";
}
}
else if (currentP->state =="paused" && midievent.type == "NOTE_ON")
{
if(currentP->pos < currentS->next->length)
{
currentP->state = "playing";
}
else
{
currentP->state = "done";
currentP->pos = 0;
}
}
else if (currentP->state == "done" && midievent.type == "NOTE_ON")
{
if(currentS->next->playmode == "FW_S") SliceStartPlayback(currentS->next);
if(currentS->next->playmode == "FW_P" || currentS->next->playmode == "FW_U"){
currentP->pos = 0;
currentP->state ="playing";}
}
if(currentP->next == NULL) playbackleft=0;
else{
currentP = currentP->next;
}
printf("Slice at %i , mode %s and first playback state %s \n", ¤tS->next,currentS->next->playmode, currentP->state);
}
}
currentS = currentS->next;
}
//
return 0;
}
#endif