1 /*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 /* MIDIMessage implementation */
18
19 #include "sles_allinclusive.h"
20
21
IMIDIMessage_SendMessage(SLMIDIMessageItf self,const SLuint8 * data,SLuint32 length)22 static SLresult IMIDIMessage_SendMessage(SLMIDIMessageItf self, const SLuint8 *data,
23 SLuint32 length)
24 {
25 SL_ENTER_INTERFACE
26
27 if (NULL == data) {
28 result = SL_RESULT_PARAMETER_INVALID;
29 } else {
30 //IMIDIMessage *thiz = (IMIDIMessage *) self;
31 result = SL_RESULT_FEATURE_UNSUPPORTED;
32 }
33
34 SL_LEAVE_INTERFACE
35 }
36
37
IMIDIMessage_RegisterMetaEventCallback(SLMIDIMessageItf self,slMetaEventCallback callback,void * pContext)38 static SLresult IMIDIMessage_RegisterMetaEventCallback(SLMIDIMessageItf self,
39 slMetaEventCallback callback, void *pContext)
40 {
41 SL_ENTER_INTERFACE
42
43 IMIDIMessage *thiz = (IMIDIMessage *) self;
44 interface_lock_exclusive(thiz);
45 thiz->mMetaEventCallback = callback;
46 thiz->mMetaEventContext = pContext;
47 interface_unlock_exclusive(thiz);
48 result = SL_RESULT_SUCCESS;
49
50 SL_LEAVE_INTERFACE
51 }
52
53
IMIDIMessage_RegisterMIDIMessageCallback(SLMIDIMessageItf self,slMIDIMessageCallback callback,void * pContext)54 static SLresult IMIDIMessage_RegisterMIDIMessageCallback(SLMIDIMessageItf self,
55 slMIDIMessageCallback callback, void *pContext)
56 {
57 SL_ENTER_INTERFACE
58
59 IMIDIMessage *thiz = (IMIDIMessage *) self;
60 interface_lock_exclusive(thiz);
61 thiz->mMessageCallback = callback;
62 thiz->mMessageContext = pContext;
63 interface_unlock_exclusive(thiz);
64 result = SL_RESULT_SUCCESS;
65
66 SL_LEAVE_INTERFACE
67 }
68
69
IMIDIMessage_AddMIDIMessageCallbackFilter(SLMIDIMessageItf self,SLuint32 messageType)70 static SLresult IMIDIMessage_AddMIDIMessageCallbackFilter(SLMIDIMessageItf self,
71 SLuint32 messageType)
72 {
73 SL_ENTER_INTERFACE
74
75 switch (messageType) {
76 case SL_MIDIMESSAGETYPE_NOTE_ON_OFF:
77 case SL_MIDIMESSAGETYPE_POLY_PRESSURE:
78 case SL_MIDIMESSAGETYPE_CONTROL_CHANGE:
79 case SL_MIDIMESSAGETYPE_PROGRAM_CHANGE:
80 case SL_MIDIMESSAGETYPE_CHANNEL_PRESSURE:
81 case SL_MIDIMESSAGETYPE_PITCH_BEND:
82 case SL_MIDIMESSAGETYPE_SYSTEM_MESSAGE:
83 {
84 SLuint8 messageTypeMask = 1 << messageType;
85 IMIDIMessage *thiz = (IMIDIMessage *) self;
86 interface_lock_exclusive(thiz);
87 thiz->mMessageTypes |= messageTypeMask;
88 interface_unlock_exclusive(thiz);
89 result = SL_RESULT_SUCCESS;
90 }
91 break;
92 default:
93 result = SL_RESULT_PARAMETER_INVALID;
94 break;
95 }
96
97 SL_LEAVE_INTERFACE
98 }
99
100
IMIDIMessage_ClearMIDIMessageCallbackFilter(SLMIDIMessageItf self)101 static SLresult IMIDIMessage_ClearMIDIMessageCallbackFilter(SLMIDIMessageItf self)
102 {
103 SL_ENTER_INTERFACE
104
105 IMIDIMessage *thiz = (IMIDIMessage *) self;
106 interface_lock_exclusive(thiz);
107 thiz->mMessageTypes = 0;
108 interface_unlock_exclusive(thiz);
109 result = SL_RESULT_SUCCESS;
110
111 SL_LEAVE_INTERFACE
112 }
113
114
115 static const struct SLMIDIMessageItf_ IMIDIMessage_Itf = {
116 IMIDIMessage_SendMessage,
117 IMIDIMessage_RegisterMetaEventCallback,
118 IMIDIMessage_RegisterMIDIMessageCallback,
119 IMIDIMessage_AddMIDIMessageCallbackFilter,
120 IMIDIMessage_ClearMIDIMessageCallbackFilter
121 };
122
IMIDIMessage_init(void * self)123 void IMIDIMessage_init(void *self)
124 {
125 IMIDIMessage *thiz = (IMIDIMessage *) self;
126 thiz->mItf = &IMIDIMessage_Itf;
127 thiz->mMetaEventCallback = NULL;
128 thiz->mMetaEventContext = NULL;
129 thiz->mMessageCallback = NULL;
130 thiz->mMessageContext = NULL;
131 thiz->mMessageTypes = 0;
132 }
133