当前位置: 首页>>代码示例>>C++>>正文


C++ MidiTrack类代码示例

本文整理汇总了C++中MidiTrack的典型用法代码示例。如果您正苦于以下问题:C++ MidiTrack类的具体用法?C++ MidiTrack怎么用?C++ MidiTrack使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了MidiTrack类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: writeTrack

bool MidiFile::writeTrack(const MidiTrack &t)
      {
      write("MTrk", 4);
      qint64 lenpos = fp->pos();
      writeLong(0);                 // dummy len

      status   = -1;
      int tick = 0;
      for (auto i : t.events()) {
            int ntick = i.first;
            putvl(ntick - tick);    // write tick delta
            //
            // if track channel != -1, then use this
            //    channel for all events in this track
            //
            if (t.outChannel() != -1)
                  writeEvent(i.second);
            tick = ntick;
            }

      //---------------------------------------------------
      //    write "End Of Track" Meta
      //    write Track Len
      //

      putvl(1);
      put(0xff);        // Meta
      put(0x2f);        // EOT
      putvl(0);         // len 0
      qint64 endpos = fp->pos();
      fp->seek(lenpos);
      writeLong(endpos-lenpos-4);   // tracklen
      fp->seek(endpos);
      return false;
      }
开发者ID:Angeldude,项目名称:MuseScore,代码行数:35,代码来源:midifile.cpp

示例2: getMidiControllerValue

PyObject* getMidiControllerValue(PyObject*, PyObject* args)
{
	const char* trackname;
	int ctrltype;

	if (!PyArg_ParseTuple(args, "si", &trackname, &ctrltype))
	{
		return NULL;
	}

	Track* t = song->findTrack(QString(trackname));
	if (t == NULL)
		return NULL;

	if (t->isMidiTrack() == false)
	{
		Py_INCREF(Py_None);
		return Py_None;
	}

	MidiTrack* track = (MidiTrack*) t;
	int channel = track->outChannel();
	int outport = track->outPort();
	MidiPort* mp = &midiPorts[outport];
	if (mp == NULL)
		return Py_BuildValue("i", -1);

	int value = mp->hwCtrlState(channel, ctrltype);
	return Py_BuildValue("i", value);
}
开发者ID:OpenGanesh,项目名称:oom,代码行数:30,代码来源:pyapi.cpp

示例3: MidiTrack

MidiTrack* MidiTrack::createTempoTrack() {

	MidiTrack* T = new MidiTrack();

	T->insertEvent(new TimeSignature());
	T->insertEvent(new Tempo());

	return T;
}
开发者ID:Geromatic,项目名称:Midi-Unreal,代码行数:9,代码来源:MidiTrack.cpp

示例4: updatePartSelection

void TrackListView::updatePartSelection(Part* part)/*{{{*/
{
    if(part)
    {
        MidiTrack* track = part->track();
        Part* curPart = m_editor->curCanvasPart();
        if (curPart)
        {
            song->setRecordFlag(curPart->track(), false);
        }
        m_editor->setCurCanvasPart(part);
        Song::movePlaybackToPart(part);
        // and turn it on for the new parts track
        song->setRecordFlag(track, true);
        song->deselectTracks();
        song->deselectAllParts();
        track->setSelected(true);
        part->setSelected(true);
        song->update(SC_SELECTION);

        int psn = part->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_selectedIndex = item->row();

                        m_tempColor = item->foreground();

                        m_model->blockSignals(true);
                        item->setForeground(QColor(99, 36, 36));
                        m_model->blockSignals(false);
                        update();
                        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;
                    }
                }
            }
        }
    }
}/*}}}*/
开发者ID:peter1000,项目名称:los,代码行数:57,代码来源:tracklistview.cpp

示例5: addPortCtrlEvents

