make VLQ save+restore functions publically accessible, for use with meta-events
authorPaul Davis <paul@linuxaudiosystems.com>
Wed, 3 Nov 2010 00:06:42 +0000 (00:06 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Wed, 3 Nov 2010 00:06:42 +0000 (00:06 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@7952 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/evoral/src/libsmf/smf.h
libs/evoral/src/libsmf/smf_load.c
libs/evoral/src/libsmf/smf_save.c

index 5e3e2d1859d837fcb3f4f269e79e14e93f4a3b26..7f4aa402c05d1ae93ae13e1f53a792dde95de548 100644 (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;
index cebca73b82aab9cc18997010309670e40c1afcee..060dc5849ea6feb49b0c6f844abab0047204956d 100644 (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.");
index b03bf900447f43b500c99e359dc98d519866007d..b99af75461b094207d11d3b9f967fe0aa6d1d7db 100644 (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));
 }