Exemplo n.º 1
0
void initMidiPorts()
{
    //TODO: Remove the need for this code
    //We should populate the losMidiPort hash with ports as we create them
    for (int i = 0; i < kMaxMidiPorts; ++i)
    {
        MidiPort* port = &midiPorts[i];
        ///port->setInstrument(genericMidiInstrument);
        port->setInstrument(registerMidiInstrument("GM")); // Changed by Tim.
    }
}
Exemplo n.º 2
0
void initMidiPorts()
{
	//TODO: Remove the need for this code
	//We should populate the oomMidiPort hash with ports as we create them
	for (int i = 0; i < MIDI_PORTS; ++i)
	{
		MidiPort* port = &midiPorts[i];
		///port->setInstrument(genericMidiInstrument);
		port->setInstrument(registerMidiInstrument("GM")); // Changed by Tim.
		port->syncInfo().setPort(i);
	}
}
Exemplo n.º 3
0
Arquivo: conf.cpp Projeto: Adamiko/los
static void readConfigMidiPort(Xml& xml)/*{{{*/
{
    int idx = 0;
    qint64 id = -1;
    QString device;
    bool isGlobal = false;

    QString instrument("GM");

    QList<PatchSequence*> patchSequences;
    QList<QPair<int, QString> > presets;

    int openFlags = 1;
    int dic = 0;
    int doc = 0;
    int type = MidiDevice::ALSA_MIDI;
    bool cachenrpn = false;

    MidiDevice* dev = 0;

    for (;;)
    {
        Xml::Token token = xml.parse();
        if (token == Xml::Error || token == Xml::End)
            break;
        QString tag = xml.s1();
        switch (token)
        {
            case Xml::TagStart:
                if (tag == "name")
                {
                    device = xml.parse1();
                    if (!dev)//Look for it as an alsa or already created device
                        dev = midiDevices.find(device);
                }
                else if (tag == "type")
                {
                    type = xml.parseInt();
                }
                else if (tag == "record")
                {   // old
                    bool f = xml.parseInt();
                    if (f)
                        openFlags |= 2;
                }
                else if (tag == "openFlags")
                    openFlags = xml.parseInt();
                else if (tag == "defaultInChans")
                    dic = xml.parseInt();
                else if (tag == "defaultOutChans")
                    doc = xml.parseInt();
                else if (tag == "instrument")
                {
                    instrument = xml.parse1();
                }
                else if (tag == "channel")
                {
                    readPortChannel(xml, idx);
                }
                else if (tag == "preset" || tag == "patchSequence")
                {
                    PatchSequence* p = readMidiPortPatchSequences(xml);
                    if (p)
                        patchSequences.append(p);
                }
                else if(tag == "midiPreset")
                {
                    presets.append(readMidiPortPreset(xml));
                }
                else if(tag == "cacheNRPN")
                {
                    cachenrpn = xml.parseInt();
                }
                else
                    xml.skip(tag);
                break;
            case Xml::Attribut:
                if (tag == "idx")
                {//Check to see if this port is already used, and bump if so
                    idx = xml.s2().toInt();
                    int freePort = getFreeMidiPort();
                    if(freePort != idx)
                    {//Set a flag here so we know when loading tracks later that we are dealing with an old file or global inputs changed
                        idx = freePort;
                    }
                }
                else if(tag == "portId")
                {//New style
                    id = xml.s2().toLongLong();
                    idx = getFreeMidiPort();
                }
                else if(tag == "isGlobalInput")
                {//Find the matching input if posible and set our index to it
                    isGlobal = xml.s2().toInt();
                }
                break;
            case Xml::TagEnd:
                if (tag == "midiport")
                {
                    if(isGlobal)
                    {//Find the global input that matches
                        //
                        if(gInputListPorts.size())
                        {
                            int myport = -1;
                            for(int i = 0; i < gInputListPorts.size(); ++i)
                            {
                                myport =  gInputListPorts.at(i);

                                MidiPort* inport = &midiPorts[i];
                                if(inport && inport->device() && inport->device()->name() == device)
                                {
                                    idx = myport;
                                    break;
                                }
                            }
                        }
                    }

                    if (idx < 0 || idx >= MIDI_PORTS)
                    {
                        fprintf(stderr, "bad midi port %d (>%d)\n",
                                idx, MIDI_PORTS);
                        idx = 0;
                    }

                    if (!dev)
                    {
                        if (type == MidiDevice::JACK_MIDI)
                        {
                            dev = MidiJackDevice::createJackMidiDevice(device); // p3.3.55

                            if (debugMsg)
                                fprintf(stderr, "readConfigMidiPort: creating jack midi device %s\n", device.toLatin1().constData());
                        }
                        else
                            dev = midiDevices.find(device);
                    }

                    if (debugMsg && !dev)
                        fprintf(stderr, "readConfigMidiPort: device not found %s\n", device.toLatin1().constData());

                    MidiPort* mp = &midiPorts[idx];
                    if(id)
                        mp->setPortId(id);

                    mp->setInstrument(registerMidiInstrument(instrument));
                    mp->setDefaultInChannels(dic);
                    mp->setDefaultOutChannels(doc);

                    //Indicate the port was found in the song file, even if no device is assigned to it.
                    mp->setFoundInSongFile(true);

                    if (!patchSequences.isEmpty())
                    {
                        for (int i = 0; i < patchSequences.size(); ++i)
                        {
                            mp->appendPatchSequence(patchSequences.at(i));
                        }
                    }
                    if(!presets.isEmpty())
                    {
                        for(int i = 0; i < presets.size(); ++i)
                        {
                            QPair<int, QString> pair = presets.at(i);
                            mp->addPreset(pair.first, pair.second);
                        }
                    }

                    if (dev)
                    {
                        dev->setOpenFlags(openFlags);
                        midiSeq->msgSetMidiDevice(mp, dev);
                        dev->setCacheNRPN(cachenrpn);
                    }
                    losMidiPorts.insert(mp->id(), mp);
                    return;
                }
            default:
                break;
        }
    }
}/*}}}*/
Exemplo n.º 4
0
void GlobalSettingsConfig::apply()
{
    int rtcticks = rtcResolutionSelect->currentIndex();
    config.guiRefresh = guiRefreshSelect->value();
    config.rtcTicks = rtcResolutions[rtcticks];
    config.userInstrumentsDir = userInstrumentsPath->text();
    config.startSong = startSongEntry->text();
    config.startMode = startSongGroup->checkedId();

    int div = midiDivisionSelect->currentIndex();
    if (div < 0 || div > 9)
        div = 3;
    config.division = divisions[div];

    config.useOldStyleStopShortCut = oldStyleStopCheckBox->isChecked();
    config.moveArmedCheckBox = moveArmedCheckBox->isChecked();
    config.useProjectSaveDialog = projectSaveCheckBox->isChecked();

    losUserInstruments = config.userInstrumentsDir;

    //QList<QPair<int, QString> > oldList(gInputList);
    bool hasPorts = !gInputListPorts.isEmpty();
    gInputList.clear();
    for(int i = 0; i < m_inputsModel->rowCount(); ++i)
    {
        QStandardItem* item = m_inputsModel->item(i);
        if(item)
        {
            bool checked = (item->checkState() == Qt::Checked);
            QPair<int, QString> pinfo = qMakePair(item->data(Qt::UserRole+2).toInt(), item->data(Qt::UserRole+1).toString());
            if(hasPorts)
            {
                bool found = false;
                int p = 0;
                MidiPort* mp = 0;
                for(p = 0;p < gInputListPorts.size(); p++)
                {
                    mp = &midiPorts[gInputListPorts.at(p)];
                    if(mp && mp->device()->name() == pinfo.second)
                    {
                        found = true;
                        break;
                    }
                }
                if(!checked)
                {//Unconfigure
                    if(found && mp)
                    {
                        //TODO:Clear routing list
                        mp->setInstrument(registerMidiInstrument("GM"));
                        midiSeq->msgSetMidiDevice(mp, 0);
                        gInputListPorts.takeAt(p);
                    }
                }
                else
                {
                    if(!found)
                        los->addGlobalInput(pinfo);
                    gInputList.append(pinfo);
                }
            }
            else if(checked)
            {
                los->addGlobalInput(pinfo);
                gInputList.append(pinfo);
            }
        }
    }

    los->setHeartBeat(); // set guiRefresh
    midiSeq->msgSetRtc(); // set midi tick rate
    los->changeConfig(true); // save settings
}