MusicPlayer vol2 -MusicPlayer.h-

2011/11/19

Music Sequence についての内容 ※間違いが含まれている場合があるので注意

CABarBeatTime

#if TARGET_OS_IPHONE
// CAClock is currently not supported on iOS, so we include the definition of this structure here 
// (otherwise we include the CAClock header
/*!
    @struct     CABarBeatTime
    @abstract   A display representation of a musical time in beats.
    
    @field  bar
                A measure number.
    @field  beat
                A beat number (1..n).
    @field  subbeat
                The numerator of the fractional number of beats.
    @field  subbeatDivisor
                The denominator of the fractional number of beats.
    @field  reserved
                Must be 0.
    @discussion
                A clock's internal representation of musical time is in beats based on the
                beginning of the timeline. Normally, such times should be displayed to the user
                in terms of bars, beats, and subbeats (sometimes called "units" or "parts per
                quarter" [PPQ]). This data structure is such a display representation.

                By convention, bar 1 is the beginning of the sequence. Beat 1 is the first beat
                of the measure. In 4/4 time, beat will have a value from 1 to 4. Music
                applications often use beat divisions such as 480 and 960.
*/
struct CABarBeatTime {
    SInt32              bar;
    UInt16              beat;
    UInt16              subbeat;
    UInt16              subbeatDivisor;
    UInt16              reserved;
};
typedef struct CABarBeatTime CABarBeatTime;
#else
    #include 
#endif

iOS は現在 CAClock に対応していないので、CABarBeatTime を利用する。 その名の通り、CoreAudio を小節・拍の時間を扱うもの。

  • bar - 小節
  • beat - 拍
  • subbeat -サブ拍
  • subbeat -サブ拍の区切り
  • subbeatDivisor
  • reserved - 未使用

MusicSequenceUserCallback

[ccp] typedef struct OpaqueMusicPlayer *MusicPlayer; typedef struct OpaqueMusicSequence *MusicSequence; typedef struct OpaqueMusicTrack *MusicTrack; typedef struct OpaqueMusicEventIterator *MusicEventIterator;

/! @typedef MusicSequenceUserCallback @discussion See MusicSequenceSetUserCallback */ typedef void (MusicSequenceUserCallback)( void *inClientData, MusicSequence inSequence, MusicTrack inTrack, MusicTimeStamp inEventTime, const MusicEventUserData *inEventData, MusicTimeStamp inStartSliceBeat, MusicTimeStamp inEndSliceBeat);

/*! @enum MusicPlayerErrors @constant kAudioToolboxErr_InvalidSequenceType @constant kAudioToolboxErr_TrackIndexError @constant kAudioToolboxErr_TrackNotFound @constant kAudioToolboxErr_EndOfTrack @constant kAudioToolboxErr_StartOfTrack @constant kAudioToolboxErr_IllegalTrackDestination @constant kAudioToolboxErr_NoSequence @constant kAudioToolboxErr_InvalidEventType @constant kAudioToolboxErr_InvalidPlayerState @constant kAudioToolboxErr_CannotDoInCurrentContext */ enum { kAudioToolboxErr_InvalidSequenceType = -10846, kAudioToolboxErr_TrackIndexError = -10859, kAudioToolboxErr_TrackNotFound = -10858, kAudioToolboxErr_EndOfTrack = -10857, kAudioToolboxErr_StartOfTrack = -10856, kAudioToolboxErr_IllegalTrackDestination = -10855, kAudioToolboxErr_NoSequence = -10854, kAudioToolboxErr_InvalidEventType = -10853, kAudioToolboxErr_InvalidPlayerState = -10852, kAudioToolboxErr_CannotDoInCurrentContext = -10863 }; シーケンサー利用時のユーザ定義コールバック関数型 シーケンサーにMusicEventUserData が存在する場合、呼び出される。 MusicSequence、MusicTrack、MusicTimeStamp、MusicEventUserData 対応 MusicPlayerErrorsを 持つ

MusicTrackProperties

/*!
    @enum MusicTrackProperties
    @discussion Property values are always get and set by reference
    
    @constant   kSequenceTrackProperty_LoopInfo
        read/write  - MusicTrackLoopInfo
        The default looping behaviour is off (track plays once)
        Looping is set by specifying the length of the loop. It loops from
            (TrackLength - loop length) to Track Length
            If numLoops is set to zero, it will loop forever.
        To turn looping off, you set this with loop length equal to zero.

    @constant   kSequenceTrackProperty_OffsetTime
        read/write  - MusicTimeStamp
        offset's the track's start time to the specified beat. By default this value is zero.
        
    @constant   kSequenceTrackProperty_MuteStatus
        read/write  - Boolean
        mute state of a track. By default this value is false (not muted)
        
    @constant   kSequenceTrackProperty_SoloStatus
        read/write  - Boolean
        solo state of a track. By default this value is false (not soloed)

    @constant   kSequenceTrackProperty_AutomatedParameters
        read/write  - UInt32
        Determines whether a track is used for automating parameters.
        If set to != 0 the track is used to automate parameter events to an AUNode.
        The track can only contain parameter events and these events are interpreted 
        as points in the automation curve
        
    @constant   kSequenceTrackProperty_TrackLength
        read/write  - MusicTimeStamp
        The time of the last event in the track plus any additional time that is allowed for fading out of ending notes
        or round a loop point to musical bar, etc.
        
        If this is not set, the track length will always be adjusted to the end of the last active event in a track and 
        is adjusted dynamically as events are added or removed.
        
        The property will return the max of the user set track length, or the calculated length
        
    @constant   kSequenceTrackProperty_TimeResolution
        read only   - SInt16 (only valid on the Tempo track)
        
        This retrieves the time resolution value for a sequence. This time resolution can be the resolution that
        was contained within the midi file used to construct a sequence. If you want to keep a time resolution
        when writing a new file, you can retrieve this value and then specify it when creating a new file from a sequence.
        
        It has no direct baring on the rendering or notion of time of the sequence itself (just its representation in file
        formats such as MIDI files). By default this is set to either:
            480 if the sequence is created manually
            some_value based on what was in a MIDI file if the sequence was created from a MIDI file        
*/
enum
{
    kSequenceTrackProperty_LoopInfo = 0,
    kSequenceTrackProperty_OffsetTime = 1,
    kSequenceTrackProperty_MuteStatus = 2,
    kSequenceTrackProperty_SoloStatus = 3,
    // added in 10.2
    kSequenceTrackProperty_AutomatedParameters = 4,
    // added in 10.3
    kSequenceTrackProperty_TrackLength = 5,
    // added in 10.5
    kSequenceTrackProperty_TimeResolution = 6
};

プロパティの値は、常に参照によるgetter、setter を用意している。 コンスタント kSequenceTrackProperty_LoopInfo = ループ情報。デフォルトのループは OFF(1回だけ再生) kSequenceTrackProperty_OffsetTime = 指定したビートにトラックのスタート時間(MusicTimeStamp)へオフセットする。デフォルトは0 kSequenceTrackProperty_MuteStatus = トラックのミュート状態。デフォルトは無効 kSequenceTrackProperty_SoloStatus = トラックのソロ状態。デフォルトは無効

MusicTrackLoopInfo

/*!
    @struct     MusicTrackLoopInfo
    @discussion Used to control the looping behaviour of a track
*/
typedef struct MusicTrackLoopInfo
{
    MusicTimeStamp      loopDuration;
    SInt32              numberOfLoops;
} MusicTrackLoopInfo;

loopDuration = ループの長さ numberOfLoops = ループの回数