poetaster / harbour-vipiano

A virtual MIDI piano keyboard built on top of FluidSynth for Sailfish OS
GNU General Public License v3.0
0 stars 0 forks source link

change soundfont #1

Closed poetaster closed 1 year ago

poetaster commented 3 years ago

That would make this really awesome ;)

It seems your just feeding in the soundfount params as settings: but something like:

A load function (cribbed from vmpkn9) (obviously some plumbing missing....

void SynthEngine::loadSoundFont()
{
    fluid_preset_t preset;
    m_instruments.clear();
    emit instrumentsChanged();
    if (m_sfid != -1) {
        ::fluid_synth_sfunload(m_synth, unsigned(m_sfid), 1);
    }
    m_sfid = ::fluid_synth_sfload(m_synth, m_soundFont.toLocal8Bit(), 1);
    if (m_sfid != -1) {
        fluid_sfont_t *pSoundFont = ::fluid_synth_get_sfont_by_id(m_synth, unsigned(m_sfid));
        if (pSoundFont) {
            pSoundFont->iteration_start(pSoundFont);
            while (pSoundFont->iteration_next(pSoundFont, &preset)) {
                int iBank = preset.get_banknum(&preset);
                int iProg = preset.get_num(&preset);
                QString sName = preset.get_name(&preset);
                //qDebug() << iBank << iProg << sName;
                Preset *bp = new Preset(iBank, iProg, sName, this);
                m_instruments.append(bp);
                emit instrumentAdded(sName);
            }
        }
        emit currentInstrumentChanged();
    }
}

and set getting input from QML

    SelectionDialog {
        id: channelSelection
        titleText: qsTr("Channel Selection")
        selectedIndex: synthEngine.channel
        model: ListModel { }
        onAccepted: {
            if (selectedIndex >= 0) {
                synthEngine.channel = selectedIndex
                channelButton.text = model.get(selectedIndex).name;
            }
        }
        onStatusChanged: {
            pianoKbd.enabled = (status == DialogStatus.Closed);
        }
    }

invoking

void SynthEngine::setInstrument(int i)
{
    Preset *bp = dynamic_cast<Preset*>(m_instruments.at(i));
    if (bp != 0) {
        //qDebug() << i << bp->name() << bp->bank() << bp->program();
        ::fluid_synth_bank_select(m_synth, m_channel, bp->bank());
        ::fluid_synth_program_change(m_synth, m_channel, bp->program());
        emit currentInstrumentChanged();
    }
}

If you have no time, I'll have a look.

poetaster commented 1 year ago

Well, instrument selection works just fine, so I'm closing this.

poetaster commented 1 year ago

closed