void addPortCtrlEvents(Event& event, Part* part, bool doClones)/*{{{*/
{
    // Traverse and process the clone chain ring until we arrive at the same part again.
    // The loop is a safety net.
    // Update: Due to the varying calls, and order of, incARefcount, (msg)ChangePart, replaceClone, and remove/addPortCtrlEvents,
    //  we can not rely on the reference count as a safety net in these routines. We will just have to trust the clone chain.
    Part* p = part;
    //int j = doClones ? p->cevents()->arefCount() : 1;
    //if(j > 0)
    {
        //for(int i = 0; i < j; ++i)
        while (1)
        {
            // Added by Tim. p3.3.6
            //printf("addPortCtrlEvents i:%d %s %p events %p refs:%d arefs:%d\n", i, p->name().toLatin1().constData(), p, part->cevents(), part->cevents()->refCount(), j);

            Track* t = p->track();
            if (t)
            {
                MidiTrack* mt = (MidiTrack*) t;
                int port = mt->outPort();
                //const EventList* el = p->cevents();
                unsigned len = p->lenTick();
                //for(ciEvent ie = el->begin(); ie != el->end(); ++ie)
                //{
                //const Event& ev = ie->second;
                // Added by Tim. p3.3.6
                //printf("addPortCtrlEvents %s len:%d end:%d etick:%d\n", p->name().toLatin1().constData(), p->lenTick(), p->endTick(), event.tick());

                // Do not add events which are past the end of the part.
                if (event.tick() >= len)
                    break;

                if (event.type() == Controller)
                {
                    int ch = mt->outChannel();
                    int tck = event.tick() + p->tick();
                    int cntrl = event.dataA();
                    int val = event.dataB();
                    MidiPort* mp = &midiPorts[port];

                    mp->setControllerVal(ch, tck, cntrl, val, p);
                }
                //}
            }

            if (!doClones)
                break;
            // Get the next clone in the chain ring.
            p = p->nextClone();
            // Same as original part? Finished.
            if (p == part)
                break;
        }
    }
}/*}}}*/
开发者ID:ViktorNova,项目名称:los,代码行数:56,代码来源:part.cpp

示例6: removePortCtrlEvents

void removePortCtrlEvents(Part* part, bool doClones)/*{{{*/
{
    // Traverse and process the clone chain ring until we arrive at the same part again.
    // The loop is a safety net.
    // Update: Due to the varying calls, and order of, incARefcount, (msg)ChangePart, replaceClone, and remove/addPortCtrlEvents,
    //  we can not rely on the reference count as a safety net in these routines. We will just have to trust the clone chain.
    Part* p = part;
    //int j = doClones ? p->cevents()->arefCount() : 1;
    //if(j > 0)
    {
        //for(int i = 0; i < j; ++i)
        while (1)
        {
            MidiTrack* t = p->track();
            if (t)
            {
                MidiTrack* mt = (MidiTrack*) t;
                int port = mt->outPort();
                const EventList* el = p->cevents();
                //unsigned len = p->lenTick();
                for (ciEvent ie = el->begin(); ie != el->end(); ++ie)
                {
                    const Event& ev = ie->second;
                    // Added by T356. Do not remove events which are past the end of the part.
                    // No, actually, do remove ALL of them belonging to the part.
                    // Just in case there are stray values left after the part end.
                    //if(ev.tick() >= len)
                    //  break;

                    if (ev.type() == Controller)
                    {
                        int ch = mt->outChannel();
                        int tck = ev.tick() + p->tick();
                        int cntrl = ev.dataA();
                        MidiPort* mp = &midiPorts[port];

                        mp->deleteController(ch, tck, cntrl, p);
                    }
                }
            }

            if (!doClones)
                break;
            // Get the next clone in the chain ring.
            p = p->nextClone();
            // Same as original part? Finished.
            if (p == part)
                break;
        }
    }
}/*}}}*/
开发者ID:ViktorNova,项目名称:los,代码行数:51,代码来源:part.cpp

示例7: chainCloneInternal

void chainCloneInternal(Part* p)/*{{{*/
{
    Track* t = p->track();
    Part* p1 = 0;

    // Look for a part with the same event list, that we can chain to.
    // It's faster if track type is known...

    {
        MidiTrack* mt = 0;
        MidiTrackList* mtl = song->midis();
        for (ciMidiTrack imt = mtl->begin(); imt != mtl->end(); ++imt)
        {
            mt = *imt;
            const PartList* pl = mt->cparts();
            for (ciPart ip = pl->begin(); ip != pl->end(); ++ip)
            {
                // Added by Tim. p3.3.6
                //printf("chainCloneInternal track %p %s part %p %s evlist %p\n", (*imt), (*imt)->name().toLatin1().constData(), ip->second, ip->second->name().toLatin1().constData(), ip->second->cevents());

                if (ip->second != p && ip->second->cevents() == p->cevents())
                {
                    p1 = ip->second;
                    break;
                }
            }
            // If a suitable part was found on a different track, we're done. We will chain to it.
            // Otherwise keep looking for parts on another track. If no others found, then we
            //  chain to any suitable part which was found on the same given track t.
            if (p1 && mt != t)
                break;
        }
    }

    // No part found with same event list? Done.
    if (!p1)
        return;

    // Make sure the part to be chained is unchained first.
    p->prevClone()->setNextClone(p->nextClone());
    p->nextClone()->setPrevClone(p->prevClone());

    // Link the part to be chained.
    p->setPrevClone(p1);
    p->setNextClone(p1->nextClone());

    // Re-link the existing part.
    p1->nextClone()->setPrevClone(p);
    p1->setNextClone(p);
}/*}}}*/
开发者ID:ViktorNova,项目名称:los,代码行数:50,代码来源:part.cpp

