IMIDITempo.c revision 262059f71a68edc5e510427c63f5f1623d3672a8
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/* MIDITempo implementation */
18
19#include "sles_allinclusive.h"
20
21
22static SLresult IMIDITempo_SetTicksPerQuarterNote(SLMIDITempoItf self, SLuint32 tpqn)
23{
24    SL_ENTER_INTERFACE
25
26    if (!(1 <= tpqn && tpqn <= 32767)) {
27        result = SL_RESULT_PARAMETER_INVALID;
28    } else {
29        IMIDITempo *this = (IMIDITempo *) self;
30        interface_lock_poke(this);
31        this->mTicksPerQuarterNote = tpqn;
32        interface_unlock_poke(this);
33        result = SL_RESULT_SUCCESS;
34    }
35
36    SL_LEAVE_INTERFACE
37}
38
39
40static SLresult IMIDITempo_GetTicksPerQuarterNote(SLMIDITempoItf self, SLuint32 *pTpqn)
41{
42    SL_ENTER_INTERFACE
43
44    if (NULL == pTpqn) {
45        result = SL_RESULT_PARAMETER_INVALID;
46    } else {
47        IMIDITempo *this = (IMIDITempo *) self;
48        interface_lock_peek(this);
49        SLuint32 ticksPerQuarterNote = this->mTicksPerQuarterNote;
50        interface_unlock_peek(this);
51        *pTpqn = ticksPerQuarterNote;
52        result = SL_RESULT_SUCCESS;
53    }
54
55    SL_LEAVE_INTERFACE
56}
57
58
59static SLresult IMIDITempo_SetMicrosecondsPerQuarterNote(SLMIDITempoItf self, SLmicrosecond uspqn)
60{
61    SL_ENTER_INTERFACE
62
63    // spec says zero, is that correct?
64    if (!(1 <= uspqn && uspqn <= 16777215)) {
65        result = SL_RESULT_PARAMETER_INVALID;
66    } else {
67        IMIDITempo *this = (IMIDITempo *) self;
68        interface_lock_poke(this);
69        this->mMicrosecondsPerQuarterNote = uspqn;
70        interface_unlock_poke(this);
71        result = SL_RESULT_SUCCESS;
72    }
73
74    SL_LEAVE_INTERFACE
75}
76
77
78static SLresult IMIDITempo_GetMicrosecondsPerQuarterNote(SLMIDITempoItf self, SLmicrosecond *uspqn)
79{
80    SL_ENTER_INTERFACE
81
82    if (NULL == uspqn) {
83        result = SL_RESULT_PARAMETER_INVALID;
84    } else {
85        IMIDITempo *this = (IMIDITempo *) self;
86        interface_lock_peek(this);
87        SLuint32 microsecondsPerQuarterNote = this->mMicrosecondsPerQuarterNote;
88        interface_unlock_peek(this);
89        *uspqn = microsecondsPerQuarterNote;
90        result = SL_RESULT_SUCCESS;
91    }
92
93    SL_LEAVE_INTERFACE
94}
95
96
97static const struct SLMIDITempoItf_ IMIDITempo_Itf = {
98    IMIDITempo_SetTicksPerQuarterNote,
99    IMIDITempo_GetTicksPerQuarterNote,
100    IMIDITempo_SetMicrosecondsPerQuarterNote,
101    IMIDITempo_GetMicrosecondsPerQuarterNote
102};
103
104void IMIDITempo_init(void *self)
105{
106    IMIDITempo *this = (IMIDITempo *) self;
107    this->mItf = &IMIDITempo_Itf;
108    this->mTicksPerQuarterNote = 32; // wrong
109    this->mMicrosecondsPerQuarterNote = 100; // wrong
110}
111