# Path: pylsdj/project.py
# def load_lsdsng(filename):
#     """Load a Project from a ``.lsdsng`` file.
# 
#     :param filename: the name of the file from which to load
#     :rtype: :py:class:`pylsdj.Project`
#     """
# 
#     # Load preamble data so that we know the name and version of the song
#     with open(filename, 'rb') as fp:
#         preamble_data = bread.parse(fp, spec.lsdsng_preamble)
# 
#     with open(filename, 'rb') as fp:
#         # Skip the preamble this time around
#         fp.seek(int(len(preamble_data) / 8))
# 
#         # Load compressed data into a block map and use BlockReader to
#         # decompress it
#         factory = BlockFactory()
# 
#         while True:
#             block_data = bytearray(fp.read(blockutils.BLOCK_SIZE))
# 
#             if len(block_data) == 0:
#                 break
# 
#             block = factory.new_block()
#             block.data = block_data
# 
#         remapped_blocks = filepack.renumber_block_keys(factory.blocks)
# 
#         reader = BlockReader()
#         compressed_data = reader.read(remapped_blocks)
# 
#         # Now, decompress the raw data and use it and the preamble to construct
#         # a Project
#         raw_data = filepack.decompress(compressed_data)
# 
#         name = preamble_data.name
#         version = preamble_data.version
#         size_blks = int(math.ceil(
#             float(len(compressed_data)) / blockutils.BLOCK_SIZE))
# 
#         return Project(name, version, size_blks, raw_data)


import os
from nose.tools import assert_equal
from .project import load_lsdsng



SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))

def test_phrase_load():
    proj = load_lsdsng(os.path.join(SCRIPT_DIR, 'test_data', 'UNTOLDST.lsdsng'))

    phrase = proj.song.phrases[0x24]

    assert_equal('C 4', phrase.notes[0x0])
    assert_equal('K', phrase.fx[0x3])
    assert_equal('L', phrase.fx[0xc])
    assert_equal(1, phrase.fx_val[0xc])
    assert_equal(None, phrase.instruments[1])
    assert_equal(2, phrase.instruments[4].index)

def test_arduinoboy_phrase_load():

# Path: pylsdj/project.py
# def load_lsdsng(filename):
#     """Load a Project from a ``.lsdsng`` file.
# 
#     :param filename: the name of the file from which to load
#     :rtype: :py:class:`pylsdj.Project`
#     """
# 
#     # Load preamble data so that we know the name and version of the song
#     with open(filename, 'rb') as fp:
#         preamble_data = bread.parse(fp, spec.lsdsng_preamble)
# 
#     with open(filename, 'rb') as fp:
#         # Skip the preamble this time around
#         fp.seek(int(len(preamble_data) / 8))
# 
#         # Load compressed data into a block map and use BlockReader to
#         # decompress it
#         factory = BlockFactory()
# 
#         while True:
#             block_data = bytearray(fp.read(blockutils.BLOCK_SIZE))
# 
#             if len(block_data) == 0:
#                 break
# 
#             block = factory.new_block()
#             block.data = block_data
# 
#         remapped_blocks = filepack.renumber_block_keys(factory.blocks)
# 
#         reader = BlockReader()
#         compressed_data = reader.read(remapped_blocks)
# 
#         # Now, decompress the raw data and use it and the preamble to construct
#         # a Project
#         raw_data = filepack.decompress(compressed_data)
# 
#         name = preamble_data.name
#         version = preamble_data.version
#         size_blks = int(math.ceil(
#             float(len(compressed_data)) / blockutils.BLOCK_SIZE))
# 
#         return Project(name, version, size_blks, raw_data)


# Path: pylsdj/test_phrase.py
import os
from nose.tools import assert_equal
from .project import load_lsdsng




SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))

def test_phrase_load():
    proj = load_lsdsng(os.path.join(SCRIPT_DIR, 'test_data', 'UNTOLDST.lsdsng'))

    phrase = proj.song.phrases[0x24]

    assert_equal('C 4', phrase.notes[0x0])
    assert_equal('K', phrase.fx[0x3])
    assert_equal('L', phrase.fx[0xc])
    assert_equal(1, phrase.fx_val[0xc])
    assert_equal(None, phrase.instruments[1])
    assert_equal(2, phrase.instruments[4].index)

def test_arduinoboy_phrase_load():

    proj = load_lsdsng(os.path.join(SCRIPT_DIR, 'test_data', 'ARDBOYxx.lsdsng'))