MCPcopy Create free account
hub / github.com/celtera/libremidi / parse

Method parse

include/libremidi/reader.cpp:536–703  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

534}
535
536LIBREMIDI_INLINE
537auto reader::parse(const uint8_t* dataPtr, std::size_t size) noexcept -> parse_result
538try
539{
540 using namespace util;
541
542 tracks.clear();
543
544 if (size == 0)
545 {
546#if defined(__LIBREMIDI_DEBUG__)
547 std::cerr << "empty buffer passed to parse." << std::endl;
548#endif
549 return parse_result::invalid;
550 }
551
552 const uint8_t* const data_end = dataPtr + size;
553
554 uint32_t header_id = read_checked::read_uint32_be(dataPtr, data_end);
555 uint32_t header_length = read_checked::read_uint32_be(dataPtr, data_end);
556
557 if (static_cast<int>(header_id) != str_to_headerid("MThd") || header_length != 6)
558 {
559#if defined(__LIBREMIDI_DEBUG__)
560 std::cerr << "couldn't parse header" << std::endl;
561#endif
562 return parse_result::invalid;
563 }
564
565 format = read_checked::read_uint16_be(
566 dataPtr, data_end); //@tofix format type -> save for later eventually
567 if (format > 2)
568 {
569#if defined(__LIBREMIDI_DEBUG__)
570 std::cerr << "unknown format" << std::endl;
571#endif
572 return parse_result::invalid;
573 }
574 int track_count = read_checked::read_uint16_be(dataPtr, data_end);
575 uint16_t time_division = read_checked::read_uint16_be(dataPtr, data_end);
576
577 // CBB: deal with the SMPTE style time coding
578 // timeDivision is described here http://www.sonicspot.com/guide/midifiles.html
579 if (time_division & 0x8000)
580 {
581#if defined(__LIBREMIDI_DEBUG__)
582 std::cerr << "found SMPTE time frames (unsupported)" << std::endl;
583 int fps = (timeDivision >> 16) & 0x7f;
584 if (fps != -30 && fps != -29 && fps != -25 && fps != -24)
585 return parse_result::invalid;
586 int ticksPerFrame = timeDivision & 0xff;
587#endif
588 // given beats per second, timeDivision should be derivable.
589 return parse_result::invalid;
590 }
591
592 startingTempo = 120.0f; // midi default
593 ticksPerBeat = float(time_division); // ticks per beat (a beat is defined as a quarter note)

Callers 4

midifile_read.cppFile · 0.80
mainFunction · 0.80
mainFunction · 0.80

Calls 6

str_to_headeridFunction · 0.85
is_meta_eventMethod · 0.80
clearMethod · 0.45
emptyMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected