13
0

make VLQ save+restore functions publically accessible, for use with meta-events

git-svn-id: svn://localhost/ardour2/branches/3.0@7952 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2010-11-03 00:06:42 +00:00
parent fb048ebc30
commit a188e69aae
3 changed files with 15 additions and 9 deletions

View File

@ -386,6 +386,12 @@ int smf_event_is_textual(const smf_event_t *event) WARN_UNUSED_RESULT;
char *smf_event_decode(const smf_event_t *event) WARN_UNUSED_RESULT;
char *smf_event_extract_text(const smf_event_t *event) WARN_UNUSED_RESULT;
/* Routines for dealing with Variable Length Quantities (VLQ's).
Slightly odd names reflect original static names within libsmf
*/
int smf_format_vlq (unsigned char *buf, int length, unsigned long value);
int smf_extract_vlq(const unsigned char *buf, const size_t buffer_length, uint32_t *value, uint32_t *len);
/* Routines for loading SMF files. */
smf_t *smf_load(FILE *) WARN_UNUSED_RESULT;
smf_t *smf_load_from_memory(const void *buffer, const size_t buffer_length) WARN_UNUSED_RESULT;

View File

@ -206,8 +206,8 @@ parse_mthd_chunk(smf_t *smf)
* Explanation of Variable Length Quantities is here: http://www.borg.com/~jglatt/tech/midifile/vari.htm
* Returns 0 iff everything went OK, different value in case of error.
*/
static int
extract_vlq(const unsigned char *buf, const size_t buffer_length, uint32_t *value, uint32_t *len)
int
smf_extract_vlq(const unsigned char *buf, const size_t buffer_length, uint32_t *value, uint32_t *len)
{
uint32_t val = 0;
const unsigned char *c = buf;
@ -284,7 +284,7 @@ expected_sysex_length(const unsigned char status, const unsigned char *second_by
return (-1);
}
extract_vlq(second_byte, buffer_length, &sysex_length, &len);
smf_extract_vlq(second_byte, buffer_length, &sysex_length, &len);
if (consumed_bytes != NULL)
*consumed_bytes = len;
@ -558,7 +558,7 @@ parse_next_event(smf_track_t *track)
assert(buffer_length > 0);
/* First, extract time offset from previous event. */
if (extract_vlq(c, buffer_length, &time, &len))
if (smf_extract_vlq(c, buffer_length, &time, &len))
goto error;
c += len;
@ -655,7 +655,7 @@ smf_event_extract_text(const smf_event_t *event)
return (NULL);
}
extract_vlq((void *)&(event->midi_buffer[2]), event->midi_buffer_length - 2, &string_length, &length_length);
smf_extract_vlq((void *)&(event->midi_buffer[2]), event->midi_buffer_length - 2, &string_length, &length_length);
if (string_length <= 0) {
g_critical("smf_event_extract_text: truncated MIDI message.");

View File

@ -156,8 +156,8 @@ track_append(smf_track_t *track, const void *buffer, const int buffer_length)
return (0);
}
static int
format_vlq(unsigned char *buf, int length, unsigned long value)
int
smf_format_vlq(unsigned char *buf, int length, unsigned long value)
{
int i;
unsigned long buffer;
@ -212,7 +212,7 @@ smf_event_new_textual(int type, const char *text)
event->midi_buffer[0] = 0xFF;
event->midi_buffer[1] = type;
vlq_length = format_vlq(event->midi_buffer + 2, MAX_VLQ_LENGTH - 2, text_length);
vlq_length = smf_format_vlq(event->midi_buffer + 2, MAX_VLQ_LENGTH - 2, text_length);
copied_length = snprintf((char *)event->midi_buffer + vlq_length + 2, event->midi_buffer_length - vlq_length - 2, "%s", text);
assert(copied_length == text_length);
@ -231,7 +231,7 @@ write_vlq(smf_event_t *event, unsigned long value)
unsigned char buf[MAX_VLQ_LENGTH];
int vlq_length;
vlq_length = format_vlq(buf, MAX_VLQ_LENGTH, value);
vlq_length = smf_format_vlq(buf, MAX_VLQ_LENGTH, value);
return (track_append(event->track, buf, vlq_length));
}