Ejemplo n.º 1
0
void AbstractMidiEditor::writePartList(int level, Xml& xml) const/*{{{*/
{
    for (ciPart p = _pl->begin(); p != _pl->end(); ++p)
    {
        Part* part = p->second;
        MidiTrack* track = part->track();
        int trkIdx = song->artracks()->index(track);
        int partIdx = track->parts()->index(part);

        if ((trkIdx == -1) || (partIdx == -1))
            printf("AbstractMidiEditor::writePartList error: trkIdx:%d partIdx:%d\n", trkIdx, partIdx);

        xml.put(level, "<part>%d:%d</part>", trkIdx, partIdx);
    }
}/*}}}*/
Ejemplo n.º 2
0
void TrackListView::selectionChanged(const QModelIndex current, const QModelIndex)/*{{{*/
{
    if(!current.isValid())
        return;
    int row = current.row();
    m_selectedIndex = row;
    QStandardItem* item = m_model->item(row);
    if(item)
    {
        int type = item->data(TrackRole).toInt();
        qint64 tid = item->data(TrackIdRole).toLongLong();
        bool checked = (item->checkState() == Qt::Checked);
        //QString trackName = item->data(TrackNameRole).toString();
        MidiTrack* track = song->findTrackById(tid);
        if(!track || !m_editor || type == 1 || !checked)
            return;

        PartList* list = track->parts();
        int sn = item->data(PartRole).toInt();
        unsigned tick = item->data(TickRole).toInt();
        Part* part = list->find(tick, sn);
        updatePartSelection(part);
    }
}/*}}}*/
Ejemplo n.º 3
0
Archivo: midi.cpp Proyecto: faesong/oom
void Audio::preloadControllers()/*{{{*/
{
	midiBusy = true;

	MidiTrackList* tracks = song->midis();
	for (iMidiTrack it = tracks->begin(); it != tracks->end(); ++it)
	{
		MidiTrack* track = *it;
		//activePorts[track->outPort()] = true;
		QList<ProcessList*> pcevents;

		int port = track->outPort();
		int channel = track->outChannel();
		int defaultPort = port;

		MidiDevice* md = midiPorts[port].device();
		if (!md)
		{
			continue;
		}
		MPEventList* playEvents = md->playEvents();
		playEvents->erase(playEvents->begin(), playEvents->end());

		PartList* pl = track->parts();
		for (iPart p = pl->begin(); p != pl->end(); ++p)
		{
			MidiPart* part = (MidiPart*) (p->second);
			EventList* events = part->events();
			unsigned partTick = part->tick();
			//unsigned partLen = part->lenTick();
			int delay = track->delay;

			unsigned offset = delay + partTick;

			for (iEvent ie = events->begin(); ie != events->end(); ++ie)
			{
				Event ev = ie->second;
				port = defaultPort;
				unsigned tick = ev.tick() + offset;
				//unsigned frame = tempomap.tick2frame(tick) + frameOffset;
				switch (ev.dataA())
				{
					case CTRL_PROGRAM:
					{
						ProcessList *pl = new ProcessList;
						pl->port = port;
						pl->channel = channel;
						pl->dataB = ev.dataB();
						bool addEvent = true;
						for(int i = 0; i < pcevents.size(); ++i)
						{
							ProcessList* ipl = pcevents.at(i);
							if(ipl->port == pl->port && ipl->channel == pl->channel && ipl->dataB == pl->dataB)
							{
								addEvent = false;
								break;
							}
						}
						if(addEvent)
						{
							printf("Audio::preloadControllers() Loading event @ tick: %d - on channel: %d - on port: %d - dataA: %d - dataB: %d\n",
								tick, channel, port, ev.dataA(), ev.dataB());
							pcevents.append(pl);
							playEvents->add(MidiPlayEvent(tick, port, channel, ev));
						}
					}
						break;
					default:
						break;
				}
			}
		}
		md->setNextPlayEvent(playEvents->begin());
	}
	midiBusy = false;
}/*}}}*/
Ejemplo n.º 4
0
void TrackListView::toggleTrackPart(QStandardItem* item)/*{{{*/
{
    if(!item)
        return;
    m_editing = true;
    int type = item->data(TrackRole).toInt();
    int column = item->column();
    bool checked = (item->checkState() == Qt::Checked);
    qint64 tid = item->data(TrackIdRole).toLongLong();
    QString trackName = item->data(TrackNameRole).toString();
    QString partName;
    m_selectedIndex = item->row();
    QString newName = item->text();
    if(type == 1)
    {
        if(trackName == newName)
            column = 0;
        else
            column = 1;
    }
    else
    {
        partName = item->data(PartNameRole).toString();
        if(partName == newName)
            column = 0;
        else
            column = 1;
    }

    MidiTrack* track = song->findTrackById(tid);
    if(!track || !m_editor)
    {
        m_editing = false;
        return;
    }

    PartList* list = track->parts();
    if(list->empty())
    {
        m_editing = false;
        updateCheck();
        return;
    }
    switch(type)
    {
        case 1: //Track
        {
            if(!column)
            {
                if(checked)
                {
                    m_editor->addParts(list);
                    m_selectedTracks.append(track->id());
                    if(!list->empty())
                    {
                        updatePartSelection(list->begin()->second);

                        updateCheck(list, checked);
                    }
                }
                else
                {
                    m_editor->removeParts(list);
                    m_editor->updateCanvas();
                    m_selectedTracks.removeAll(track->id());
                    updateCheck();
                    song->update(SC_SELECTION);
                }
            }
            else
            {
                bool valid = true;
                if(newName.isEmpty())
                {
                    valid = false;
                }
                if(valid)
                {
                    for (iMidiTrack i = song->tracks()->begin(); i != song->tracks()->end(); ++i)
                    {
                        if ((*i)->name() == newName)
                        {
                            valid = false;
                            break;
                        }
                    }
                }
                if(!valid)
                {
                    QMessageBox::critical(this, tr("LOS: bad trackname"),
                            tr("please choose a unique track name"),
                            QMessageBox::Ok, Qt::NoButton, Qt::NoButton);
                    m_model->blockSignals(true);
                    item->setText(item->data(TrackNameRole).toString());
                    m_model->blockSignals(false);
                    update();
                    m_editing = false;
                    return;
                }
                m_model->blockSignals(true);
                item->setData(newName, TrackNameRole);
                m_model->blockSignals(false);

                Track* newTrack = track->clone(false);
                newTrack->setName(newName);
                track->setName(newName);
                audio->msgChangeTrack((MidiTrack*)newTrack, track);
            }
        }
        break;
        case 2: //Part
        {
            int sn = item->data(PartRole).toInt();
            unsigned tick = item->data(TickRole).toInt();
            Part* part = list->find(tick, sn);
            if(part)
            {
                if(!column)
                {
                    if(checked)
                    {
                        m_editor->addPart(part);
                        updatePartSelection(part);
                    }
                    else
                    {
                        m_editor->removePart(sn);
                        m_editor->updateCanvas();
                        updateCheck();
                        song->update(SC_SELECTION);
                    }
                }
                else
                {
                    if(partName.isEmpty())
                    {
                        QMessageBox::critical(this, tr("LOS: Invalid part name"),
                                tr("Please choose a name with at least one charactor"),
                                QMessageBox::Ok, Qt::NoButton, Qt::NoButton);

                        m_model->blockSignals(true);
                        item->setText(item->data(PartNameRole).toString());
                        m_model->blockSignals(false);
                        update();
                        m_editing = false;
                        return;
                    }

                    m_model->blockSignals(true);
                    item->setData(newName, PartNameRole);
                    m_model->blockSignals(false);

                    Part* newPart = part->clone();
                    newPart->setName(newName);
                    // Indicate do undo, and do port controller values but not clone parts.
                    audio->msgChangePart(part, newPart, true, true, false);
                    song->update(SC_PART_MODIFIED);
                }
            }
        }
        break;
    }
    update();
    if(m_selectedIndex < m_model->rowCount())
    {
        m_table->selectRow(m_selectedIndex);
        m_table->scrollTo(m_model->index(m_selectedIndex, 0));
    }
    m_editing = false;
}/*}}}*/
Ejemplo n.º 5
0
void TrackListView::contextPopupMenu(QPoint pos)/*{{{*/
{
    QModelIndex mindex = m_table->indexAt(pos);
    if(!mindex.isValid())
        return;
    //int row = mindex.row();
    QStandardItem* item = m_model->itemFromIndex(mindex);
    if(item)
    {
        m_selectedIndex = item->row();
        //Make it works even if you rightclick on the checkbox
        QString trackName = item->data(TrackNameRole).toString();
        int type = item->data(TrackRole).toInt();
        MidiTrack* track = song->findTrack(trackName);
        if(!track || !m_editor)
            return;
        QMenu* p = new QMenu(this);
        QString title(tr("Part Color"));
        int index = track->getDefaultPartColor();
        Part* npart = 0;
        if(type == 1)
            title = QString(tr("Default Part Color"));
        else
        {
            PartList* list = track->parts();
            int sn = item->data(PartRole).toInt();
            unsigned tick = item->data(TickRole).toInt();
            npart = list->find(tick, sn);
            if(npart)
                index = npart->colorIndex();
        }
        QMenu* colorPopup = p->addMenu(title);

        QMenu* colorSub;
        for (int i = 0; i < NUM_PARTCOLORS; ++i)
        {
            QString colorname(config.partColorNames[i]);
            if(colorname.contains("menu:", Qt::CaseSensitive))
            {
                colorSub = colorPopup->addMenu(colorname.replace("menu:", ""));
            }
            else
            {
                if(index == i)
                {
                    colorname = QString(config.partColorNames[i]);
                    colorPopup->setIcon(partColorIconsSelected.at(i));
                    colorPopup->setTitle(colorSub->title()+": "+colorname);

                    colorname = QString("* "+config.partColorNames[i]);
                    QAction *act_color = colorSub->addAction(partColorIconsSelected.at(i), colorname);
                    act_color->setData(20 + i);
                }
                else
                {
                    colorname = QString("     "+config.partColorNames[i]);
                    QAction *act_color = colorSub->addAction(partColorIcons.at(i), colorname);
                    act_color->setData(20 + i);
                }
            }
        }
        p->addAction(tr("Add Part"))->setData(1);
        p->addAction(tr("Add Part and Select"))->setData(2);
        if(type == 2)
            p->addAction(tr("Delete Part"))->setData(3);

        QAction* act = p->exec(QCursor::pos());
        if (act)
        {
            int selection = act->data().toInt();
            switch(selection)
            {
                case 1:
                {
                    CItem *citem = los->composer->addCanvasPart(track);
                    if(citem)
                    {
                        Part* mp = citem->part();
                        populateTable();//update check state
                        //Select and scroll to the added part
                        if(mp)
                        {
                            int psn = mp->sn();
                            for(int i = 0; i < m_model->rowCount(); ++i)
                            {
                                QStandardItem* item = m_model->item(i, 0);
                                if(item)
                                {
                                    int type = item->data(TrackRole).toInt();
                                    if(type == 1)
                                    {//TrackMode
                                        continue;
                                    }
                                    else
                                    {//PartMode
                                        int sn = item->data(PartRole).toInt();
                                        if(psn == sn)
                                        {
                                            //m_tempColor = item->foreground();
                                            m_model->blockSignals(true);
                                            item->setForeground(QColor(99, 36, 36));
                                            m_model->blockSignals(false);
                                            update();
                                            m_selectedIndex = item->row();
                                            m_table->selectRow(m_selectedIndex);
                                            m_table->scrollTo(m_model->index(m_selectedIndex, 0));
                                            m_colorRows.append(m_selectedIndex);
                                            QTimer::singleShot(350, this, SLOT(updateColor()));
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                break;
                case 2:
                {
                    CItem* citem = los->composer->addCanvasPart(track);
                    if(citem)
                    {
                        Part* mp = citem->part();
                        if(mp)
                        {
                            m_editor->addPart(mp);
                            populateTable();//update check state
                            updatePartSelection(mp);
                        }
                    }
                    break;
                }
                case 3:
                {
                    if(npart)
                    {
                        audio->msgRemovePart(npart);
                        populateTable();//update check state
                        scrollPos = pos;
                        /*if(row < m_model->rowCount())
                        {
                            QModelIndex rowIndex = m_table->indexAt(pos);
                            m_table->scrollTo(rowIndex, QAbstractItemView::PositionAtTop);
                        }*/
                    }
                    break;
                }
                case 20 ... NUM_PARTCOLORS + 20:
                {
                    int curColorIndex = selection - 20;
                    if(npart)
                    {
                        npart->setColorIndex(curColorIndex);
                        song->update(SC_PART_COLOR_MODIFIED);
                    }
                    else
                    {
                        track->setDefaultPartColor(curColorIndex);
                    }
                    populateTable();//update check state
                    break;
                }
            }
        }
        delete p;
    }
}/*}}}*/
Ejemplo n.º 6
0
void TrackListView::populateTable()/*{{{*/
{
    if(debugMsg)
        printf("TrackListView::populateTable\n");
    QScrollBar *bar = m_table->verticalScrollBar();
    int barPos = 0;
    if(bar)
        barPos = bar->sliderPosition();

    m_model->clear();
    for(iMidiTrack i = song->artracks()->begin(); i != song->artracks()->end(); ++i)
    {
        MidiTrack* track = (MidiTrack*)(*i);
        PartList* pl = track->parts();
        if(m_displayRole == PartRole && pl->empty())
        {
            continue;
        }

        QStandardItem* trackName = new QStandardItem();
        trackName->setForeground(QBrush(QColor(205,209,205)));
        trackName->setBackground(QBrush(QColor(20,20,20)));
        trackName->setFont(QFont("fixed-width", 10, QFont::Bold));
        trackName->setText(track->name());
        trackName->setCheckable(true);
        trackName->setCheckState(m_selectedTracks.contains(track->id()) ? Qt::Checked : Qt::Unchecked);

        trackName->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
        trackName->setData(1, TrackRole);
        trackName->setData(track->name(), TrackNameRole);
        trackName->setData(track->id(), TrackIdRole);
        trackName->setEditable(true);
        m_model->appendRow(trackName);

        for(iPart ip = pl->begin(); ip != pl->end(); ++ip)
        {
            Part* part = ip->second;
            QStandardItem* partName = new QStandardItem();
            partName->setFont(QFont("fixed-width", 9, QFont::Bold));
            partName->setText(part->name());
            partName->setData(part->sn(), PartRole);
            partName->setData(2, TrackRole);
            partName->setData(track->name(), TrackNameRole);
            partName->setData(part->name(), PartNameRole);
            partName->setData(part->tick(), TickRole);
            partName->setData(track->id(), TrackIdRole);
            partName->setEditable(true);
            partName->setCheckable(true);
            partName->setCheckState(m_editor->hasPart(part->sn()) ? Qt::Checked : Qt::Unchecked);

            if(!partColorIcons.isEmpty() && part->colorIndex() < partColorIcons.size())
                partName->setIcon(partColorIcons.at(part->colorIndex()));

            m_model->appendRow(partName);
        }
    }
    m_model->setHorizontalHeaderLabels(m_headers);
    if(m_selectedIndex < m_model->rowCount())
    {
        m_table->selectRow(m_selectedIndex);
        m_table->scrollTo(m_model->index(m_selectedIndex, 0));
    }
    if(bar)
        bar->setSliderPosition(barPos);
}/*}}}*/
Ejemplo n.º 7
0
void CanvasNavigator::updateParts()/*{{{*/
{
    m_editing = true;
    m_playhead = 0;
    m_start = 0;
    m_canvasBox =  0;
    m_punchIn = 0;
    m_punchOut = 0;
    m_parts.clear();
    m_markers.clear();
    m_scene->clear();
    /*foreach(PartItem* i, m_parts)
        m_scene->removeItem(i);
    while(m_parts.size())
        delete m_parts.takeFirst();*/
    m_heightList.clear();
    m_scene->setSceneRect(QRectF());
    int index = 1;
    //QList<QGraphicsItem*> group;
    MidiTrackList* tl = song->visibletracks();
    ciMidiTrack ci = tl->begin();
    for(; ci != tl->end(); ci++)
    {
        m_heightList.append((*ci)->height());
    }
    ci = tl->begin();
    if(ci != tl->end())
    {
        int mh = (*ci)->height();
        double partHeight = (mh * 8)/100;
        m_start = m_scene->addRect(0.0, 0.0, calcSize(song->len()), partHeight);
        m_start->setBrush(QColor(63, 63, 63));
        m_start->setPen(QPen(QColor(63, 63, 63)));
        m_start->setZValue(-50);
        ci++;//Special case for master
    }
    for(; ci != tl->end(); ci++)
    {
        MidiTrack* track = *ci;
        if(track)
        {
            QList<int> list = m_heightList.mid(0, index);
            int ypos = 0;
            foreach(int i, list)
                ypos += i;
            ypos = (ypos * 8)/100;
            int ih = m_heightList.at(index);
            double partHeight = (ih * 8)/100;

            //qDebug("CanvasNavigator::updateParts: partHeight: %2f, ypos: %d", partHeight, ypos);
            PartList* parts = track->parts();
            if(parts && !parts->empty())
            {
                for(iPart p = parts->begin(); p != parts->end(); p++)
                {
                    Part *part =  p->second;

                    int tick, len;
                    if(part)
                    {
                        tick = part->tick();
                        len = part->lenTick();
                    }
                    double w = calcSize(len);
                    double pos = calcSize(tick);

                    PartItem* item = new PartItem(pos, ypos, w, partHeight);
                    item->setPart(part);
                    m_parts.append(item);
                    //group.append((QGraphicsItem*)item);
                    int i = part->colorIndex();
                    QColor partWaveColor(config.partWaveColors[i]);
                    QColor partColor(config.partColors[i]);
                    //partWaveColor.setAlpha(150);
                    partColor.setAlpha(150);
                    item->setBrush(part->selected() ? partWaveColor : partColor);
                    item->setPen(part->selected() ? partColor : partWaveColor);
                    m_scene->addItem(item);
                }
            }
            ++index;
        }
    }
    QColor colTimeLine = QColor(0, 186, 255);
    int kpos = 0;
    foreach(int i, m_heightList)
        kpos += i;
    //kpos = ((kpos + 400) * 8)/100;
    kpos = ((kpos + 400) * 8)/100;

    m_playhead = new QGraphicsRectItem(0, 0, 1, kpos);
    m_playhead->setBrush(colTimeLine);
    m_playhead->setPen(Qt::NoPen);
    m_playhead->setZValue(124001.0f);
    m_playhead->setFlags(QGraphicsItem::ItemIgnoresTransformations);
    m_scene->addItem(m_playhead);
    QColor loopColor(139, 225, 69);
    QColor markerColor(243,191,124);
    MarkerList* markers = song->marker();
    for (iMarker m = markers->begin(); m != markers->end(); ++m)
    {
        //double xp = calcSize(m->second.tick());
        QGraphicsRectItem *marker = m_scene->addRect(0, 0, 1, kpos);
        marker->setData(Qt::UserRole, m->second.id());
        m_markers[m->second.id()] = marker;
        marker->setPen(Qt::NoPen);
        marker->setBrush(markerColor);
        marker->setZValue(124002.0f);
        marker->setFlags(QGraphicsItem::ItemIgnoresTransformations);
        m_updateMarkers = true;
    }

    m_punchIn = new QGraphicsRectItem(0, 0, 1, kpos);
    m_punchIn->setBrush(loopColor);
    m_punchIn->setPen(Qt::NoPen);
    m_punchIn->setZValue(124003.0f);
    m_punchIn->setFlags(QGraphicsItem::ItemIgnoresTransformations);
    m_scene->addItem(m_punchIn);
    m_punchIn->setVisible(song->loop() || song->punchin());

    m_punchOut = new QGraphicsRectItem(0, 0, 1, kpos);
    m_punchOut->setBrush(loopColor);
    m_punchOut->setPen(Qt::NoPen);
    m_punchOut->setZValue(124003.0f);
    m_punchOut->setFlags(QGraphicsItem::ItemIgnoresTransformations);
    m_scene->addItem(m_punchOut);
    m_punchOut->setVisible(song->loop() || song->punchout());

    createCanvasBox();

    //group.append((QGraphicsItem*)m_start);
    //group.append((QGraphicsItem*)m_playhead);
    //if(group.size())
    //{
    //	m_partGroup = m_scene->createItemGroup(group);
    //}
    //else
    m_partGroup = 0;
    updateSpacing();
    m_editing = false;
}/*}}}*/