File: seqtest1.py

package info (click to toggle)
python-pyalsa 1.2.12-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 496 kB
  • sloc: ansic: 5,616; python: 1,260; makefile: 4
file content (193 lines) | stat: -rwxr-xr-x 6,341 bytes parent folder | download | duplicates (2)
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#! /usr/bin/python
# Sample code for pyalsa Sequencer binding
# by Aldrin Martoq <amartoq@dcc.uchile.cl>
# version 2008012401 (UTC: 1201153962 secs since the epoch)
#
# This code is in the public domain,
# use it as base for creating your pyalsa
# sequencer application.

import sys
sys.path.insert(0, '..')
del sys
from alsamemdebug import debuginit, debug, debugdone
from pyalsa import alsaseq


def dump_portinfo(dict):
    def dl(dict, key):
        if key in dict:
            return "'" + str(dict[key]) + "'"
        return "N/A"
    def da(dict, key, search):
        tmp = None
        if key in dict:
            for k in search:
                if k & dict[key]:
                    if tmp == None:
                        tmp = str(search[k])
                    else:
                        tmp += " " + str(search[k])
            if tmp == None:
                tmp = "UNKNOWN(%d)" % (dict[key])
        else:
            tmp = "N/A"
        return tmp

    return "name=%s capability=%s type=%s" % (dl(dict, 'name'), da(dict, 'capability', alsaseq._dportcap), da(dict, 'type', alsaseq._dporttype))

def dump_list(connections, simple=True):
    for clientports in connections:
        clientname, clientid, portlist = clientports
        print("    client: %3d    %s" % (clientid, clientname))
        if not simple:
            clientinfo = sequencer.get_client_info(clientid)
            print("\t[%s]" % clientinfo)
        else:
            print()
        for port in portlist:
            portname, portid, connections = port
            print("      port: %3d:%-2d +-%s" % (clientid, portid, portname))
            if not simple:
                portinfo = sequencer.get_port_info(portid, clientid)
                print("\t[%s]" % (dump_portinfo(portinfo)))
            else:
                print()
            readconn, writeconn = connections
            for c,p,i in readconn:
                if not simple:
                    print("        connection   to: %d:%d %s" % (c,p, i))
                else:
                    print("        connection   to: %d:%d" % (c,p))
            for c,p,i in writeconn:
                if not simple:
                    print("        connection   to: %d:%d %s" % (c,p, i))
                else:
                    print("        connection   to: %d:%d" % (c,p))


debuginit()

print("01:Creating Sequencer ==============================")
sequencer = alsaseq.Sequencer()
# other examples:
# sequencer = alsaseq.Sequencer("hw", "myfancyapplication", alsaseq.SEQ_OPEN_INPUT, alsaseq.SEQ_BLOCK)
# sequencer = alsaseq.Sequencer(clientname='python-test', streams=alsaseq.SEQ_OPEN_OUTPUT)
print("    sequencer:  %s" % sequencer)
print("    name:       %s" % sequencer.name)
print("    clientname: %s" % sequencer.clientname)
print("    streams:    %d (%s)" % (sequencer.streams, str(sequencer.streams)))
print("    mode:       %d (%s)" % (sequencer.mode, str(sequencer.mode)))
print("    client_id:  %s" % sequencer.client_id)
print()

print("02:Changing some parameters ========================")
sequencer.clientname = 'pepito'
sequencer.mode = alsaseq.SEQ_BLOCK
print("    clientname: %s" % sequencer.clientname)
print("    mode:       %d (%s)" % (sequencer.mode, str(sequencer.mode)))
print()

print("03:Creating simple port ============================")
port_id = sequencer.create_simple_port("myport", alsaseq.SEQ_PORT_TYPE_APPLICATION,alsaseq.SEQ_PORT_CAP_WRITE | alsaseq.SEQ_PORT_CAP_SUBS_WRITE)
print("    port_id:    %s" % port_id)
print()

print("04:Getting port info ===============================")
port_info = sequencer.get_port_info(port_id)
print("      -->       %s" % dump_portinfo(port_info))
print("      -->       %s" % port_info)
print()

print("05:Retrieving clients and connections (as list) ====")
connections = sequencer.connection_list()
print("  %s" % (connections))
print()

print("06:Retrieving clients and connections (detailed) ===")
connections = sequencer.connection_list()
dump_list(connections, False)
print()

print("07:Connecting 'arbitrary' ports... =================")
source = (alsaseq.SEQ_CLIENT_SYSTEM, alsaseq.SEQ_PORT_SYSTEM_ANNOUNCE)
dest = (sequencer.client_id, port_id)
print("%s ---> %s" % (str(source), str(dest)))
sequencer.connect_ports(source, dest)
print()

print("08:Retrieving clients and connections (simple) =====")
connections = sequencer.connection_list()
dump_list(connections)
print()

print("09:Disconnecting previous 'arbitrary' port =========")
print("%s -X-> %s" % (str(source), str(dest)))
sequencer.disconnect_ports(source, dest)
print()

print("10:Retrieving clients and connections (simple) =====")
connections = sequencer.connection_list()
dump_list(connections)
print()

print("11:Listing known streams constants =================")
print("%s" % alsaseq._dstreams.values())
print()

print("12:Listing known mode constants ====================")
print("%s" % alsaseq._dmode.values())
print()

print("13:Listing known queue constants ===================")
print("%s" % alsaseq._dqueue.values())
print()

print("14:Listing known client type constants =============")
print("%s" % alsaseq._dclienttype.values())
print()

print("15:Listing known port caps constants ===============")
print("%s" % alsaseq._dportcap.values())
print()

print("16:Listing known port types constants ==============")
print("%s" % alsaseq._dporttype.values())
print()

print("17:Listing known event type constants ==============")
print("%s" % alsaseq._deventtype.values())
print()

print("18:Listing known event timestamp constants =========")
print("%s" % alsaseq._deventtimestamp.values())
print()

print("19:Listing known event timemode constants ==========")
print("%s" % alsaseq._deventtimemode.values())
print()

print("20:Listing known client addresses constants ========")
print("%s" % alsaseq._dclient.values())
print()

print("21:Listing known port addresses constants ==========")
print("%s" % alsaseq._dport.values())
print()

print("22:SeqEvent repr ===================================")
print("%s" % alsaseq.SeqEvent(alsaseq.SEQ_EVENT_NOTEON))
print()


print("98:Removing sequencer ==============================")
debug([sequencer])
del sequencer
print()

print("99:Listing sequencer (using new one) ===============")
dump_list(alsaseq.Sequencer().connection_list())
print()

debugdone()
print("seqtest1.py done.")