Example #1
0
// Try to set up a new instrument that is linked to the current plugin.
bool CAbstractVstEditor::CreateInstrument()
//-----------------------------------------
{
    CModDoc *pModDoc = m_pVstPlugin->GetModDoc();
    module_renderer *pSndFile = m_pVstPlugin->GetSoundFile();
    if(pModDoc == nullptr || pSndFile == nullptr)
    {
            return false;
    }

    bool bFirst = (pSndFile->GetNumInstruments() == 0);
    modplug::tracker::instrumentindex_t nIns = pModDoc->InsertInstrument(0);
    if(nIns == modplug::tracker::InstrumentIndexInvalid)
    {
            return false;
    }

    modplug::tracker::modinstrument_t *pIns = pSndFile->Instruments[nIns];
    m_nInstrument = nIns;

    _snprintf(pIns->name, CountOf(pIns->name) - 1, _T("%d: %s"), m_pVstPlugin->GetSlot() + 1, pSndFile->m_MixPlugins[m_pVstPlugin->GetSlot()].Info.szName);
    strncpy(pIns->legacy_filename, pSndFile->m_MixPlugins[m_pVstPlugin->GetSlot()].Info.szLibraryName, CountOf(pIns->legacy_filename) - 1);
    pIns->nMixPlug = (PLUGINDEX)m_pVstPlugin->GetSlot() + 1;
    pIns->midi_channel = 1;
    // People will forget to change this anyway, so the following lines can lead to some bad surprises after re-opening the module.
    //pIns->wMidiBank = (uint16_t)((m_pVstPlugin->GetCurrentProgram() >> 7) + 1);
    //pIns->nMidiProgram = (uint8_t)((m_pVstPlugin->GetCurrentProgram() & 0x7F) + 1);

    pModDoc->UpdateAllViews(NULL, (nIns << HINT_SHIFT_INS) | HINT_INSTRUMENT | HINT_INSNAMES | HINT_ENVELOPE | (bFirst ? HINT_MODTYPE : 0));
    if(pSndFile->GetModSpecifications().supportsPlugins)
    {
            pModDoc->SetModified();
    }

    return true;
}