view jssplr.h @ 0:32250b436bca

Initial re-import.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 28 Sep 2012 01:54:23 +0300
parents
children e0e470c3fc8e
line wrap: on
line source

/*
 * miniJSS - Module playing routines
 * Programmed and designed by Matti 'ccr' Hamalainen
 * (C) Copyright 2006-2007 Tecnic Software productions (TNSP)
 */
#ifndef JSSPLR_H
#define JSSPLR_H

#include "jss.h"
#include "jssmod.h"
#include "jssmix.h"


// Player general constants
#define mpMinVol            (0)
#define mpMaxVol            (64)
#define mpPanCenter         (0)
#define mpMaxFadeoutVol     (65535)


// Channel New-Data flags
#define cdfNONE             (0x00)    // Set nothing
#define cdfNewInstr         (0x01)    // Set a new instrument
#define cdfNewPitch         (0x02)    // Set a new pitch
#define cdfNewPos           (0x04)    // Set a new position
#define cdfNewVolume        (0x08)    // Set a new volume
#define cdfNewPanPos        (0x10)    // Set a new panning position
#define cdfNewGlobalVol     (0x20)    // Set a new global volume
#define cdfStop             (0x80)    // Stop channel playing


// Typedefs for channel structures
typedef int                  JDInt[jsetNChannels];
typedef BOOL                 JDBool[jsetNChannels];
typedef JSSInstrument *      JDInst[jsetNChannels];
typedef JSSExtInstrument *   JDEInst[jsetNChannels];


// Struct holding all player related information
typedef struct
{
    // General variables
    int     iTempo,                 // Current values
            iSpeed,
            iTick,
            iOrder,
            iPattern,
            iRow,
            iGlobalVol,
            iOptions;               // Playing option flags
    BOOL    isPlaying;              // Are we playing?

    int     iNewOrder,              // NEW order number
            iNewRow;                // NEW row number
    BOOL    newOrderSet,            // TRUE if new order has been set
            newRowSet;              // TRUE if new row has been set

    // Parameters for effects, etc
    BOOL    jumpFlag,               // Pattern jump flag
            breakFlag;              // Pattern break flag
    int     iPatternDelay,          // Pattern delay tick-counter
            iLastPatLoopRow;        // Latest set pattern loop row (any channel)

    JDInt   iPatLoopRow,            // Pattern loop start row for each channel
            iPatLoopCount,          // Pattern loop count for each channel
        
            iLastPortaParam,        // Last portamento effect parameter
            iLastPortaToNoteParam,  // Last porta-to-note parameter
            iLastPortaToNotePitch,  // Last porta-to-note pitch

            iVibratoPos,            // Vibrato waveform position
            iVibratoSpeed,          // Vibrato speed
            iVibratoDepth,          // Vibrato depth
            iVibratoWC,             // Vibrato wave control

            iTremoloPos,            // Tremolo waveform position
            iTremoloSpeed,          // Tremolo speed
            iTremoloDepth,          // Tremolo depth

            iTremoloWC,             // Tremolo wave control

            iLastTremorParam,
            iTremorCount,
            iLastSampleOffset,
            iLastRetrigParam,
            iLastVolSlideParam,
        
            iRetrigNDFlags,         // For retrig-effect
            iSaveNDFlags;           // For notedelay-effect

    // Current channel data
    JDInst  iCInstrument;           // Instruments
    JDEInst iCExtInstrument;       // ExtInstruments
    JDInt   iCInstrumentN,
            iCExtInstrumentN,
            iCNewDataFlags,         // New data flags
            iCNote,                 // Current notes
            iCPitch,                // Pitches (NOT actual frequencies!)
            iCOldPitch,
            iCPosition,             // Sample positions
            iCVolume,               // Volumes
            iCPanning,              // Panning positions

            iCFadeOutVol,

            iCPanEnv,
            iCVolEnv,

            iCAutoVib_Frames,
            iCPanEnv_Frames,
            iCVolEnv_Frames,

            iCLastFineVolumeslideUpParam,
            iCLastFineVolumeslideDownParam,
            iCLastExtraFinePortamentoUpParam,
            iCLastExtraFinePortamentoDownParam,
            iCLastFinePortamentoUpParam,
            iCLastFinePortamentoDownParam;
    
    JDBool  iCPanEnv_Exec,
            iCVolEnv_Exec,
            iCKeyOff;

    // Module and sounddevice specific
    JSSModule *pModule;          // Current module in this player
    JSSPattern *pPattern;        // Current pattern
    JSSMixer *pDevice;           // Pointer to mixing device structure

#ifdef JSS_SUP_THREADS
    DMMutex *mutex;
#endif

} JSSPlayer;


/* External functions for end users
 */
int             jmpPlayOrder(JSSPlayer *, int);
int             jmpPlayPattern(JSSPlayer *, int);
void            jmpStop(JSSPlayer *);
void            jmpResume(JSSPlayer *);
void            jmpSetModule(JSSPlayer *, JSSModule *);
JSSPlayer *     jmpInit(JSSMixer *);
int             jmpClose(JSSPlayer *);
void            jmpExec(void *, void *);


/* Helper macros
 */
#define JMPMAKEPARAM(AIVAL, AVALX, AVALY) { AVALX = (((AIVAL) >> 4) & 0x0f); AVALY = ((AIVAL) & 0x0f); }
#define JMPSETNDFLAGS(IVAL) mp->iCNewDataFlags[channel] |= IVAL
#define JMPUNSETNDFLAGS(IVAL) mp->iCNewDataFlags[channel] &= (~(IVAL))
#define JMPGETNOTE(MNOTE, MROW, MCHAN) assert(mp); assert(mp->pPattern); assert((MROW) >= 0); assert((MROW) < mp->pPattern->nrows); MNOTE = &mp->pPattern->data[(mp->pPattern->nchannels * MROW) + (MCHAN)]
#define JMPGETEFFECT(MEFF, MIEFF) if ((MIEFF >= 0) && (MIEFF < jmpNMODEffectTable)) MEFF = jmpMODEffectTable[MIEFF]; else MEFF = 0
#define JMPGETMODFLAGS(Q, Z) ((Q->pModule->defFlags & (Z)) == (Z))


/* Debugging macros
 */
#if !defined(JSS_LIGHT) && defined(JSS_DEBUG)
#  define JMPDEBUG(QQ) { fprintf(stderr, "[o=%03d:p=%03d:r=%03d] (%c/%x:%x) %s\n", mp->iOrder, mp->iPattern, mp->iRow, effect, currNote->effect, currNote->param, QQ ); }
#else
#  define JMPDEBUG(QQ) // stub
#endif

#endif // JSSPLR_H