# Path: fretwork/midi/DataTypeConverters.py
# def writeVar(value):
#     "Converts an integer to varlength format"
#     sevens = to_n_bits(value, varLen(value))
#     for i in range(len(sevens)-1):
#         sevens[i] = sevens[i] | 0x80
#     return fromBytes(sevens)
# 
# Path: fretwork/midi/DataTypeConverters.py
# def writeBew(value, length):
#     """
#     Write int as big endian formatted string, (asserts length in [1,2,4])
#     Difficult to print the result in doctest, so I do a simple roundabout test.
# 
#     .. doctest::
# 
#         >>> readBew(writeBew(25057, 2))
#         25057
#         >>> readBew(writeBew(1642193635L, 4))
#         1642193635
#     """
#     return pack('>%s' % {1: 'B', 2: 'H', 4: 'L'}[length], value)


import sys
    import io as StringIO
    from cStringIO import StringIO
    from types import StringType
from .DataTypeConverters import writeVar
from .DataTypeConverters import writeBew

try:
except ImportError:
    StringType = str



class RawOutstreamFile(object):

    """

    Writes a midi file to disk.

    """

    def __init__(self, outfile=''):
        self.buffer = StringIO()
        self.outfile = outfile


    # native data reading functions


    def writeSlice(self, str_slice):
        "Writes the next text slice to the raw data"
        self.buffer.write(str_slice)


    def writeBew(self, value, length=1):
        "Writes a value to the file as big endian word"

# Path: fretwork/midi/DataTypeConverters.py
# def writeVar(value):
#     "Converts an integer to varlength format"
#     sevens = to_n_bits(value, varLen(value))
#     for i in range(len(sevens)-1):
#         sevens[i] = sevens[i] | 0x80
#     return fromBytes(sevens)
# 
# Path: fretwork/midi/DataTypeConverters.py
# def writeBew(value, length):
#     """
#     Write int as big endian formatted string, (asserts length in [1,2,4])
#     Difficult to print the result in doctest, so I do a simple roundabout test.
# 
#     .. doctest::
# 
#         >>> readBew(writeBew(25057, 2))
#         25057
#         >>> readBew(writeBew(1642193635L, 4))
#         1642193635
#     """
#     return pack('>%s' % {1: 'B', 2: 'H', 4: 'L'}[length], value)


# Path: fretwork/midi/RawOutstreamFile.py
import sys
    import io as StringIO
    from cStringIO import StringIO
    from types import StringType
from .DataTypeConverters import writeVar
from .DataTypeConverters import writeBew


try:
except ImportError:
    StringType = str



class RawOutstreamFile(object):

    """

    Writes a midi file to disk.

    """

    def __init__(self, outfile=''):
        self.buffer = StringIO()
        self.outfile = outfile


    # native data reading functions


    def writeSlice(self, str_slice):
        "Writes the next text slice to the raw data"
        self.buffer.write(str_slice)


    def writeBew(self, value, length=1):
        "Writes a value to the file as big endian word"

        self.writeSlice(writeBew(value, length))