亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? midistrm.cpp

?? 6410BSP3
?? CPP
字號:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
// -----------------------------------------------------------------------------
//
//      THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
//      ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
//      THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//      PARTICULAR PURPOSE.
//
// -----------------------------------------------------------------------------

#include "wavemain.h"


void CMidiStream::GainChange()
{
    PLIST_ENTRY pListEntry;
    CMidiNote *pCNote;
    pListEntry = m_NoteList.Flink;
    while (pListEntry != &m_NoteList)
    {
        // Get a pointer to the stream context
        pCNote = CONTAINING_RECORD(pListEntry,CMidiNote,m_Link);
        pCNote->GainChange();
        pListEntry = pListEntry->Flink;
    }
}


DWORD CMidiStream::MapNoteGain(DWORD NoteGain)
{
    DWORD TotalGain = NoteGain & 0xFFFF;
    DWORD StreamGain = m_dwGain & 0xFFFF;

    TotalGain *= StreamGain; // Calc. aggregate gain
    TotalGain += 0xFFFF;   // Force to round up
    TotalGain >>= 16;

    return MapGain(TotalGain);
}


HRESULT CMidiStream::Open(DeviceContext *pDeviceContext, LPWAVEOPENDESC lpWOD, DWORD dwFlags)
{
    HRESULT Result;
    LPWAVEFORMAT_MIDI pwfxmidi = (LPWAVEFORMAT_MIDI) lpWOD->lpFormat;

    if (pwfxmidi->wfx.cbSize!=WAVEFORMAT_MIDI_EXTRASIZE)
    {
        return E_FAIL;
    }

    m_USecPerQuarterNote  = pwfxmidi->USecPerQuarterNote;
    m_TicksPerQuarterNote = pwfxmidi->TicksPerQuarterNote;

    UpdateTempo();

    m_DeltaSampleCount=0;

    // Add all notes to free list
    InitializeListHead(&m_NoteList);
    InitializeListHead(&m_FreeList);
    for (int i=0;i<NUMNOTES;i++)
    {
        InsertTailList(&m_FreeList,&m_MidiNote[i].m_Link);
    }

    Result = StreamContext::Open(pDeviceContext, lpWOD, dwFlags);

    if (Result==MMSYSERR_NOERROR)
    {
        // Note: Output streams should be initialized in the run state.
        Run();
    }

    return Result;
}


DWORD CMidiStream::Reset()
{
    DWORD dwResult = StreamContext::Reset();
    if (dwResult==MMSYSERR_NOERROR)
    {
        AllNotesOff(0);

        // Note: Output streams should be reset to the run state.
        Run();
    }
    return dwResult;
}


DWORD CMidiStream::Close()
{
    DWORD dwResult = StreamContext::Close();
    if (dwResult==MMSYSERR_NOERROR)
    {
        AllNotesOff(0);
    }
    return dwResult;
}


HRESULT CMidiStream::UpdateTempo()
{
    if (m_USecPerQuarterNote==0)
    {
        m_USecPerQuarterNote = 500000; // If not specified, assume 500000usec = 1/2 sec per quarter note
    }

    if (m_TicksPerQuarterNote==0)
    {
        m_TicksPerQuarterNote = 96;      // If not specified, assume 96 ticks/quarter note
    }

    UINT64 Num = SAMPLERATE;
    Num *= m_USecPerQuarterNote;
    UINT64 Den = 1000000;
    Den *= m_TicksPerQuarterNote;
    UINT64 SamplesPerTick = Num/Den;
    m_SamplesPerTick = (UINT32)SamplesPerTick;
    return S_OK;
}