示例8: writePartList

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);
    }
}/*}}}*/
开发者ID:peter1000,项目名称:los,代码行数:15,代码来源:AbstractMidiEditor.cpp

示例9: importPart

void LOS::importPart()
{
    unsigned curPos = song->cpos();
    MidiTrackList* tracks = song->tracks();
    MidiTrack* track = 0;
    // Get first selected track:
    for (iMidiTrack i = tracks->begin(); i != tracks->end(); i++)
    {
        MidiTrack* t = *i;
        if (t->selected())
        {
            // Changed by T356. Support mixed .mpt files.
            {
                track = t;
                break;
            }
        }
    }

    if (track)
    {
        bool loadAll;
        QString filename = getOpenFileName(QString(""), part_file_pattern, this, tr("LOS: load part"), &loadAll);
        if (!filename.isEmpty())
        {
            // Make a backup of the current clone list, to retain any 'copy' items,
            //  so that pasting works properly after.
            CloneList copyCloneList = cloneList;
            // Clear the clone list to prevent any dangerous associations with
            //  current non-original parts.
            cloneList.clear();

            importPartToTrack(filename, curPos, track);

            // Restore backup of the clone list, to retain any 'copy' items,
            //  so that pasting works properly after.
            cloneList.clear();
            cloneList = copyCloneList;
        }
    }
    else
    {
        QMessageBox::warning(this, QString("LOS"), tr("No track selected for import"));
    }
}
开发者ID:peter1000,项目名称:los,代码行数:45,代码来源:importmidi.cpp

示例10: getItemlistForPart

void EventCanvas::populateMultiSelect(CItem* baseItem)/*{{{*/
{
    if(editor->isGlobalEdit() && baseItem)
    {
        PartList* pl = editor->parts();
        int curTranspose = ((MidiTrack*)baseItem->part()->track())->getTransposition();
        Event curEvent = baseItem->event();
        int curPitch = curEvent.pitch();
        int curRawPitch = curPitch - curTranspose;
        //int curLen = curEvent.lenTick();
        m_multiSelect.clear();
        for(iPart p = pl->begin(); p != pl->end(); ++p)
        {
            if(p->second == _curPart)
                continue;
            CItemList pitems = getItemlistForPart(p->second);
            for (iCItem i = pitems.begin(); i != pitems.end(); ++i)
            {
                MidiTrack* mtrack = (MidiTrack*)i->second->part()->track();
                int transp = mtrack->getTransposition();
                Event e = i->second->event();
                if(e.empty())
                    continue;
                int pitch = e.pitch();
                int rpitch = pitch - transp;
                //int len = e.lenTick();
                //printf("Current pitch: %d, rawpitch: %d - note pitch: %d, raw: %d\n", curPitch, curRawPitch, pitch, rpitch);
                if(e.tick() == curEvent.tick() && rpitch == curRawPitch/*, len == curLen*/)
                {
                    m_multiSelect.add(i->second);
                        break;
                }
            }
        }
        //printf("MultiSelect list size: %d \n", (int)m_multiSelect.size());
    }
}/*}}}*/
开发者ID:ViktorNova,项目名称:los,代码行数:37,代码来源:EventCanvas.cpp

示例11: selectionChanged

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);
    }
}/*}}}*/
开发者ID:peter1000,项目名称:los,代码行数:24,代码来源:tracklistview.cpp

示例12: createWidget

QWidget* MenuList::createWidget(QWidget* parent)
{
	if(!_track)
		return 0;
	//if(!_track->isMidiTrack() || _track->type() != Track::AUDIO_SOFTSYNTH)
	//	return 0;
	MidiTrack* track = (MidiTrack*) _track;

	MidiDevice* md = 0;
	int port = -1;
	if (track->type() == Track::AUDIO_SOFTSYNTH)
	{
		md = dynamic_cast<MidiDevice*> (track);
		if (md)
			port = md->midiPort();
	}
	else
		port = track->outPort();
	list = new QListWidget(parent);
	list->setSelectionMode(QAbstractItemView::SingleSelection);
	list->setAlternatingRowColors(true);
	list->setEditTriggers(QAbstractItemView::NoEditTriggers);
	list->setFixedHeight(300);
	for (int i = 0; i < MIDI_PORTS; ++i)
	{
		QString name;
		name.sprintf("%d:%s", i + 1, midiPorts[i].portname().toLatin1().constData());
		list->insertItem(i, name);
		if (i == port)
			list->setCurrentRow(i);
	}
	connect(list, SIGNAL(itemPressed(QListWidgetItem*)), this, SLOT(updateData(QListWidgetItem*)));
	//connect(list, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(updateData(QListWidgetItem*)));
	//connect(list, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(updateData(QListWidgetItem*)));
	return list;
}
开发者ID:faesong,项目名称:oom,代码行数:36,代码来源:menulist.cpp

