Package echonest :: Package support :: Package midi :: Module DataTypeConverters
[hide private]
[frames] | no frames]

Module DataTypeConverters

source code

Functions [hide private]
 
getNibbles(byte)
Returns hi and lo bits in a byte as a tuple >>> getNibbles(142) (8, 14)
source code
 
setNibbles(hiNibble, loNibble)
Returns byte with value set according to hi and lo bits Asserts hiNibble and loNibble in range(16) >>> setNibbles(8, 14) 142
source code
 
readBew(value)
Reads string as big endian word, (asserts len(value) in [1,2,4]) >>> readBew('aáâã') 1642193635L >>> readBew('aá') 25057
source code
 
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.
source code
 
readVar(value)
Converts varlength format to integer.
source code
 
varLen(value)
Returns the the number of bytes an integer will be when converted to varlength
source code
 
writeVar(value)
Converts an integer to varlength format
source code
 
to_n_bits(value, length=1, nbits=7)
returns the integer value as a sequence of nbits bytes
source code
 
toBytes(value)
Turns a string into a list of byte values
source code
 
fromBytes(value)
Turns a list of bytes into a string
source code
Function Details [hide private]

getNibbles(byte)

source code 

Returns hi and lo bits in a byte as a tuple
>>> getNibbles(142)
(8, 14)

Asserts byte value in byte range
>>> getNibbles(256)
Traceback (most recent call last):
    ...
ValueError: Byte value out of range 0-255: 256

writeBew(value, length)

source code 
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. >>> readBew(writeBew(25057, 2)) 25057 >>> readBew(writeBew(1642193635L, 4)) 1642193635L

readVar(value)

source code 
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 >>> readVar('€@') 64 >>> readVar('áâãa') 205042145