// Return the delta # of samples until the next midi event
// or 0 if no midi events are left in the queue
UINT32 CMidiStream::ProcessMidiStream()
{
    WAVEFORMAT_MIDI_MESSAGE *pMsg;
    WAVEFORMAT_MIDI_MESSAGE *pMsgEnd;
    UINT32 ThisMidiEventDelta;

    // Process all midi messages up to and including the current sample
    pMsg    = (WAVEFORMAT_MIDI_MESSAGE *)m_lpCurrData;
    pMsgEnd = (WAVEFORMAT_MIDI_MESSAGE *)m_lpCurrDataEnd;

    for (;;)
    {
        if (pMsg>=pMsgEnd)
        {
            pMsg = (WAVEFORMAT_MIDI_MESSAGE *)GetNextBuffer();
            if (!pMsg)
            {
                DEBUGMSG(ZONE_ERROR, (TEXT("CMidiStream::ProcessMidiStream no more events\r\n")));
                return 0;
            }
            pMsgEnd = (WAVEFORMAT_MIDI_MESSAGE *)m_lpCurrDataEnd;
        }

        ThisMidiEventDelta = DeltaTicksToSamples(pMsg->DeltaTicks);
        if (ThisMidiEventDelta > m_DeltaSampleCount)
        {
            m_lpCurrData = (PBYTE)pMsg;
            INT32 Delta = ThisMidiEventDelta-m_DeltaSampleCount;
            DEBUGMSG(ZONE_FUNCTION, (TEXT("CMidiStream::ProcessMidiStream next event @delta %d\r\n"),Delta));
            return Delta;
        }

        DEBUGMSG(ZONE_FUNCTION, (TEXT("CMidiStream::ProcessMidiStream sending midi message 0x%x\r\n"),pMsg->MidiMsg));
        InternalMidiMessage(pMsg->MidiMsg);
        m_DeltaSampleCount=0;
        pMsg++;
    }
}


PBYTE CMidiStream::Render(PBYTE pBuffer, PBYTE pBufferEnd, PBYTE pBufferLast)
{

    DEBUGMSG(ZONE_FUNCTION, (TEXT("Entering CMidiStream::Render, pBuffer=0x%x, current delta = %d\r\n"), pBuffer, m_DeltaSampleCount));

    // If we're not running, or we don't have any buffers queued and the note list is empty,
    // just return
    if ( (!m_bRunning) || (!StillPlaying() && IsListEmpty(&m_NoteList)) )
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("CMidiStream::Render nothing to do\r\n")));
        return pBuffer;
    }

    while (pBuffer<pBufferEnd)
    {
        // Process pending midi messages and get relative sample # of next midi event
        UINT32 NextMidiEvent;
        NextMidiEvent = ProcessMidiStream();

        PBYTE pBufferEndEvent;  // Where to stop on this pass

        // If NextMidiEvent returns 0, it means there are no more midi messages left in the queue.
        if (NextMidiEvent==0)
        {
            // Just process the rest of this buffer
            pBufferEndEvent=pBufferEnd;
        }
        // NextMidiEvent is non-zero, and represents the delta sample value of the next midi event
        else
        {
            // Convert to be a pointer in this buffer
            pBufferEndEvent = pBuffer + (NextMidiEvent * (sizeof(HWSAMPLE) * OUTCHANNELS));

            // If the next event occurs after this buffer, just finish processing this buffer
            if (pBufferEndEvent>pBufferEnd)
            {
                pBufferEndEvent=pBufferEnd;
            }
        }

        // Update the delta for the samples we're about to process
        m_DeltaSampleCount += ((pBufferEndEvent-pBuffer)/(sizeof(HWSAMPLE) * OUTCHANNELS));

        // Process existing notes
        PLIST_ENTRY pListEntry;
        pListEntry = m_NoteList.Flink;
        while (pListEntry != &m_NoteList)
        {
            CMidiNote *pCNote;

            // Get a pointer to the stream context
            pCNote = CONTAINING_RECORD(pListEntry,CMidiNote,m_Link);

            // Get next list entry, since Render may cause note to go away
            pListEntry = pListEntry->Flink;

            PBYTE pBufferLastThis;
            pBufferLastThis = pCNote->Render(pBuffer, pBufferEndEvent, pBufferLast);
            if (pBufferLast < pBufferLastThis)
            {
                pBufferLast = pBufferLastThis;
            }
        }

        pBuffer = pBufferEndEvent;
    }

    // We need to make sure we clear any unwritten section of the buffer to make sure the DMA controller doesn't stop
    StreamContext::ClearBuffer(pBufferLast,pBufferEnd);
    pBufferLast=pBufferEnd;

    DEBUGMSG(ZONE_FUNCTION, (TEXT("CMidiStream::Render returning, pBufferLast=0x%x, pBufferEnd=0x%x\r\n"),pBufferLast,pBufferEnd));
    return pBufferLast;
}


