# Path: fretwork/midi/DataTypeConverters.py
# def readBew(value):
#     """
#     Reads string as big endian word, (asserts len(value) in [1,2,4])
# 
#     .. doctest::
# 
#         >>> readBew('aáâã')
#         0
#         >>> readBew('aá')
#         0
#     """
#     try:
#         return unpack('>%s' % {1:'B', 2:'H', 4:'L'}[len(value)], value)[0]
#     except KeyError:
#         return 0
# 
# Path: fretwork/midi/DataTypeConverters.py
# def readVar(value):
#     """
#     Converts varlength format to integer. Just pass it 0 or more chars that
#     might be a varlen and it will only use the relevant chars.
#     use varLen(readVar(value)) to see how many bytes the integer value takes.
#     asserts len(value) >= 0
# 
#     .. doctest::
# 
#         >>> readVar('@')
#         1081408
#         >>> readVar('áâãa')
#         295821045191137
#     """
#     sum = 0
#     for byte in unpack('%sB' % len(value), value):
#         sum = (sum << 7) + (byte & 0x7F)
#         if not 0x80 & byte: break # stop after last byte
#     return sum
# 
# Path: fretwork/midi/DataTypeConverters.py
# def varLen(value):
#     """
#     Returns the the number of bytes an integer will be when
#     converted to varlength
#     """
#     if value <= 127:
#         return 1
#     elif value <= 16383:
#         return 2
#     elif value <= 2097151:
#         return 3
#     else:
#         return 4


import os.path
from .DataTypeConverters import readBew as readBew_
from .DataTypeConverters import readVar
from .DataTypeConverters import varLen

    def getCursor(self):
        "Returns the value of the cursor"
        return self.cursor

    def moveCursor(self, relative_position=0):
        "Moves the cursor to a new relative position"
        self.cursor += relative_position

    def nextSlice(self, length, move_cursor=1):
        "Reads the next text slice from the raw data, with length"
        c = self.cursor
        slc = self.data[c:c+length]
        if move_cursor:
            self.moveCursor(length)
        return slc

    def readBew(self, n_bytes=1, move_cursor=1):
        """
        Reads n bytes of date from the current cursor position.
        Moves cursor if move_cursor is true
        """
        return readBew_(self.nextSlice(n_bytes, move_cursor))

    def readVarLen(self):
        """
        Reads a variable length value from the current cursor position.
        Moves cursor if move_cursor is true
        """
        MAX_VARLEN = 4  # Max value varlen can be

# Path: fretwork/midi/DataTypeConverters.py
# def readBew(value):
#     """
#     Reads string as big endian word, (asserts len(value) in [1,2,4])
# 
#     .. doctest::
# 
#         >>> readBew('aáâã')
#         0
#         >>> readBew('aá')
#         0
#     """
#     try:
#         return unpack('>%s' % {1:'B', 2:'H', 4:'L'}[len(value)], value)[0]
#     except KeyError:
#         return 0
# 
# Path: fretwork/midi/DataTypeConverters.py
# def readVar(value):
#     """
#     Converts varlength format to integer. Just pass it 0 or more chars that
#     might be a varlen and it will only use the relevant chars.
#     use varLen(readVar(value)) to see how many bytes the integer value takes.
#     asserts len(value) >= 0
# 
#     .. doctest::
# 
#         >>> readVar('@')
#         1081408
#         >>> readVar('áâãa')
#         295821045191137
#     """
#     sum = 0
#     for byte in unpack('%sB' % len(value), value):
#         sum = (sum << 7) + (byte & 0x7F)
#         if not 0x80 & byte: break # stop after last byte
#     return sum
# 
# Path: fretwork/midi/DataTypeConverters.py
# def varLen(value):
#     """
#     Returns the the number of bytes an integer will be when
#     converted to varlength
#     """
#     if value <= 127:
#         return 1
#     elif value <= 16383:
#         return 2
#     elif value <= 2097151:
#         return 3
#     else:
#         return 4


# Path: fretwork/midi/RawInstreamFile.py
import os.path
from .DataTypeConverters import readBew as readBew_
from .DataTypeConverters import readVar
from .DataTypeConverters import varLen


    def getCursor(self):
        "Returns the value of the cursor"
        return self.cursor

    def moveCursor(self, relative_position=0):
        "Moves the cursor to a new relative position"
        self.cursor += relative_position

    def nextSlice(self, length, move_cursor=1):
        "Reads the next text slice from the raw data, with length"
        c = self.cursor
        slc = self.data[c:c+length]
        if move_cursor:
            self.moveCursor(length)
        return slc

    def readBew(self, n_bytes=1, move_cursor=1):
        """
        Reads n bytes of date from the current cursor position.
        Moves cursor if move_cursor is true
        """
        return readBew_(self.nextSlice(n_bytes, move_cursor))

    def readVarLen(self):
        """
        Reads a variable length value from the current cursor position.
        Moves cursor if move_cursor is true
        """
        MAX_VARLEN = 4  # Max value varlen can be

        var = readVar(self.nextSlice(MAX_VARLEN, 0))