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


C++ MidiEvent::GetEventType方法代码示例

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


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

示例1: PostLoad

bool QSoundSeq::PostLoad()
{
	if (readMode != READMODE_CONVERT_TO_MIDI)
		return true;

	// We need to add pitch bend events for vibrato, which is controlled by a software LFO
	//  This is actually a bit tricky because the LFO is running independent of the sequence
	//  tempo.  It gets updated (251/4) times a second, always.  We will have to convert 
	//  ticks in our sequence into absolute elapsed time, which means we also need to keep
	//  track of any tempo events that change the absolute time per tick.
	vector<MidiEvent*> tempoEvents;
	vector<MidiTrack*>& miditracks = midi->aTracks;

	// First get all tempo events, we assume they occur on track 1
	for (unsigned int i = 0; i < miditracks[0]->aEvents.size(); i++)
	{
		MidiEvent* event = miditracks[0]->aEvents[i];
		if (event->GetEventType() == MIDIEVENT_TEMPO)
			tempoEvents.push_back(event);
	}

	// Now for each track, gather all vibrato events, lfo events, pitch bend events and track end events
	for (unsigned int i = 0; i < miditracks.size(); i++)
	{
		vector<MidiEvent*> events(tempoEvents);
		MidiTrack* track = miditracks[i];
		int channel = this->aTracks[i]->channel;

		for (unsigned int j = 0; j < track->aEvents.size(); j++)
		{
			MidiEvent* event = miditracks[i]->aEvents[j];
			MidiEventType type = event->GetEventType();
			if (type == MIDIEVENT_MARKER || type == MIDIEVENT_PITCHBEND || type == MIDIEVENT_ENDOFTRACK)
				events.push_back(event);
		}
		// We need to sort by priority so that vibrato events get ordered correctly.  Since they cause the
		//  pitch bend range to be set, they need to occur before pitchbend events.
		stable_sort(events.begin(), events.end(), PriorityCmp());	//Sort all the events by priority
		stable_sort(events.begin(), events.end(), AbsTimeCmp());	//Sort all the events by absolute time, so that delta times can be recorded correctly
		

		// And now we actually add vibrato and pitch bend events
		const uint32_t ppqn = GetPPQN();					// pulses (ticks) per quarter note
		const uint32_t mpLFOt = (uint32_t)((1/(251/4.0)) * 1000000);	// microseconds per LFO tick
		uint32_t mpqn = 500000;							// microseconds per quarter note - 120 bpm default
		uint32_t mpt = mpqn / ppqn;						// microseconds per MIDI tick
		short pitchbend = 0;							// pitch bend in cents
		int pitchbendRange = 200;						// pitch bend range in cents default 2 semitones
		double vibrato = 0;								// vibrato depth in cents
		uint16_t tremelo = 0;								// tremelo depth.  we divide this value by 0x10000 to get percent amplitude attenuation
		uint16_t lfoRate = 0;								// value added to lfo env every lfo tick
		uint32_t lfoVal = 0;									// LFO envelope value. 0 - 0xFFFFFF .  Effective envelope range is -0x1000000 to +0x1000000
		int lfoStage = 0;								// 0 = rising from mid, 1 = falling from peak, 2 = falling from mid 3 = rising from bottom
		short lfoCents = 0;								// cents adjustment from most recent LFO val excluding pitchbend.
		long effectiveLfoVal = 0;
		//bool bLfoRising = true;;						// is LFO rising or falling?
		
		uint32_t startAbsTicks = 0;							// The MIDI tick time to start from for a given vibrato segment

		size_t numEvents = events.size();
		for (size_t j = 0; j < numEvents; j++)
		{
			MidiEvent* event = events[j];
			uint32_t curTicks = event->AbsTime;			//current absolute ticks
			
			if (curTicks > 0 /*&& (vibrato > 0 || tremelo > 0)*/ && startAbsTicks < curTicks)
			{
				// if we're starting a fresh vibrato segment, let's start the LFO env at 0 and set it to rise
				/*if (prevVibrato == 0 && prevTremelo == 0)
				{
					lfoVal = 0;
					lfoStage = 0;
				}*/
				
				long segmentDurTicks = curTicks - startAbsTicks;
				double segmentDur = segmentDurTicks * mpt;	// duration of this segment in micros
				double lfoTicks = segmentDur / (double)mpLFOt;
				double numLfoPhases = (lfoTicks * (double)lfoRate) / (double)0x20000;
				//double midiTicksPerPhase = (curTicks-startAbsTicks) / numLfoPhases;
				//double centsPerMidiTick = vibrato / midiTicksPerPhase;
				double lfoRatePerMidiTick = (numLfoPhases * 0x20000) / (double)segmentDurTicks;

				const uint8_t tickRes = 16;
				uint32_t lfoRatePerLoop = (uint32_t)((tickRes * lfoRatePerMidiTick) * 256);

				for (int t = 0; t < segmentDurTicks; t += tickRes)
				{
					lfoVal += lfoRatePerLoop;
					if (lfoVal > 0xFFFFFF)
					{
						lfoVal -= 0x1000000;
						lfoStage = (lfoStage+1) % 4;
					}
					effectiveLfoVal = lfoVal;
					if (lfoStage == 1)
						effectiveLfoVal = 0x1000000 - lfoVal;
					else if (lfoStage == 2)
						effectiveLfoVal = -((long)lfoVal);
					else if (lfoStage == 3)
						effectiveLfoVal = -0x1000000 + lfoVal;
//.........这里部分代码省略.........
开发者ID:Kajiu,项目名称:vgmtrans,代码行数:101,代码来源:QSoundSeq.cpp


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