1 //------------------------------------------------------------------------------
3 // EchoGals/Echo24 BeOS Driver for Echo audio cards
5 // Copyright (c) 2005, Jérôme Duval
7 // Permission is hereby granted, free of charge, to any person obtaining a
8 // copy of this software and associated documentation files (the "Software"),
9 // to deal in the Software without restriction, including without limitation
10 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 // and/or sell copies of the Software, and to permit persons to whom the
12 // Software is furnished to do so, subject to the following conditions:
14 // The above copyright notice and this permission notice shall be included in
15 // all copies or substantial portions of the Software.
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 // DEALINGS IN THE SOFTWARE.
27 #include "midi_driver.h"
29 static status_t
midi_open(const char *name
, uint32 flags
, void **cookie
);
30 static status_t
midi_close(void *cookie
);
31 static status_t
midi_free(void *cookie
);
32 static status_t
midi_control(void *cookie
, uint32 op
, void *data
, size_t len
);
33 static status_t
midi_read(void *cookie
, off_t pos
, void *data
, size_t *len
);
34 static status_t
midi_write(void *cookie
, off_t pos
, const void *data
, size_t *len
);
37 device_hooks midi_hooks
= {
51 midi_open(const char* name
, uint32 flags
, void** cookie
)
55 LOG(("midi_open()\n"));
58 for (ix
=0; ix
<num_cards
; ix
++) {
59 if (!strcmp(name
, cards
[ix
].midi
.name
)) {
63 if (ix
>= num_cards
) {
64 LOG(("bad device\n"));
69 atomic_add(&cards
[ix
].midi
.count
, 1);
70 memset(&cards
[ix
].midi
.context
, 0, sizeof(cards
[ix
].midi
.context
));
71 cards
[ix
].pEG
->OpenMidiInput(&cards
[ix
].midi
.context
);
77 midi_close(void* cookie
)
79 LOG(("midi_close()\n"));
85 midi_free(void* cookie
)
87 echo_dev
*card
= (echo_dev
*) cookie
;
89 LOG(("midi_free()\n"));
91 card
->pEG
->CloseMidiInput(&card
->midi
.context
);
93 atomic_add(&card
->midi
.count
, -1);
94 LOG(("midi_free() done\n"));
100 midi_control(void* cookie
, uint32 iop
, void* data
, size_t len
)
102 LOG(("midi_control()\n"));
109 midi_read(void* cookie
, off_t pos
, void* ptr
, size_t* nread
)
111 echo_dev
*card
= (echo_dev
*) cookie
;
115 PBYTE next
= (PBYTE
)ptr
;
117 LOG(("midi_read()\n"));
119 if (acquire_sem(card
->midi
.midi_ready_sem
) != B_OK
)
122 err
= card
->pEG
->ReadMidiByte(&card
->midi
.context
, midiData
, timestamp
);
123 if (err
== ECHOSTATUS_OK
) {
126 LOG(("midi_read() : 0x%lx\n", *next
));
134 midi_write(void* cookie
, off_t pos
, const void* ptr
, size_t* _nwritten
)
136 echo_dev
*card
= (echo_dev
*) cookie
;
138 DWORD nwritten
= *_nwritten
;
140 LOG(("midi_write()\n"));
142 err
= card
->pEG
->WriteMidi(nwritten
, (PBYTE
)ptr
, &nwritten
);
143 *_nwritten
= nwritten
;
144 return (err
!= ECHOSTATUS_OK
) ? B_ERROR
: B_OK
;