コード例 #1
0
ファイル: pyapi.cpp プロジェクト: OpenGanesh/oom
PyObject* getParts(PyObject*, PyObject* args)
{
	TrackList* tracks = song->tracks();
	const char* trackname;
	if (!PyArg_ParseTuple(args, "s", &trackname))
	{
		return NULL;
	}

	PyObject* pyparts = Py_BuildValue("[]");
	for (ciTrack t = tracks->begin(); t != tracks->end(); ++t)
	{
		Track* track = *t;
		if (track->name() != trackname)
			continue;

		PartList* parts = track->parts();
		for (ciPart p = parts->begin(); p != parts->end(); p++)
		{
			Part* part = p->second;

			MidiPart* mpart = (MidiPart*) part;
			PyObject* pypart = PyDict_New();
			int tick = mpart->tick();
			int lentick = mpart->lenTick();
			int serialnr = mpart->sn();
			PyObject* pstrtick = Py_BuildValue("s", "tick");
			PyObject* pitick = Py_BuildValue("i", tick);
			PyObject* pstrid = Py_BuildValue("s", "id");
			PyObject* pstrserial = Py_BuildValue("i", serialnr);
			PyObject* pstrlen = Py_BuildValue("s", "len");
			PyObject* pstrtick2 = Py_BuildValue("i", lentick);

			PyDict_SetItem(pypart, pstrtick, pitick);
			PyDict_SetItem(pypart, pstrid, pstrserial);
			PyDict_SetItem(pypart, pstrlen, pstrtick2);

			Py_DECREF(pstrtick);
			Py_DECREF(pitick);
			Py_DECREF(pstrid);
			Py_DECREF(pstrserial);
			Py_DECREF(pstrlen);
			Py_DECREF(pstrtick2);

			// Pack midi events into list before wrapping it all up
			EventList* events = mpart->events();
			PyObject* pyevents = Py_BuildValue("[]");
			for (ciEvent e = events->begin(); e != events->end(); e++)
			{
				PyObject* pyevent = PyDict_New(); // The event structure - a dictionary with keys 'type','tick','data'

				const Event& event = e->second;
				unsigned tick = e->first;
				PyObject* eventdata = Py_BuildValue("[i,i,i]", event.dataA(), event.dataB(), event.dataC());
				PyObject* pstrdata = Py_BuildValue("s", "data");
				pstrtick = Py_BuildValue("s", "tick");
				PyObject* pitickval = Py_BuildValue("i", tick);
				PyDict_SetItem(pyevent, pstrdata, eventdata);
				PyDict_SetItem(pyevent, pstrtick, pitickval);
				Py_DECREF(eventdata);
				Py_DECREF(pstrdata);
				Py_DECREF(pstrtick);
				Py_DECREF(pitickval);

				switch (event.type())
				{
					case Note:
					{
						PyObject* pstrtype = Py_BuildValue("s", "type");
						PyObject* pstrnote = Py_BuildValue("s", "note");
						PyObject* pstrlen = Py_BuildValue("s", "len");
						PyObject* pilentick = Py_BuildValue("i", event.lenTick());
						PyDict_SetItem(pyevent, pstrtype, pstrnote);
						PyDict_SetItem(pyevent, pstrlen, pilentick);
						Py_DECREF(pstrtype);
						Py_DECREF(pstrnote);
						Py_DECREF(pstrlen);
						Py_DECREF(pilentick);
						break;
					}
					case Controller:
					{
						PyObject* pstrtype = Py_BuildValue("s", "type");
						PyObject* pstrctrl = Py_BuildValue("s", "ctrl");
						PyDict_SetItem(pyevent, pstrtype, pstrctrl);
						Py_DECREF(pstrtype);
						Py_DECREF(pstrctrl);
						break;
					}
					default:
						printf("Event type not supported yet: %d\n", event.type());
						break;
				}
				PyList_Append(pyevents, pyevent);
				Py_DECREF(pyevent);
			}
			Py_DECREF(pyevents);
			// Add the event list to the pypart dictionary
			PyObject* pystrevents = Py_BuildValue("s", "events");
			PyDict_SetItem(pypart, pystrevents, pyevents);
			Py_DECREF(pystrevents);
			PyList_Append(pyparts, pypart);
			Py_DECREF(pypart);
		}

		return pyparts;
	}

	return NULL;
}
コード例 #2
0
ファイル: EventCanvas.cpp プロジェクト: ViktorNova/los
void EventCanvas::songChanged(int flags)/*{{{*/
{
    // Is it simply a midi controller value adjustment? Forget it.
    if (flags == SC_MIDI_CONTROLLER)
        return;

    if (flags & ~SC_SELECTION)
    {
        _items.clear();
        start_tick = MAXINT;
        end_tick = 0;
    _curPart = 0;

        for (iPart p = editor->parts()->begin(); p != editor->parts()->end(); ++p)
        {
            MidiPart* part = (MidiPart*) (p->second);
        if (part->sn() == _curPartId)
        _curPart = part;
            unsigned stick = part->tick();
            unsigned len = part->lenTick();
            unsigned etick = stick + len;
            if (stick < start_tick)
                start_tick = stick;
            if (etick > end_tick)
                end_tick = etick;

            EventList* el = part->events();
            for (iEvent i = el->begin(); i != el->end(); ++i)
            {
                Event e = i->second;
                if (e.isNote())
                {
                    addItem(part, e);
                }
            }
        }
    }

    Event event;
    MidiPart* part = 0;
    int x = 0;
    CItem* nevent = 0;

    int n = 0; // count selections
    for (iCItem k = _items.begin(); k != _items.end(); ++k)
    {
        Event ev = k->second->event();
        bool selected = ev.selected();
        if (selected)
        {
            k->second->setSelected(true);
            ++n;
            if (!nevent)
            {
                nevent = k->second;
                Event mi = nevent->event();
                curVelo = mi.velo();
            }
        }
    }
    start_tick = song->roundDownBar(start_tick);
    end_tick = song->roundUpBar(end_tick);

    if (n == 1)
    {
        x = nevent->x();
        event = nevent->event();
        part = (MidiPart*) nevent->part();
    if (_curPart != part)
        {
        _curPart = part;
        _curPartId = _curPart->sn();
            curPartChanged();
        }
    }
    emit selectionChanged(x, event, part);
    if (_curPart == 0)
    {
        _curPart = (MidiPart*) (editor->parts()->begin()->second);
        if(_curPart)
        {
            editor->setCurCanvasPart(_curPart);
        }
    }

    updateCItemsZValues();

    redraw();
}/*}}}*/
コード例 #3
0
ファイル: listedit.cpp プロジェクト: ViktorNova/los
void ListEdit::songChanged(int type)
{
    if (type == 0)
        return;
    if (type & (SC_PART_REMOVED | SC_PART_MODIFIED
            | SC_PART_INSERTED | SC_EVENT_REMOVED | SC_EVENT_MODIFIED
            | SC_EVENT_INSERTED | SC_SELECTION))
    {
        if (type & (SC_PART_REMOVED | SC_PART_INSERTED))
            genPartlist();
        // close window if editor has no parts anymore
        if (parts()->empty())
        {
            close();
            return;
        }
        liste->setSortingEnabled(false);
        if (type == SC_SELECTION)
        {
            bool update = false;
            QTreeWidgetItem* ci = 0;
            liste->blockSignals(true);
            for (int row = 0; row < liste->topLevelItemCount(); ++row)
            {
                QTreeWidgetItem* i = liste->topLevelItem(row);
                if (i->isSelected() ^ ((EventListItem*) i)->event.selected())
                {
                    i->setSelected(((EventListItem*) i)->event.selected());
                    if (i->isSelected())
                        ci = i;
                    update = true;
                }
            }
            if (update)
            {
                if (ci)
                {
                    liste->setCurrentItem(ci);
                    liste->scrollToItem(ci, QAbstractItemView::EnsureVisible);
                }
                //liste->update();
            }
            liste->blockSignals(false);
        }
        else
        {
            curPart = 0;
            curTrack = 0;
            liste->clear();
            for (iPart p = parts()->begin(); p != parts()->end(); ++p)
            {
                MidiPart* part = (MidiPart*) (p->second);
                if (part->sn() == curPartId)
                    curPart = part;
                EventList* el = part->events();
                for (iEvent i = el->begin(); i != el->end(); ++i)
                {
                    EventListItem* item = new EventListItem(liste, i->second, part);
                    for (int col = 0; col < liste->columnCount(); ++col)
                        item->setText(col, item->text(col));
                    item->setSelected(i->second.selected());
                    if (item->event.tick() == (unsigned) selectedTick)
                    { //prevent compiler warning: comparison of signed/unsigned)
                        liste->setCurrentItem(item);
                        item->setSelected(true);
                        liste->scrollToItem(item, QAbstractItemView::EnsureVisible);
                    }
                }
            }
        }

        // p3.3.34
        //if (curPart == 0)
        //      curPart  = (MidiPart*)(parts()->begin()->second);
        //curTrack = curPart->track();
        if (!curPart)
        {
            if (!parts()->empty())
            {
                curPart = (MidiPart*) (parts()->begin()->second);
                if (curPart)
                    curTrack = curPart->track();
                else
                    curPart = 0;
            }
        }
    }
    liste->setSortingEnabled(true);
}