Gambas France BETA


Pas de compte ? Incription

Intercepter données Midi avec les fonctions externes du subsistema Seq de Alsa

1
AuteurMessages
vuott#1 Posté le 17/3/2016 à 16:13:49
Ne cedere ineluctabili possimusSalut,

c'est un code pour intercepter données Midi avec les fonctions externes du subsistema Seq de Alsa.

Avant tout il faut connecter le clavier Midi au système ALSA:
~ $ aconnect 24:0 14:0

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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
PRIVATE bo AS BOOLEAN

LIBRARY "libasound:2"

PUBLIC STRUCT snd_seq_event
type AS BYTE
flags AS BYTE
tag AS BYTE
queue AS BYTE
tick_time AS INTEGER
real_time AS INTEGER
source_client AS BYTE
source_port AS BYTE
dest_client AS BYTE
dest_port AS BYTE
channel AS BYTE
note AS BYTE
velocity AS BYTE
off_velocity AS BYTE
param AS INTEGER
value AS INTEGER
END STRUCT

PRIVATE CONST SND_SEQ_OPEN_DUPLEX AS INTEGER = 3
PRIVATE CONST SND_SEQ_PORT_CAP_WRITE AS INTEGER = 2
PRIVATE CONST SND_SEQ_PORT_CAP_SUBS_WRITE AS INTEGER = 64
PRIVATE CONST SND_SEQ_PORT_TYPE_MIDI_GENERIC AS INTEGER = 2
PRIVATE CONST SND_SEQ_PORT_TYPE_APPLICATION AS INTEGER = 1048576
PRIVATE ENUM SND_SEQ_EVENT_NOTEON = 6, SND_SEQ_EVENT_NOTEOFF, SND_SEQ_EVENT_KEYPRESS, SND_SEQ_EVENT_CONTROLLER = 10, SND_SEQ_EVENT_PGMCHANGE

' int snd_seq_open (snd_seq_t **handle, const char *name, int streams, int mode)
' Open the ALSA sequencer.
PRIVATE EXTERN snd_seq_open(handle AS POINTER, name AS STRING, streams AS INTEGER, mode AS INTEGER) AS INTEGER

' int snd_seq_create_simple_port(snd_seq_t* seq, const char* name, unsigned int caps, unsigned int type)
' Create a port - simple version.
PRIVATE EXTERN snd_seq_create_simple_port(seq AS POINTER, name AS STRING, caps AS INTEGER, type AS INTEGER) AS INTEGER

' int snd_seq_connect_from(seq as pointer, myport as integer, src_client as integer, src_port as integer)
' Simple subscription (w/o exclusive & time conversion)
PRIVATE EXTERN snd_seq_connect_from(seq AS POINTER, myport AS INTEGER, src_client AS INTEGER, src_port AS INTEGER) AS INTEGER

' int snd_seq_event_input (snd_seq_t *handle, snd_seq_event_t **ev)
' Retrieve an event from sequencer.
PRIVATE EXTERN snd_seq_event_input(handle AS POINTER, ev AS POINTER) AS INTEGER

' int snd_seq_close (snd_seq_t *handle)
' Close the sequencer.
PRIVATE EXTERN snd_seq_close(handle AS POINTER) AS INTEGER


PUBLIC SUB Main()

DIM seq, po AS POINTER
DIM i AS INTEGER
DIM evento AS Snd_seq_event

seq = Connectio_Alsa()

WHILE bo = FALSE
i = snd_seq_event_input(seq, VarPtr(po))
evento = po
IF i = 0 THEN BREAK
IF IsNull(evento) = FALSE THEN Videre_Eventum(evento)
WAIT 0.01
WEND

snd_seq_close(seq)
PRINT "\nFinis terrae !"
QUIT

END


PRIVATE FUNCTION Connectio_Alsa() AS POINTER

DIM hs AS POINTER
DIM i, porta_in AS INTEGER

i = snd_seq_open(VarPtr(hs), "default", SND_SEQ_OPEN_DUPLEX, 0)
IF i < 0 THEN Error.Raise("Error !")

porta_in = snd_seq_create_simple_port(hs, "gambas", SND_SEQ_PORT_CAP_WRITE OR SND_SEQ_PORT_CAP_SUBS_WRITE, SND_SEQ_PORT_TYPE_MIDI_GENERIC OR SND_SEQ_PORT_TYPE_APPLICATION)
IF porta_in < 0 THEN Error.Raise("Error !")

i = snd_seq_connect_from(hs, porta_in, 14, 0)
IF i < 0 THEN Error.Raise("Error !")

RETURN hs

END


PRIVATE PROCEDURE Videre_Eventum(eventum AS Snd_seq_event)

SELECT CASE eventum.type
CASE SND_SEQ_EVENT_NOTEOFF
WITH eventum
PRINT "Note Off: ", .channel, .note, .velocity
END WITH
CASE SND_SEQ_EVENT_NOTEON
WITH eventum
PRINT "Note On: ", .channel, .note, .velocity
END WITH
CASE SND_SEQ_EVENT_CONTROLLER
WITH eventum
PRINT "Control Change: ", .channel, .param, .value
END WITH
CASE SND_SEQ_EVENT_PGMCHANGE
WITH eventum
PRINT "Program Change: ", .channel, .value
END WITH
END SELECT

END


PUBLIC SUB Application_Read() ' ...pour fermer l'application

DIM s AS STRING

INPUT #File.in, s
IF s = "q" THEN bo = TRUE

END
Gambette#2 Posté le 17/3/2016 à 17:58:16
Super Vuott, je vais me mettre à la musique.
gambix#3 Posté le 18/3/2016 à 10:36:53
Faire simple !test
Moins de texte dans une signature c'est agrandir son espace.
1