libremidi icon indicating copy to clipboard operation
libremidi copied to clipboard

Writing meta data?

Open g40 opened this issue 3 years ago • 0 comments

Hello and thanks for your efforts here.

Which tools are the preferred GOTOs for testing this code?

The code below did appear to produce a broken file, where import into Tracktion/Cakewalk etc failed. Is there anything simple and open source that can be used as a baseline reference?

Any thoughts?

Environment: Windows 10 / VS 2022.

MTIA.

			// test out writer stuff.
			std::ofstream of("x.mid", std::ios::binary);
			if (of.good())
			{
				libremidi::message meta;
				libremidi::writer writer;
				// writer.add_track();

				// this block seems to create an unreadable file in any of the many tools tested?
				{
					// standard 4/4 timing
					meta = libremidi::meta_events::time_signature(4, 4);
					writer.add_event(0, libremidi::track_event{ 0, 0, meta });
					// 120 BPM as we know it Jim
					meta = libremidi::meta_events::tempo(50000); 
					writer.add_event(0, libremidi::track_event{ 0, 0, meta });
				}
				// play middle C loudly
				libremidi::message msg = libremidi::message::note_on(0,60,127);
				writer.add_event(0, libremidi::track_event{ 0, 0, msg });
				// off -why does it need velocity?
				msg = libremidi::message::note_off(0, 60, 0);
				writer.add_event(0, libremidi::track_event{ 500, 0, msg });

				// does it need an end of track message? 
                               // not according to the library code
				meta = libremidi::meta_events::end_of_track();
				writer.add_event(0, libremidi::track_event{ 0, 0, meta });

				// write the content to file.
				writer.write(of);
			}

g40 avatar Apr 27 '22 00:04 g40