Home | History | Annotate | Download | only in itf
      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 
     22 static 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 *thiz = (IMIDITempo *) self;
     30         interface_lock_poke(thiz);
     31         thiz->mTicksPerQuarterNote = tpqn;
     32         interface_unlock_poke(thiz);
     33         result = SL_RESULT_SUCCESS;
     34     }
     35 
     36     SL_LEAVE_INTERFACE
     37 }
     38 
     39 
     40 static 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 *thiz = (IMIDITempo *) self;
     48         interface_lock_peek(thiz);
     49         SLuint32 ticksPerQuarterNote = thiz->mTicksPerQuarterNote;
     50         interface_unlock_peek(thiz);
     51         *pTpqn = ticksPerQuarterNote;
     52         result = SL_RESULT_SUCCESS;
     53     }
     54 
     55     SL_LEAVE_INTERFACE
     56 }
     57 
     58 
     59 static 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 *thiz = (IMIDITempo *) self;
     68         interface_lock_poke(thiz);
     69         thiz->mMicrosecondsPerQuarterNote = uspqn;
     70         interface_unlock_poke(thiz);
     71         result = SL_RESULT_SUCCESS;
     72     }
     73 
     74     SL_LEAVE_INTERFACE
     75 }
     76 
     77 
     78 static 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 *thiz = (IMIDITempo *) self;
     86         interface_lock_peek(thiz);
     87         SLuint32 microsecondsPerQuarterNote = thiz->mMicrosecondsPerQuarterNote;
     88         interface_unlock_peek(thiz);
     89         *uspqn = microsecondsPerQuarterNote;
     90         result = SL_RESULT_SUCCESS;
     91     }
     92 
     93     SL_LEAVE_INTERFACE
     94 }
     95 
     96 
     97 static const struct SLMIDITempoItf_ IMIDITempo_Itf = {
     98     IMIDITempo_SetTicksPerQuarterNote,
     99     IMIDITempo_GetTicksPerQuarterNote,
    100     IMIDITempo_SetMicrosecondsPerQuarterNote,
    101     IMIDITempo_GetMicrosecondsPerQuarterNote
    102 };
    103 
    104 void IMIDITempo_init(void *self)
    105 {
    106     IMIDITempo *thiz = (IMIDITempo *) self;
    107     thiz->mItf = &IMIDITempo_Itf;
    108     thiz->mTicksPerQuarterNote = 32; // wrong
    109     thiz->mMicrosecondsPerQuarterNote = 100; // wrong
    110 }
    111