DWORD CMidiStream::MidiMessage(UINT32 dwMessage)
{
    HRESULT Result;

    Result = InternalMidiMessage(dwMessage);

    // If we're running, and the notelist has notes to render, make sure DMA is enabled
    if ( (m_bRunning) && (m_NoteList.Flink != &m_NoteList) )
    {
        m_pDeviceContext->StreamReadyToRender(this);
    }

    return (Result==S_OK) ? MMSYSERR_NOERROR : MMSYSERR_ERROR;
}


// Assumes lock is taken, and we're already positioned at the correct point in the stream
HRESULT CMidiStream::InternalMidiMessage(UINT32 dwData)
{
    UINT32 OpCode = dwData & 0xF0000000;
    switch (OpCode)
    {
    case 0:
        return MidiData(dwData);
    case MIDI_MESSAGE_UPDATETEMPO:
        m_USecPerQuarterNote  = (dwData & 0xFFFFFF);
        return UpdateTempo();
    case MIDI_MESSAGE_FREQGENON:
    case MIDI_MESSAGE_FREQGENOFF:
        {
            UINT32 dwNote = ((dwData) & 0xffff);
            UINT32 dwVelocity = ((dwData >> 16) & 0x7f) ;
            if ((OpCode==MIDI_MESSAGE_FREQGENON)  && (dwVelocity>0))
            {
                return NoteOn(dwNote, dwVelocity, FREQCHANNEL);
            }
            else
            {
                return NoteOff(dwNote, dwVelocity, FREQCHANNEL);
            }
        }
    }
    return E_NOTIMPL;
}


HRESULT CMidiStream::MidiData(UINT32 dwData)
{
    HRESULT Result=E_NOTIMPL;
    UINT32 dwChannel;
    UINT32 dwNote;
    UINT32 dwVelocity;

    if (dwData & 0x80)
    {
        m_RunningStatus = dwData&0xFF;      // status byte...
    }
    else
    {
        dwData = (dwData<<8) | m_RunningStatus;
    }

    dwChannel  = (dwData & 0x0f) ;
    dwNote     = ((dwData >> 8) & 0x7f) ;
    dwVelocity = ((dwData >> 16) & 0x7f) ;

    switch (dwData & 0xf0)
    {
    case 0x90:  // Note on
        if (dwVelocity!=0)
        {
            Result = NoteOn(dwNote, dwVelocity, dwChannel);
            break;
        }
        // If dwVelocity is 0, this is really a note off message, so fall through

    case 0x80:  // Note off
        Result = NoteOff(dwNote, dwVelocity, dwChannel);
        break;

    case 0xB0:  // Control change
        {
            switch (dwNote)
            {
            case 123:   // turns all notes off
                {
                    Result = AllNotesOff(0);
                    break;
                }
            }
            break;
        }
    }

    return Result;
}


CMidiNote *CMidiStream::FindNote(UINT32 dwNote, UINT32 dwChannel)
{
    PLIST_ENTRY pListEntry;
    CMidiNote *pCNote;
    pListEntry = m_NoteList.Flink;
    while (pListEntry != &m_NoteList)
    {
        // Get a pointer to the stream context
        pCNote = CONTAINING_RECORD(pListEntry,CMidiNote,m_Link);

        if (pCNote->NoteVal()==dwNote && pCNote->NoteChannel()==dwChannel)
        {
            return pCNote;
        }

        pListEntry = pListEntry->Flink;
    }
    return NULL;
}


// Assumes lock is taken, and we're already positioned at the correct point in the stream
HRESULT CMidiStream::NoteOn(UINT32 dwNote, UINT32 dwVelocity, UINT32 dwChannel)
{
    CMidiNote *pCNote=NULL;

    PLIST_ENTRY pListEntry;

    // First try to find the same note already being played
    pCNote = FindNote(dwNote, dwChannel);
    if (pCNote)
    {
        // If so, just set its velocity to the new velocity
        // This allows us to change volume while a note is being
        // played without any chance of glitching
        pCNote->SetVelocity(dwVelocity);
    }
    else
    {
        // Try to allocate a note from the free list
        pListEntry = m_FreeList.Flink;
        if (pListEntry != &m_FreeList)
        {
            pCNote = CONTAINING_RECORD(pListEntry,CMidiNote,m_Link);

            // If we got a note from the free list, do an AddRef on this stream context
            AddRef();
        }
        else
        {
            // Note: if we every support multiple instruments, here we should try to steal the oldest
            // note with the same channel before just trying to steal the oldest note.

            // Steal the oldest note (which is the note at the head of the note list)
            // Note: This should _never_ fail, since there must be a note on one of the lists!
            pListEntry = m_NoteList.Flink;
            pCNote = CONTAINING_RECORD(pListEntry,CMidiNote,m_Link);
        }

        pCNote->NoteOn(this,dwNote,dwVelocity,dwChannel);
    }

    // Move the note from whichever list it was on to the note list at the end.
    // This ensures that if we reused an existing note, its age gets reset.
    NoteMoveToNoteList(pCNote);

    return S_OK;
}