示例13: extractLyricsFromTrack

std::multimap<ReducedFraction, std::string>
extractLyricsFromTrack(const MidiTrack &lyricsTrack, int division)
      {
      std::multimap<ReducedFraction, std::string> lyrics;

      for (const auto &i: lyricsTrack.events()) {
            const auto& e = i.second;
            if (isLyricEvent(e)) {
                  const uchar* data = (uchar*)e.edata();
                  std::string text = MidiCharset::fromUchar(data);
                  if (isLyricText(text)) {
                        const auto tick = toMuseScoreTicks(i.first, division);
                                    // no charset handling here
                        lyrics.insert({tick, text});
                        }
                  }
            }
      return lyrics;
      }
开发者ID:cardinot,项目名称:MuseScore,代码行数:19,代码来源:importmidi_lyrics.cpp

示例14: isLyricsTrack

bool isLyricsTrack(const MidiTrack &lyricsTrack)
      {
      bool lyricsFlag = false;

      for (const auto &i: lyricsTrack.events()) {
            const auto& e = i.second;
            if (isLyricEvent(e)) {
                  const uchar* data = (uchar*)e.edata();
                              // no charset handling here
                  std::string text = MidiCharset::fromUchar(data);
                  if (isLyricText(text)) {
                        if (!lyricsFlag)
                              lyricsFlag = true;
                        }
                  }
            else if (e.type() == ME_NOTE)
                  return false;
            }

      return lyricsFlag;
      }
开发者ID:BlueMockingbird,项目名称:MuseScore,代码行数:21,代码来源:importmidi_lyrics.cpp

示例15: sizeof

MidiTrack MidiTrack::ReadFromStream(std::istream &stream)
{
   // Verify the track header
   const static string MidiTrackHeader = "MTrk";

   // I could use (MidiTrackHeader.length() + 1), but then this has to be
   // dynamically allocated.  More hassle than it's worth.  MIDI is well
   // defined and will always have a 4-byte header.  We use 5 so we get
   // free null termination.
   char header_id[5] = { 0, 0, 0, 0, 0 };
   unsigned long track_length;

   stream.read(header_id, static_cast<streamsize>(MidiTrackHeader.length()));
   stream.read(reinterpret_cast<char*>(&track_length), sizeof(unsigned long));

   if (stream.fail()) throw MidiError(MidiError_TrackHeaderTooShort);

   string header(header_id);
   if (header != MidiTrackHeader) throw MidiError_BadTrackHeaderType;

   // Pull the full track out of the file all at once -- there is an
   // End-Of-Track event, but this allows us handle malformed MIDI a
   // little more gracefully.
   track_length = BigToSystem32(track_length);
   char *buffer = new char[track_length + 1];
   buffer[track_length] = 0;

   stream.read(buffer, track_length);
   if (stream.fail())
   {
      delete[] buffer;
      throw MidiError(MidiError_TrackTooShort);
   }

   // We have to jump through a couple hoops because istringstream
   // can't handle binary data unless constructed through an std::string. 
   string buffer_string(buffer, track_length);
   istringstream event_stream(buffer_string, ios::binary);
   delete[] buffer;

   MidiTrack t;

   // Read events until we run out of track
   char last_status = 0;
   unsigned long current_pulse_count = 0;
   while (event_stream.peek() != char_traits<char>::eof())
   {
      MidiEvent ev = MidiEvent::ReadFromStream(event_stream, last_status); 
      last_status = ev.StatusCode();
      
      t.m_events.push_back(ev);

      current_pulse_count += ev.GetDeltaPulses();
      t.m_event_pulses.push_back(current_pulse_count);
   }

   t.BuildNoteSet();
   t.DiscoverInstrument();

   return t;
}
开发者ID:johndpope,项目名称:pianogame,代码行数:61,代码来源:MidiTrack.cpp


注:本文中的MidiTrack类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。