156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * File:
456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * eas_rtttl.c
556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Contents and purpose:
756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * RTTTL parser
856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Copyright Sonic Network Inc. 2005
107df30109963092559d3760c0661a020f9daf1030The Android Open Source Project
117df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License");
127df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * you may not use this file except in compliance with the License.
137df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * You may obtain a copy of the License at
147df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *
157df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *      http://www.apache.org/licenses/LICENSE-2.0
167df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *
177df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Unless required by applicable law or agreed to in writing, software
187df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS,
197df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
207df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * See the License for the specific language governing permissions and
217df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * limitations under the License.
2256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
2356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
2456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Revision Control:
2556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *   $Revision: 795 $
2656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *   $Date: 2007-08-01 00:14:45 -0700 (Wed, 01 Aug 2007) $
2756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
2856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
2956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
3056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#include "eas_data.h"
3156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#include "eas_miditypes.h"
3256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#include "eas_parser.h"
3356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#include "eas_report.h"
3456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#include "eas_host.h"
3556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#include "eas_midi.h"
3656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#include "eas_config.h"
3756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#include "eas_vm_protos.h"
3856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#include "eas_rtttldata.h"
3956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#include "eas_ctype.h"
4056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
4156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/* increase gain for mono ringtones */
4256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define RTTTL_GAIN_OFFSET       8
4356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
4456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/* maximum title length including colon separator */
4556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define RTTTL_MAX_TITLE_LEN     32
4656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define RTTTL_INFINITE_LOOP     15
4756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
4856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/* length of 32nd note in 1/256ths of a msec for 63 BPM tempo */
4956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define DEFAULT_TICK_CONV       30476
5056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define TICK_CONVERT            1920000
5156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
5256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/* default channel and program for RTTTL playback */
5356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define RTTTL_CHANNEL           0
5456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define RTTTL_PROGRAM           80
5556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define RTTTL_VELOCITY          127
5656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
5756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/* note used for rest */
5856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define RTTTL_REST              1
5956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
6056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/* multiplier for fixed point triplet conversion */
6156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define TRIPLET_MULTIPLIER      683
6256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define TRIPLET_SHIFT           10
6356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
6456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/* local prototypes */
6556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT RTTTL_CheckFileType (S_EAS_DATA *pEASData, EAS_FILE_HANDLE fileHandle, EAS_VOID_PTR *ppHandle, EAS_I32 offset);
6656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT RTTTL_Prepare (S_EAS_DATA *pEASData, EAS_VOID_PTR pInstData);
6756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT RTTTL_Time (S_EAS_DATA *pEASData, EAS_VOID_PTR pInstData, EAS_U32 *pTime);
6856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT RTTTL_Event (S_EAS_DATA *pEASData, EAS_VOID_PTR pInstData, EAS_INT parserMode);
6956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT RTTTL_State (S_EAS_DATA *pEASData, EAS_VOID_PTR pInstData, EAS_STATE *pState);
7056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT RTTTL_Close (S_EAS_DATA *pEASData, EAS_VOID_PTR pInstData);
7156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT RTTTL_Reset (S_EAS_DATA *pEASData, EAS_VOID_PTR pInstData);
7256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT RTTTL_Pause (S_EAS_DATA *pEASData, EAS_VOID_PTR pInstData);
7356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT RTTTL_Resume (S_EAS_DATA *pEASData, EAS_VOID_PTR pInstData);
7456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT RTTTL_SetData (S_EAS_DATA *pEASData, EAS_VOID_PTR pInstData, EAS_I32 param, EAS_I32 value);
7556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT RTTTL_GetData (S_EAS_DATA *pEASData, EAS_VOID_PTR pInstData, EAS_I32 param, EAS_I32 *pValue);
7656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT RTTTL_GetStyle (EAS_HW_DATA_HANDLE hwInstData, S_RTTTL_DATA *pData);
7756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT RTTTL_GetDuration (EAS_HW_DATA_HANDLE hwInstData, S_RTTTL_DATA *pData, EAS_I8 *pDuration);
7856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT RTTTL_GetOctave (EAS_HW_DATA_HANDLE hwInstData, S_RTTTL_DATA *pData, EAS_U8 *pOctave);
7956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT RTTTL_GetTempo (EAS_HW_DATA_HANDLE hwInstData, S_RTTTL_DATA *pData);
8056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT RTTTL_GetNumber (EAS_HW_DATA_HANDLE hwInstData, S_RTTTL_DATA *pData, EAS_I32 *pValue);
8156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT RTTTL_ParseHeader (S_EAS_DATA *pEASData, S_RTTTL_DATA* pData, EAS_BOOL metaData);
8256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT RTTTL_GetNextChar (EAS_HW_DATA_HANDLE hwInstData, S_RTTTL_DATA *pData, EAS_I8 *pValue);
8356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT RTTTL_PeekNextChar (EAS_HW_DATA_HANDLE hwInstData, S_RTTTL_DATA *pData, EAS_I8 *pValue);
8456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
8556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/* inline functions */
8656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave SparksEAS_INLINE void RTTTL_PutBackChar (S_RTTTL_DATA *pData, EAS_I8 value) { pData->dataByte = value; }
8756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
8856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
8956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/* lookup table for note values */
9056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic const EAS_U8 noteTable[] = { 21, 23, 12, 14, 16, 17, 19, 23 };
9156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
9256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
9356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
9456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * EAS_RTTTL_Parser
9556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
9656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * This structure contains the functional interface for the iMelody parser
9756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
9856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
9956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksconst S_FILE_PARSER_INTERFACE EAS_RTTTL_Parser =
10056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
10156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    RTTTL_CheckFileType,
10256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    RTTTL_Prepare,
10356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    RTTTL_Time,
10456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    RTTTL_Event,
10556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    RTTTL_State,
10656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    RTTTL_Close,
10756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    RTTTL_Reset,
10856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    RTTTL_Pause,
10956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    RTTTL_Resume,
11056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    NULL,
11156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    RTTTL_SetData,
11256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    RTTTL_GetData,
11356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    NULL
11456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks};
11556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
11656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
11756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * RTTTL_CheckFileType()
11856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
11956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
12056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Check the file type to see if we can parse it
12156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
12256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
12356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pEASData         - pointer to overall EAS data structure
12456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * handle           - pointer to file handle
12556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
12656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
12756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
12856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
12956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
13056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
13156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
13256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
13356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT RTTTL_CheckFileType (S_EAS_DATA *pEASData, EAS_FILE_HANDLE fileHandle, EAS_VOID_PTR *ppHandle, EAS_I32 offset)
13456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
13556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    S_RTTTL_DATA data;
13656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    S_RTTTL_DATA *pData;
13756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
13856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* see if we can parse the header */
13956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    data.fileHandle = fileHandle;
14056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    data.fileOffset = offset;
14156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    *ppHandle= NULL;
14256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (RTTTL_ParseHeader (pEASData, &data, EAS_FALSE) == EAS_SUCCESS)
14356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
14456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
14556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* check for static memory allocation */
14656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (pEASData->staticMemoryModel)
14756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pData = EAS_CMEnumData(EAS_CM_RTTTL_DATA);
14856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        else
14956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pData = EAS_HWMalloc(pEASData->hwInstData, sizeof(S_RTTTL_DATA));
15056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (!pData)
15156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            return EAS_ERROR_MALLOC_FAILED;
15256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        EAS_HWMemSet(pData, 0, sizeof(S_RTTTL_DATA));
15356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
15456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* return a pointer to the instance data */
15556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pData->fileHandle = fileHandle;
15656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pData->fileOffset = offset;
15756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pData->state = EAS_STATE_OPEN;
15856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        *ppHandle = pData;
15956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
16056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
16156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_SUCCESS;
16256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
16356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
16456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
16556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * RTTTL_Prepare()
16656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
16756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
16856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Prepare to parse the file. Allocates instance data (or uses static allocation for
16956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * static memory model).
17056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
17156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
17256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pEASData         - pointer to overall EAS data structure
17356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * handle           - pointer to file handle
17456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
17556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
17656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
17756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
17856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
17956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
18056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
18156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
18256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT RTTTL_Prepare (S_EAS_DATA *pEASData, EAS_VOID_PTR pInstData)
18356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
18456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    S_RTTTL_DATA* pData;
18556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_RESULT result;
18656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
18756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* check for valid state */
18856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pData = (S_RTTTL_DATA*) pInstData;
18956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (pData->state != EAS_STATE_OPEN)
19056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return EAS_ERROR_NOT_VALID_IN_THIS_STATE;
19156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
19256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* instantiate a synthesizer */
19356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if ((result = VMInitMIDI(pEASData, &pData->pSynth)) != EAS_SUCCESS)
19456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
19556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "VMInitMIDI returned %d\n", result); */ }
19656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return result;
19756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
19856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
19956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pData->state = EAS_STATE_ERROR;
20056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if ((result = RTTTL_ParseHeader (pEASData,  pData, (EAS_BOOL) (pData->metadata.callback != NULL))) != EAS_SUCCESS)
20156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
20256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* if using dynamic memory, free it */
20356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (!pEASData->staticMemoryModel)
20456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            EAS_HWFree(pEASData->hwInstData, pData);
20556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return result;
20656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
20756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
20856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pData->state = EAS_STATE_READY;
20956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_SUCCESS;
21056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
21156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
21256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
21356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * RTTTL_Time()
21456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
21556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
21656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Returns the time of the next event in msecs
21756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
21856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
21956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pEASData         - pointer to overall EAS data structure
22056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * handle           - pointer to file handle
22156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pTime            - pointer to variable to hold time of next event (in msecs)
22256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
22356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
22456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
22556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
22656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
22756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
22856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
22956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
23056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*lint -esym(715, pEASData) reserved for future use */
23156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT RTTTL_Time (S_EAS_DATA *pEASData, EAS_VOID_PTR pInstData, EAS_U32 *pTime)
23256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
23356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    S_RTTTL_DATA *pData;
23456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
23556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pData = (S_RTTTL_DATA*) pInstData;
23656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
23756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* return time in milliseconds */
23856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /*lint -e{704} use shift instead of division */
23956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    *pTime = pData->time >> 8;
24056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_SUCCESS;
24156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
24256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
24356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
24456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * RTTTL_Event()
24556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
24656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
24756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Parse the next event in the file
24856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
24956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
25056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pEASData         - pointer to overall EAS data structure
25156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * handle           - pointer to file handle
25256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
25356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
25456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
25556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
25656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
25756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
25856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
25956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
26056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT RTTTL_Event (S_EAS_DATA *pEASData, EAS_VOID_PTR pInstData, EAS_INT parserMode)
26156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
26256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    S_RTTTL_DATA* pData;
26356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_RESULT result;
26456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_I32 ticks;
26556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_I32 temp;
26656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_I8 c;
26756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_U8 note;
26856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_U8 octave;
26956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
27056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pData = (S_RTTTL_DATA*) pInstData;
27156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (pData->state >= EAS_STATE_OPEN)
27256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return EAS_SUCCESS;
27356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
27456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* initialize MIDI channel when the track starts playing */
27556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (pData->time == 0)
27656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
27756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* set program to square lead */
27856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        VMProgramChange(pEASData->pVoiceMgr, pData->pSynth, RTTTL_CHANNEL, RTTTL_PROGRAM);
27956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
28056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* set channel volume to max */
28156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        VMControlChange(pEASData->pVoiceMgr, pData->pSynth, RTTTL_CHANNEL, 7, 127);
28256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
28356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
28456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* check for end of note */
28556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (pData->note)
28656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
28756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* stop the note */
28856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        VMStopNote(pEASData->pVoiceMgr, pData->pSynth, RTTTL_CHANNEL, pData->note, 0);
28956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pData->note = 0;
29056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
29156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* check for rest between notes */
29256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (pData->restTicks)
29356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        {
29456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pData->time += pData->restTicks;
29556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pData->restTicks = 0;
29656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            return EAS_SUCCESS;
29756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        }
29856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
29956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
30056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* parse the next event */
30156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    octave = pData->octave;
30256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    note = 0;
30356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    ticks = pData->duration * pData->tick;
30456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    for (;;)
30556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
30656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
30756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* get next character */
30856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if ((result = RTTTL_GetNextChar(pEASData->hwInstData, pData, &c)) != EAS_SUCCESS)
30956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        {
31056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            if (result != EAS_EOF)
31156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                return result;
31256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
31356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            /* end of file, if no notes to process, check for looping */
31456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            if (!note)
31556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            {
31656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                /* if no loop set state to stopping */
31756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                if (pData->repeatCount == 0)
31856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                {
31956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    pData->state = EAS_STATE_STOPPING;
32056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    VMReleaseAllVoices(pEASData->pVoiceMgr, pData->pSynth);
32156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    return EAS_SUCCESS;
32256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                }
32356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
32456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                /* decrement loop count */
32556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                if (pData->repeatCount != RTTTL_INFINITE_LOOP)
32656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    pData->repeatCount--;
32756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
32856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                /* if locating, ignore infinite loops */
32956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                else if (parserMode != eParserModePlay)
33056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                {
33156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    pData->state = EAS_STATE_STOPPING;
33256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    VMReleaseAllVoices(pEASData->pVoiceMgr, pData->pSynth);
33356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    return EAS_SUCCESS;
33456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                }
33556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
33656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                /* loop back to start of notes */
33756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                if ((result = EAS_HWFileSeek(pEASData->hwInstData, pData->fileHandle, pData->repeatOffset)) != EAS_SUCCESS)
33856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    return result;
33956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                continue;
34056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            }
34156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
34256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            /* still have a note to process */
34356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            else
34456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                c = ',';
34556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        }
34656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
34756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* bpm */
34856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (c == 'b')
34956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        {
35056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            /* peek at next character */
35156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            if ((result = RTTTL_PeekNextChar(pEASData->hwInstData, pData, &c)) != EAS_SUCCESS)
35256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                return result;
35356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
35456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            /* if a number, must be octave or tempo */
35556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            if (IsDigit(c))
35656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            {
35756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                if ((result = RTTTL_GetNumber(pEASData->hwInstData, pData, &temp)) != EAS_SUCCESS)
35856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    return result;
35956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
36056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                /* check for octave first */
36156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                if ((temp >= 4) && (temp <= 7))
36256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                {
36356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    octave = (EAS_U8) temp;
36456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                }
36556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
36656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                /* check for tempo */
36756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                else if ((temp >= 25) && (temp <= 900))
36856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                {
36956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    pData->tick = TICK_CONVERT / (EAS_U32) temp;
37056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                }
37156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
37256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                /* don't know what it was */
37356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                else
37456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    return EAS_ERROR_FILE_FORMAT;
37556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            }
37656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
37756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            /* must be a note */
37856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            else
37956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            {
38056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                note = noteTable[1];
38156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            }
38256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        }
38356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
38456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* octave */
38556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        else if (c == 'o')
38656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        {
38756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            if ((result = RTTTL_GetOctave(pEASData->hwInstData, pData, &pData->octave)) != EAS_SUCCESS)
38856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                return result;
38956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        }
39056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
39156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* style */
39256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        else if (c == 's')
39356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        {
39456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            if ((result = RTTTL_GetStyle(pEASData->hwInstData, pData)) != EAS_SUCCESS)
39556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                return result;
39656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        }
39756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
39856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* duration or octave */
39956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        else if (IsDigit(c))
40056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        {
40156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            RTTTL_PutBackChar(pData, c);
40256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
40356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            /* duration comes before note */
40456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            if (!note)
40556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            {
40656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                if ((result = RTTTL_GetDuration(pEASData->hwInstData, pData, &c)) != EAS_SUCCESS)
40756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    return result;
40856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                ticks = c * pData->tick;
40956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            }
41056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
41156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            /* octave comes after note */
41256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            else
41356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            {
41456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                if ((result = RTTTL_GetOctave(pEASData->hwInstData, pData, &octave)) != EAS_SUCCESS)
41556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    return result;
41656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            }
41756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        }
41856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
41956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* note or rest */
42056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        else if ((c >= 'a') && (c <= 'h'))
42156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        {
42256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            note = noteTable[c - 'a'];
42356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        }
42456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
42556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        else if (c == 'p')
42656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        {
42756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            note = RTTTL_REST;
42856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        }
42956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
43056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* dotted note */
43156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        else if (c == '.')
43256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        {
43356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            /*lint -e{704} shift for performance */
43456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            ticks += ticks >> 1;
43556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        }
43656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
43756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* accidental */
43856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        else if (c == '#')
43956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        {
44056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            if (note)
44156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                note++;
44256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        }
44356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
44456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* end of event */
44556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        else if ((c == ',') && note)
44656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        {
44756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
44856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            /* handle note events */
44956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            if (note != RTTTL_REST)
45056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            {
45156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
45256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                /* save note and start it */
45356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                pData->note = note + octave;
45456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                if (parserMode == eParserModePlay)
45556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    VMStartNote(pEASData->pVoiceMgr, pData->pSynth, RTTTL_CHANNEL, pData->note, RTTTL_VELOCITY);
45656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
45756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                /* determine note length */
45856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                switch (pData->style)
45956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                {
46056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    /* natural */
46156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    case 'n':
46256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                        /*lint -e{704} shift for performance */
46356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                        pData->restTicks = ticks >> 4;
46456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                        break;
46556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    /* continuous */
46656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
46756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    case 'c':
46856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                        pData->restTicks = 0;
46956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                        break;
47056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
47156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    /* staccato */
47256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    case 's':
47356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                        /*lint -e{704} shift for performance */
47456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                        pData->restTicks = ticks >> 1;
47556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                        break;
47656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
47756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    default:
47856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                        { /* dpp: EAS_ReportEx(_EAS_SEVERITY_WARNING, "RTTTL_Event: Unexpected style type %c\n", pData->style); */ }
47956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                        break;
48056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                }
48156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
48256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                /* next event is at end of this note */
48356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                pData->time += ticks - pData->restTicks;
48456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            }
48556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
48656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            /* rest */
48756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            else
48856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                pData->time += ticks;
48956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
49056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            /* event found, return to caller */
49156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            break;
49256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        }
49356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
49456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
49556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pData->state = EAS_STATE_PLAY;
49656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_SUCCESS;
49756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
49856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
49956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
50056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * RTTTL_State()
50156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
50256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
50356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Returns the current state of the stream
50456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
50556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
50656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pEASData         - pointer to overall EAS data structure
50756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * handle           - pointer to file handle
50856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pState           - pointer to variable to store state
50956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
51056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
51156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
51256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
51356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
51456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
51556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
51656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
51756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*lint -esym(715, pEASData) reserved for future use */
51856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT RTTTL_State (S_EAS_DATA *pEASData, EAS_VOID_PTR pInstData, EAS_I32 *pState)
51956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
52056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    S_RTTTL_DATA* pData;
52156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
52256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* establish pointer to instance data */
52356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pData = (S_RTTTL_DATA*) pInstData;
52456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
52556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* if stopping, check to see if synth voices are active */
52656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (pData->state == EAS_STATE_STOPPING)
52756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
52856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (VMActiveVoices(pData->pSynth) == 0)
52956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pData->state = EAS_STATE_STOPPED;
53056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
53156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
53256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (pData->state == EAS_STATE_PAUSING)
53356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
53456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (VMActiveVoices(pData->pSynth) == 0)
53556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pData->state = EAS_STATE_PAUSED;
53656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
53756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
53856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* return current state */
53956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    *pState = pData->state;
54056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_SUCCESS;
54156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
54256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
54356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
54456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * RTTTL_Close()
54556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
54656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
54756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Close the file and clean up
54856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
54956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
55056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pEASData         - pointer to overall EAS data structure
55156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * handle           - pointer to file handle
55256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
55356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
55456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
55556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
55656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
55756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
55856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
55956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
56056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT RTTTL_Close (S_EAS_DATA *pEASData, EAS_VOID_PTR pInstData)
56156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
56256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    S_RTTTL_DATA* pData;
56356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_RESULT result;
56456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
56556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pData = (S_RTTTL_DATA*) pInstData;
56656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
56756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* close the file */
56856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if ((result = EAS_HWCloseFile(pEASData->hwInstData, pData->fileHandle)) != EAS_SUCCESS)
56956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            return result;
57056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
57156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* free the synth */
57256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (pData->pSynth != NULL)
57356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        VMMIDIShutdown(pEASData, pData->pSynth);
57456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
57556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* if using dynamic memory, free it */
57656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (!pEASData->staticMemoryModel)
57756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        EAS_HWFree(pEASData->hwInstData, pData);
57856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
57956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_SUCCESS;
58056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
58156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
58256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
58356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * RTTTL_Reset()
58456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
58556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
58656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Reset the sequencer. Used for locating backwards in the file.
58756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
58856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
58956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pEASData         - pointer to overall EAS data structure
59056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * handle           - pointer to file handle
59156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
59256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
59356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
59456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
59556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
59656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
59756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
59856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
59956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT RTTTL_Reset (S_EAS_DATA *pEASData, EAS_VOID_PTR pInstData)
60056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
60156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    S_RTTTL_DATA* pData;
60256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_RESULT result;
60356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
60456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pData = (S_RTTTL_DATA*) pInstData;
60556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
60656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* reset the synth */
60756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    VMReset(pEASData->pVoiceMgr, pData->pSynth, EAS_TRUE);
60856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
60956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* reset time to zero */
61056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pData->time = 0;
61156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pData->note = 0;
61256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
61356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* reset file position and re-parse header */
61456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pData->state = EAS_STATE_ERROR;
61556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if ((result = EAS_HWFileSeek(pEASData->hwInstData, pData->fileHandle, pData->fileOffset)) != EAS_SUCCESS)
61656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return result;
61756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if ((result = RTTTL_ParseHeader (pEASData,  pData, EAS_TRUE)) != EAS_SUCCESS)
61856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return result;
61956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
62056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pData->state = EAS_STATE_READY;
62156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_SUCCESS;
62256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
62356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
62456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
62556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * RTTTL_Pause()
62656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
62756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
62856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Pauses the sequencer. Mutes all voices and sets state to pause.
62956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
63056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
63156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pEASData         - pointer to overall EAS data structure
63256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * handle           - pointer to file handle
63356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
63456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
63556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
63656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
63756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
63856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
63956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
64056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
64156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT RTTTL_Pause (S_EAS_DATA *pEASData, EAS_VOID_PTR pInstData)
64256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
64356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    S_RTTTL_DATA *pData;
64456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
64556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* can't pause a stopped stream */
64656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pData = (S_RTTTL_DATA*) pInstData;
64756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (pData->state == EAS_STATE_STOPPED)
64856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return EAS_ERROR_ALREADY_STOPPED;
64956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
65056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* mute the synthesizer */
65156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    VMMuteAllVoices(pEASData->pVoiceMgr, pData->pSynth);
65256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pData->state = EAS_STATE_PAUSING;
65356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_SUCCESS;
65456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
65556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
65656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
65756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * RTTTL_Resume()
65856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
65956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
66056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Resume playing after a pause, sets state back to playing.
66156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
66256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
66356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pEASData         - pointer to overall EAS data structure
66456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * handle           - pointer to file handle
66556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
66656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
66756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
66856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
66956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
67056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
67156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
67256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
67356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*lint -esym(715, pEASData) reserved for future use */
67456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT RTTTL_Resume (S_EAS_DATA *pEASData, EAS_VOID_PTR pInstData)
67556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
67656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    S_RTTTL_DATA *pData;
67756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
67856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* can't resume a stopped stream */
67956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pData = (S_RTTTL_DATA*) pInstData;
68056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (pData->state == EAS_STATE_STOPPED)
68156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return EAS_ERROR_ALREADY_STOPPED;
68256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
68356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* nothing to do but resume playback */
68456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pData->state = EAS_STATE_PLAY;
68556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_SUCCESS;
68656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
68756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
68856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
68956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * RTTTL_SetData()
69056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
69156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
69256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Return file type
69356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
69456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
69556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pEASData         - pointer to overall EAS data structure
69656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * handle           - pointer to file handle
69756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
69856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
69956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
70056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
70156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
70256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
70356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
70456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
70556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*lint -esym(715, pEASData) reserved for future use */
70656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT RTTTL_SetData (S_EAS_DATA *pEASData, EAS_VOID_PTR pInstData, EAS_I32 param, EAS_I32 value)
70756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
70856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    S_RTTTL_DATA *pData;
70956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
71056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pData = (S_RTTTL_DATA *) pInstData;
71156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    switch (param)
71256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
71356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
71456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* set metadata callback */
71556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        case PARSER_DATA_METADATA_CB:
71656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            EAS_HWMemCpy(&pData->metadata, (void*) value, sizeof(S_METADATA_CB));
71756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            break;
71856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
71956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        default:
72056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            return EAS_ERROR_INVALID_PARAMETER;
72156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
72256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
72356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_SUCCESS;
72456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
72556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
72656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
72756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * RTTTL_GetData()
72856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
72956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
73056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Return file type
73156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
73256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
73356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pEASData         - pointer to overall EAS data structure
73456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * handle           - pointer to file handle
73556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
73656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
73756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
73856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
73956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
74056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
74156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
74256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
74356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*lint -esym(715, pEASData) reserved for future use */
74456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT RTTTL_GetData (S_EAS_DATA *pEASData, EAS_VOID_PTR pInstData, EAS_I32 param, EAS_I32 *pValue)
74556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
74656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    S_RTTTL_DATA *pData;
74756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
74856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pData = (S_RTTTL_DATA *) pInstData;
74956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    switch (param)
75056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
75156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* return file type as RTTTL */
75256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        case PARSER_DATA_FILE_TYPE:
75356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            *pValue = EAS_FILE_RTTTL;
75456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            break;
75556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
75656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#if 0
75756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* set transposition */
75856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        case PARSER_DATA_TRANSPOSITION:
75956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            *pValue = pData->transposition;
76056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            break;
76156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#endif
76256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
76356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        case PARSER_DATA_SYNTH_HANDLE:
76456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            *pValue = (EAS_I32) pData->pSynth;
76556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            break;
76656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
76756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        case PARSER_DATA_GAIN_OFFSET:
76856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            *pValue = RTTTL_GAIN_OFFSET;
76956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            break;
77056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
77156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    default:
77256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            return EAS_ERROR_INVALID_PARAMETER;
77356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
77456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_SUCCESS;
77556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
77656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
77756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
77856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * RTTTL_GetStyle()
77956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
78056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
78156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
78256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
78356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
78456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
78556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
78656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
78756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
78856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
78956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
79056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
79156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
79256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
79356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT RTTTL_GetStyle (EAS_HW_DATA_HANDLE hwInstData, S_RTTTL_DATA *pData)
79456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
79556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_RESULT result;
79656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_I8 style;
79756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
79856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* get style */
79956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if ((result = RTTTL_GetNextChar(hwInstData, pData, &style)) != EAS_SUCCESS)
80056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return result;
80156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
80256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if ((style != 's')  && (style != 'n') && (style != 'c'))
80356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return EAS_ERROR_FILE_FORMAT;
80456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
80556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pData->style = style;
80656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_SUCCESS;
80756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
80856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
80956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
81056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * RTTTL_GetDuration()
81156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
81256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
81356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
81456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
81556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
81656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
81756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
81856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
81956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
82056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
82156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
82256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
82356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
82456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
82556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT RTTTL_GetDuration (EAS_HW_DATA_HANDLE hwInstData, S_RTTTL_DATA *pData, EAS_I8 *pDuration)
82656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
82756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_RESULT result;
82856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_I32 duration;
82956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_I8 temp;
83056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
83156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* get the duration */
83256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if ((result = RTTTL_GetNumber(hwInstData, pData, &duration)) != EAS_SUCCESS)
83356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return result;
83456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
83556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if ((duration != 1) && (duration != 2) && (duration != 4) && (duration != 8) && (duration != 16) && (duration != 32))
83656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return EAS_ERROR_FILE_FORMAT;
83756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
83856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    temp = 64;
83956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    while (duration)
84056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
84156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /*lint -e{704} shift for performance */
84256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        duration = duration >> 1;
84356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /*lint -e{702} use shift for performance */
84456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        temp = temp >> 1;
84556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
84656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
84756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    *pDuration = temp;
84856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_SUCCESS;
84956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
85056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
85156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
85256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * RTTTL_GetOctave()
85356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
85456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
85556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
85656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
85756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
85856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
85956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
86056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
86156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
86256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
86356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
86456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
86556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
86656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
86756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT RTTTL_GetOctave (EAS_HW_DATA_HANDLE hwInstData, S_RTTTL_DATA *pData, EAS_U8 *pOctave)
86856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
86956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_RESULT result;
87056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_I32 octave;
87156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
87256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* get the tempo */
87356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if ((result = RTTTL_GetNumber(hwInstData, pData, &octave)) != EAS_SUCCESS)
87456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return result;
87556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
87656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if ((octave < 4) || (octave > 7))
87756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return EAS_ERROR_FILE_FORMAT;
87856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
87956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    *pOctave = (EAS_U8) (octave * 12);
88056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_SUCCESS;
88156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
88256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
88356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
88456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * RTTTL_GetTempo()
88556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
88656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
88756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
88856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
88956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
89056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
89156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
89256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
89356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
89456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
89556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
89656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
89756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
89856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
89956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT RTTTL_GetTempo (EAS_HW_DATA_HANDLE hwInstData, S_RTTTL_DATA *pData)
90056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
90156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_RESULT result;
90256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_I32 tempo;
90356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
90456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* get the tempo */
90556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if ((result = RTTTL_GetNumber(hwInstData, pData, &tempo)) != EAS_SUCCESS)
90656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return result;
90756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
90856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if ((tempo < 25) || (tempo > 900))
90956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return EAS_ERROR_FILE_FORMAT;
91056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
91156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pData->tick = TICK_CONVERT / (EAS_U32) tempo;
91256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_SUCCESS;
91356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
91456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
91556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
91656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * RTTTL_GetNumber()
91756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
91856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
91956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
92056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
92156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
92256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
92356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
92456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
92556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
92656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
92756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
92856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
92956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
93056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
93156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT RTTTL_GetNumber (EAS_HW_DATA_HANDLE hwInstData, S_RTTTL_DATA *pData, EAS_I32 *pValue)
93256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
93356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_RESULT result;
93456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_INT temp;
93556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_I8 c;
93656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
93756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    *pValue = -1;
93856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    temp = 0;
93956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    for (;;)
94056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
94156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if ((result = RTTTL_PeekNextChar(hwInstData, pData, &c)) != EAS_SUCCESS)
94256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        {
94356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            if ((result == EAS_EOF) && (*pValue != -1))
94456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                return EAS_SUCCESS;
94556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            return result;
94656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        }
94756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
94856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (IsDigit(c))
94956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        {
95056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pData->dataByte = 0;
95156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            temp = temp * 10 + c - '0';
95256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            *pValue = temp;
95356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        }
95456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        else
95556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            return EAS_SUCCESS;
95656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
95756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
95856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
95956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
96056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * RTTTL_ParseHeader()
96156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
96256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
96356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Prepare to parse the file. Allocates instance data (or uses static allocation for
96456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * static memory model).
96556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
96656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
96756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pEASData         - pointer to overall EAS data structure
96856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * handle           - pointer to file handle
96956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
97056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
97156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
97256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
97356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
97456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
97556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
97656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
97756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT RTTTL_ParseHeader (S_EAS_DATA *pEASData, S_RTTTL_DATA* pData, EAS_BOOL metaData)
97856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
97956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_RESULT result;
98056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_I32 i;
98156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_I8 temp;
98256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_I8 control;
98356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
98456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* initialize some defaults */
98556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pData->time = 0;
98656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pData->tick = DEFAULT_TICK_CONV;
98756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pData->note = 0;
98856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pData->duration = 4;
98956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pData ->restTicks = 0;
99056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pData->octave = 60;
99156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pData->repeatOffset = -1;
99256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pData->repeatCount = 0;
99356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pData->style = 'n';
99456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pData->dataByte = 0;
99556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
99656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    metaData = metaData && (pData->metadata.buffer != NULL) && (pData->metadata.callback != NULL);
99756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
99856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* seek to start of data */
99956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if ((result = EAS_HWFileSeek(pEASData->hwInstData, pData->fileHandle, pData->fileOffset)) != EAS_SUCCESS)
100056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return result;
100156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
100256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* zero the metadata buffer */
100356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (metaData)
100456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        EAS_HWMemSet(pData->metadata.buffer, 0, pData->metadata.bufferSize);
100556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
100656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* read the title */
100756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    for (i = 0; i < RTTTL_MAX_TITLE_LEN; i++)
100856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
100956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if ((result = EAS_HWGetByte(pEASData->hwInstData, pData->fileHandle, &temp)) != EAS_SUCCESS)
101056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            return result;
101156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
101256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (temp == ':')
101356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            break;
101456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
101556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* pass along metadata */
101656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (metaData)
101756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        {
101856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            if (i < (pData->metadata.bufferSize- 1))
101956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                pData->metadata.buffer[i] = (char) temp;
102056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        }
102156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
102256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
102356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* check for error in title */
102456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (i == RTTTL_MAX_TITLE_LEN)
102556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return EAS_ERROR_FILE_FORMAT;
102656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
102756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* pass along metadata */
102856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (metaData)
102956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        (*pData->metadata.callback)(EAS_METADATA_TITLE, pData->metadata.buffer, pData->metadata.pUserData);
103056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
103156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* control fields */
103256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    for (;;)
103356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
103456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
103556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* get control type */
103656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if ((result = RTTTL_GetNextChar(pEASData->hwInstData, pData, &control)) != EAS_SUCCESS)
103756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            return result;
103856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
103956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* next char should be equal sign */
104056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if ((result = RTTTL_GetNextChar(pEASData->hwInstData, pData, &temp)) != EAS_SUCCESS)
104156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            return result;
104256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (temp != '=')
104356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            return EAS_ERROR_FILE_FORMAT;
104456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
104556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* get the control value */
104656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        switch (control)
104756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        {
104856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
104956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            /* bpm */
105056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            case 'b':
105156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                if ((result = RTTTL_GetTempo(pEASData->hwInstData, pData)) != EAS_SUCCESS)
105256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    return result;
105356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                break;
105456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
105556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            /* duration */
105656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            case 'd':
105756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                if ((result = RTTTL_GetDuration(pEASData->hwInstData, pData, &temp)) != EAS_SUCCESS)
105856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    return result;
105956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                pData->duration = temp;
106056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                break;
106156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
106256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            /* loop */
106356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            case 'l':
106456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                if ((result = RTTTL_GetNumber(pEASData->hwInstData, pData, &i)) != EAS_SUCCESS)
106556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    return result;
106656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                if ((i < 0) || (i > 15))
106756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    return EAS_ERROR_FILE_FORMAT;
106856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                pData->repeatCount = (EAS_U8) i;
106956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                break;
107056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
107156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            /* octave */
107256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            case 'o':
107356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                if ((result = RTTTL_GetOctave(pEASData->hwInstData, pData, &pData->octave)) != EAS_SUCCESS)
107456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    return result;
107556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                break;
107656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
107756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            /* get style */
107856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            case 's':
107956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                if ((result = RTTTL_GetStyle(pEASData->hwInstData, pData)) != EAS_SUCCESS)
108056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    return result;
108156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                break;
108256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
108356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            /* unrecognized control */
108456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            default:
108556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                return EAS_ERROR_FILE_FORMAT;
108656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        }
108756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
108856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* next character should be comma or colon */
108956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if ((result = RTTTL_GetNextChar(pEASData->hwInstData, pData, &temp)) != EAS_SUCCESS)
109056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            return result;
109156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
109256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* check for end of control field */
109356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (temp == ':')
109456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            break;
109556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
109656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* must be a comma */
109756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (temp != ',')
109856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            return EAS_ERROR_FILE_FORMAT;
109956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
110056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
110156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* should be at the start of the music block */
110256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if ((result = EAS_HWFilePos(pEASData->hwInstData, pData->fileHandle, &pData->repeatOffset)) != EAS_SUCCESS)
110356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return result;
110456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
110556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_SUCCESS;
110656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
110756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
110856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
110956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * RTTTL_GetNextChar()
111056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
111156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
111256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
111356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
111456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
111556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
111656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
111756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
111856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
111956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
112056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
112156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
112256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
112356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
112456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT RTTTL_GetNextChar (EAS_HW_DATA_HANDLE hwInstData, S_RTTTL_DATA *pData, EAS_I8 *pValue)
112556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
112656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_RESULT result;
112756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_I8 temp;
112856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
112956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    *pValue = 0;
113056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    for(;;)
113156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
113256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
113356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* check for character that has been put back */
113456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (pData->dataByte)
113556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        {
113656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            temp = pData->dataByte;
113756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pData->dataByte = 0;
113856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        }
113956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        else
114056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        {
114156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            if ((result = EAS_HWGetByte(hwInstData, pData->fileHandle, &temp)) != EAS_SUCCESS)
114256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                return result;
114356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        }
114456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
114556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* ignore white space */
114656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (!IsSpace(temp))
114756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        {
114856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            *pValue = ToLower(temp);
114956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            return EAS_SUCCESS;
115056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        }
115156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
115256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
115356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
115456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
115556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * RTTTL_PeekNextChar()
115656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
115756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
115856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
115956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
116056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
116156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
116256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
116356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
116456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
116556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
116656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
116756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
116856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
116956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
117056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT RTTTL_PeekNextChar (EAS_HW_DATA_HANDLE hwInstData, S_RTTTL_DATA *pData, EAS_I8 *pValue)
117156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
117256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_RESULT result;
117356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_I8 temp;
117456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
117556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    *pValue = 0;
117656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    for(;;)
117756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
117856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
117956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* read a character from the file, if necessary */
118056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (!pData->dataByte)
118156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        {
118256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            if ((result = EAS_HWGetByte(hwInstData, pData->fileHandle, &pData->dataByte)) != EAS_SUCCESS)
118356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                return result;
118456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
118556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        }
118656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        temp = pData->dataByte;
118756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
118856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* ignore white space */
118956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (!IsSpace(temp))
119056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        {
119156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            *pValue = ToLower(temp);
119256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            return EAS_SUCCESS;
119356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        }
119456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pData->dataByte = 0;
119556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
119656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
119756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
1198