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


C++ MidiMessage::getTextFromTextMetaEvent方法代码示例

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


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

示例1: main


//.........这里部分代码省略.........
        gcode.clear();
        heeks.clear();
        key_position.clear();

        std::ostringstream l_ossGCode;

        for (int track = 0; track<midi_file.getNumTracks(); track++)
        {
            int number_of_notes_included = 0;
            int number_of_notes_ignored = 0;

            const MidiMessageSequence *pMessageSequence = midi_file.getTrack(track);
            double start_time = pMessageSequence->getStartTime();
            double end_time = pMessageSequence->getEndTime();
            double duration = end_time - start_time;

            if (duration <= 0.0001) continue;

            l_ossGCode.str("");
            l_ossGCode << "(Duration of track " << track << " is " << duration << " seconds)";
            gcode.push_back( l_ossGCode.str() );
            printf("%s\n", l_ossGCode.str().c_str());

            // printf("Duration of track %d is %lf seconds\n", track, duration);

            for (int event = 0; event < pMessageSequence->getNumEvents(); event++)
            {
                MidiMessageSequence::MidiEventHolder *pEvent = pMessageSequence->getEventPointer(event);
                MidiMessage message = pEvent->message;
                double time_stamp = message.getTimeStamp();

                if (message.isTextMetaEvent())
                {
                    String text = message.getTextFromTextMetaEvent();
                    char buf[1024];
                    memset( buf, '\0', sizeof(buf) );
                    text.copyToBuffer( buf, sizeof(buf)-1 );
                    // printf("Track %d is %s\n", track, buf );
                    l_ossGCode.str("");
                    l_ossGCode << "(Text track " << track << " is " << buf << ")";
                    gcode.push_back(l_ossGCode.str());
                    printf("%s\n", l_ossGCode.str().c_str());

                    std::ostringstream l_ossHeeks;
                    l_ossHeeks << "<Text text=\"" << buf << "\" font=\"OpenGL\" col=\"0\" m0=\"-0.0443342566\" m1=\"-0.999016753\" m2=\"0\" m3=\"" << (double) (time_stamp * mm_per_second) << "\" m4=\"0.999016753\" m5=\"-0.0443342566\" m6=\"0\" m7=\"" << (double) ((track_width + space_between_tracks) * track) << "\" m8=\"0\" m9=\"0\" ma=\"1\" mb=\"0\" id=\"" << id++ << "\" />";
                    heeks.push_back( l_ossHeeks.str() );
                }

                if (message.isTrackNameEvent())
                {
                    String text = message.getTextFromTextMetaEvent();
                    char buf[1024];
                    memset( buf, '\0', sizeof(buf) );
                    text.copyToBuffer( buf, sizeof(buf)-1 );
                    printf("Track %d is %s\n", track, buf );
                }

                if (message.isNoteOn())
                {
                    char note_name[256];
                    memset( note_name, '\0', sizeof(note_name) );
                    message.getMidiNoteName(message.getNoteNumber(), true, true, middle_c_octave).copyToBuffer( note_name, sizeof(note_name)-1 );

                    notes.insert( message.getNoteNumber() );

                    // printf("time %lf note %s\n", time_stamp, note_name );
开发者ID:DavidNicholls,项目名称:heekscnc,代码行数:67,代码来源:main.cpp

示例2: main

int main(int argc, char* argv[])
{
	string printThis = "";	//string which will contain the content to be saved to output file
	cout << "Path and name of file: ";
	//String st = "C:\\Program Files (x86)\\Phase Shift\\music\\Paramore\\Paramore - Ignorance\\notes.mid"; //this file was throwing exceptions in Java version
	//C:\Users\Sinead\Documents\102. Paramore 01_P-I\Paramore - Ignorance
//	String st = "C:\\Users\\Sinead\\Documents\\102. Paramore 01_P-I\\Paramore - Ignorance\\notes.mid"; //hardcoded for now
	String st = "C:\\Users\\Sinead\\Documents\\(GHSH_MSL)_09-TIO\\09 - Take It Off\\notes.mid"; //hardcoded for now
	//String st = "C:\\Program Files (x86)\\Phase Shift\\music\\The Donnas\\09 - Take It Off\\notes.mid"; //hardcoded for now
	//C:\\Users\\Sinead\\Documents\\(GHSH_MSL)_09-TIO\\09 - Take It Off

	printThis += st.toStdString() + "\n";
	cout << st << "\n";

	//load notes.midi
	File file(st);
	FileInputStream fiStream(file);
	MidiFile midiFile;
	if (!midiFile.readFrom(fiStream))
	{
		cout << "Error: Nothing Loaded";
		return 1;
	}

	if (midiFile.getNumTracks() == 0) return 1;

	//set level of difficulty
	string level = "expert"; //hardcoded for now
	int lvl = 0;
	if (level == "easy") {
		lvl = 4;
	}
	else if (level == "medium") {
		lvl = 5;
	}
	else if (level == "hard") {
		lvl = 6;
	}
	else if (level == "expert") {
		lvl = 7;
	}
	else {
		cout << "invalid level";
		return 1;
	}
	printThis += "Level: " + level + "\n";
	//set instrument
	string selectInstru = "drums";
	if (selectInstru != "guitar" && selectInstru != "bass" && selectInstru != "drums" && selectInstru != "vocals")
	{
		cout << "invalid instrument";
		return 1;
	}
	printThis += "Instrument: " + selectInstru + "\n";
	long ticks_per_beat = midiFile.getTimeFormat();
	int tracks = midiFile.getNumTracks();

	int useTrack = 0; //the index of the mid file which contains the notes for the instrument. Set in following for-loop
	string timeSig = ""; //the time signature of the song. Set in following for-loop
	vector<vector<string>> songSections; //timestamps and sections names of the song. Set in following for-loop
	//use this to store entries of [timestamp,  song_section] which will be used to mark the verse, chorus, etc of the tab
	//populated in the following for-loop

	for (int n = 0; n < tracks; n++)
	{
		const MidiMessageSequence* seq = midiFile.getTrack(n);
		MidiMessageSequence::MidiEventHolder * event = seq->getEventPointer(0); //get the event 0 for each track
		MidiMessage m = event->message;

		String trackName = m.getTextFromTextMetaEvent();

		//TRACK WITH INSTRUMENT NOTES
		if (trackName.toLowerCase().contains(String(selectInstru)))
			//get indexes of the tracks which contain the songs sections, and drum notes
		{
			useTrack = n;
			//cout << "use Track " << useTrack << "\n";
		}

		//TIME SIGNATURE
		if (trackName.equalsIgnoreCase("midi_export"))
			//get information about the song
			//time signature and tempo are entries 2 and 3, where tick ==0
		{
			for (int nEvent = 1; nEvent < seq->getNumEvents(); nEvent++)
			{
				event = seq->getEventPointer(nEvent); //get each event in track
				MidiMessage m = event->message;
				double tick = m.getTimeStamp();

				if (tick == 0)
				{
					//cout << n << " "  << nEvent  << " " << tick << " " << m.getTextFromTextMetaEvent() << "\n";
					//cout << n << " " << nEvent << " isTimeSignatureMetaEvent "  << m.isTimeSignatureMetaEvent () << " getTimeSignatureInfo \n"; //<< m.getTimeSignatureInfo() << "\n";
					//getTimeSignatureInfo (int &numerator, int &denominator)
					//cout << n << " " << nEvent << " isTempoMetaEvent "  << m.isTempoMetaEvent () << " getTimeSignatureInfo \n"; //<< m.getTimeSignatureInfo() << "\n";
				}
			}
		}

//.........这里部分代码省略.........
开发者ID:sineadkearney,项目名称:Portfolio_of_code,代码行数:101,代码来源:Main.cpp


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