// Assumes lock is taken, and we're already positioned at the correct point in the stream
HRESULT CMidiStream::NoteOff(UINT32 dwNote, UINT32 dwVelocity, UINT32 dwChannel)
{
    CMidiNote *pCNote = FindNote(dwNote, dwChannel);
    if (pCNote)
    {
        pCNote->NoteOff(dwVelocity);
    }

    return S_OK;
}


HRESULT CMidiStream::AllNotesOff(UINT32 dwVelocity)
{
    PLIST_ENTRY pListEntry;
    CMidiNote *pCNote;
    pListEntry = m_NoteList.Flink;
    while (pListEntry != &m_NoteList)
    {
        // Get the note
        pCNote = CONTAINING_RECORD(pListEntry,CMidiNote,m_Link);

        // Get the next link, since NoteOff may remove the note from the queue depeding on the implementation
        pListEntry = pListEntry->Flink;

        // Turn the note off
        pCNote->NoteOff(dwVelocity);
    }
    return S_OK;
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
精品一区二区三区不卡| 91国内精品野花午夜精品| 成av人片一区二区| 欧美在线观看视频一区二区三区| 日韩精品专区在线影院重磅| 亚洲欧美一区二区三区国产精品| 久久99精品久久久久久动态图| 色婷婷国产精品久久包臀 | 开心九九激情九九欧美日韩精美视频电影| 国产成人精品免费一区二区| 欧美精品aⅴ在线视频| 亚洲欧美日韩在线| 国产精品1024| 亚洲精品在线观| 美女视频免费一区| 91麻豆精品国产91| 亚洲va国产天堂va久久en| 99精品国产一区二区三区不卡| 久久婷婷色综合| 美日韩一区二区| 日韩欧美国产系列| 日韩电影在线看| 欧美日韩aaaaaa| 亚洲国产中文字幕在线视频综合| 99精品视频在线观看免费| 国产精品不卡在线| 懂色一区二区三区免费观看| 国产亚洲一区二区三区| 国产成人三级在线观看| 久久午夜国产精品| 国产一区二区在线电影| 日韩精品中文字幕一区二区三区 | 亚洲精品一二三| 91在线丨porny丨国产| 亚洲日本中文字幕区| 97久久久精品综合88久久| 国产精品成人一区二区艾草| 99re这里只有精品视频首页| 亚洲欧美一区二区不卡| 91国内精品野花午夜精品 | 91原创在线视频| 亚洲伊人色欲综合网| 欧美丰满嫩嫩电影| 九色porny丨国产精品| 337p粉嫩大胆噜噜噜噜噜91av| 国产精品综合二区| 国产精品美女久久久久久久久| 99久久精品国产毛片| 久久精品国产999大香线蕉| 日韩欧美亚洲国产另类| 国产成人综合在线| 亚洲三级理论片| 欧美精品久久99久久在免费线| 狠狠v欧美v日韩v亚洲ⅴ| 国产亚洲制服色| 日本韩国一区二区| 久久99国产精品尤物| 国产精品萝li| 欧美人狂配大交3d怪物一区| 国产一区二区视频在线播放| 国产精品天美传媒沈樵| 欧美在线影院一区二区| 欧美a一区二区| 国产精品超碰97尤物18| 这里是久久伊人| 成人精品国产福利| 日韩电影免费一区| 成人免费在线视频| 日韩欧美二区三区| 色综合久久天天| 极品少妇一区二区| 亚洲国产中文字幕在线视频综合| 久久久综合视频| 亚洲一区影音先锋| 首页欧美精品中文字幕| 精品国产乱码久久| 色94色欧美sute亚洲线路二| 强制捆绑调教一区二区| 亚洲人成影院在线观看| 久久新电视剧免费观看| 欧美三级日韩在线| www.久久久久久久久| 精品综合免费视频观看| 一区二区久久久久久| 国产精品女同一区二区三区| 欧美一级爆毛片| 欧美人与性动xxxx| 91在线视频免费91| 成人性生交大片免费看在线播放| 五月天欧美精品| 亚洲蜜臀av乱码久久精品蜜桃| 久久综合999| 91精品国产91久久久久久最新毛片| 99久久伊人精品| 国产成人午夜精品影院观看视频 | 中文字幕一区二区三区精华液 | 国产伦精品一区二区三区免费迷| 午夜激情一区二区三区| 日韩一区有码在线| 国产精品久久久久久久蜜臀| 国产亚洲欧洲997久久综合| 日韩免费看的电影| 日韩亚洲欧美一区二区三区| 欧美伦理视频网站| 欧美日韩一区二区三区在线看| 色综合天天狠狠| 99热精品一区二区| 一区二区三区资源| 久久久综合激的五月天| 精品国产sm最大网站免费看| 欧美一区二区精美| 欧美一区二区在线播放| 91精品久久久久久久99蜜桃| 欧美午夜不卡在线观看免费| 欧美视频一区二区三区| 色94色欧美sute亚洲线路二| 色吧成人激情小说| 欧美性受xxxx黑人xyx性爽| 色先锋aa成人| 欧美亚洲国产一区二区三区va| 一本久久a久久免费精品不卡| 91亚洲午夜精品久久久久久| 色综合一区二区| 91在线看国产| 欧美专区在线观看一区| 欧美日韩精品福利| 日韩一区二区三| 久久综合色8888| 国产精品嫩草久久久久| 中文字幕亚洲一区二区av在线| 亚洲欧美色图小说| 亚洲va欧美va天堂v国产综合| 午夜精品免费在线| 久久精品国产精品亚洲综合| 国产麻豆视频一区二区| 91论坛在线播放| 在线电影欧美成精品| 欧美精品一区二区不卡| 成人欧美一区二区三区视频网页 | 欧美日韩在线一区二区| 91精品黄色片免费大全| 2020国产精品久久精品美国| 日韩三级在线免费观看| 国产精品久久久久久久午夜片 | 欧美视频中文一区二区三区在线观看| 欧美日韩一本到| 日韩三级在线观看| 亚洲国产精品精华液ab| 午夜伊人狠狠久久| 国产福利一区在线| 色综合 综合色| 欧美不卡视频一区| 一区二区三区欧美| 久久91精品国产91久久小草| www.成人在线| 日韩午夜电影av| 亚洲欧美日韩在线不卡| 狠狠狠色丁香婷婷综合久久五月| 91丨九色丨蝌蚪丨老版| 日韩精品一区二| 亚洲va欧美va国产va天堂影院| 国产福利视频一区二区三区| 欧美视频在线观看一区| 在线不卡一区二区| 欧美videos中文字幕| 亚洲精品免费一二三区| 91国产丝袜在线播放| 欧美精品一区二区在线播放| 亚洲永久精品大片| 国产91精品一区二区麻豆网站| 欧美一级片在线| 亚洲综合一区二区精品导航| 国产 日韩 欧美大片| 日韩精品综合一本久道在线视频| 亚洲精选视频在线| 成人精品国产福利| 久久美女艺术照精彩视频福利播放| 视频一区中文字幕| 日本韩国欧美三级| 国产精品精品国产色婷婷| 国产一区二区三区在线观看免费 | 奇米777欧美一区二区| 在线精品国精品国产尤物884a| 国产精品对白交换视频| 国产精品一区二区在线看| 精品国产自在久精品国产| 日本不卡不码高清免费观看| 欧美色倩网站大全免费| 一区二区三区四区不卡视频| 成人白浆超碰人人人人| 国产亚洲综合色| 韩日欧美一区二区三区| 久久综合色婷婷| 国产精品一区专区| 久久久国产一区二区三区四区小说| 久久精品久久精品| 精品国产麻豆免费人成网站| 蜜臀av一区二区| 欧美电影免费观看高清完整版在线| 日韩成人一区二区|