# Path: xnb_parse/type_reader.py
# class TypeReaderPlugin(Plugin):
#     """
#     type reader plugins
#     """
# 
# class BaseTypeReader(object):
#     target_type = None
#     reader_name = None
#     is_value_type = False
#     is_generic_type = False
#     is_enum_type = False
#     file_platform = None
#     file_version = None
# 
#     def __init__(self, stream=None, version=None):
#         self.stream = stream
#         self.version = version
# 
#     def __str__(self):
#         return self.reader_name
# 
#     def read(self):
#         raise ReaderError("Unimplemented type reader: '{}'".format(self.reader_name))
# 
#     def init_reader(self, file_platform=None, file_version=None):
#         self.file_platform = file_platform
#         self.file_version = file_version
# 
# Path: xnb_parse/type_readers/xna_primitive.py
# class StringReader(BaseTypeReader, TypeReaderPlugin):
#     target_type = 'System.String'
#     reader_name = 'Microsoft.Xna.Framework.Content.StringReader'
# 
#     def read(self):
#         return self.stream.read_string()
# 
# class Int32Reader(ValueTypeReader, TypeReaderPlugin):
#     target_type = 'System.Int32'
#     reader_name = 'Microsoft.Xna.Framework.Content.Int32Reader'
# 
#     def read(self):
#         return self.stream.read_int32()
# 
# class SingleReader(ValueTypeReader, TypeReaderPlugin):
#     target_type = 'System.Single'
#     reader_name = 'Microsoft.Xna.Framework.Content.SingleReader'
# 
#     def read(self):
#         return self.stream.read_single()
# 
# Path: xnb_parse/xna_types/xna_media.py
# class SoundEffect(object):
#     def __init__(self, sound_format, sound_data, loop_start, loop_length, duration, needs_swap=False):
#         self.sound_format = sound_format
#         self.sound_data = sound_data
#         self.loop_start = loop_start
#         self.loop_length = loop_length
#         self.duration = duration
#         self.needs_swap = needs_swap
# 
#     def __str__(self):
#         return "SoundEffect fs:{} ds:{} d:{}ms ls:{} ll:{}".format(len(self.sound_format), len(self.sound_data),
#                                                                    self.duration, self.loop_start, self.loop_length)
# 
#     def export(self, filename):
#         write_wav(filename, self.sound_format, self.sound_data, self.needs_swap)
# 
#     def xml(self, parent=None):
#         if parent is None:
#             root = ET.Element('SoundEffect')
#         else:
#             root = ET.SubElement(parent, 'SoundEffect')
#         root.set('loopStart', str(self.loop_start))
#         root.set('loopLength', str(self.loop_length))
#         root.set('duration', str(self.duration))
#         return root
# 
# class Song(object):
#     def __init__(self, filename, duration):
#         self.filename = filename
#         self.duration = duration
# 
#     def __str__(self):
#         return "Song f:'{}' d:{}ms".format(self.filename, self.duration)
# 
#     def xml(self, parent=None):
#         if parent is None:
#             root = ET.Element('Song')
#         else:
#             root = ET.SubElement(parent, 'Song')
#         root.set('filename', self.filename)
#         root.set('duration', str(self.duration))
#         return root
# 
# class Video(object):
#     def __init__(self, filename, duration, width, height, fps, video_soundtrack_type):
#         self.filename = filename
#         self.duration = duration
#         self.width = width
#         self.height = height
#         self.fps = fps
#         self.video_soundtrack_type = video_soundtrack_type
# 
#     def __str__(self):
#         return "Video f:'{}' d:{}ms s:{}x{} f:{:.2f} t:{}".format(self.filename, self.duration, self.width, self.height,
#                                                                   self.fps, self.video_soundtrack_type)
# 
#     def xml(self, parent=None):
#         if parent is None:
#             root = ET.Element('Video')
#         else:
#             root = ET.SubElement(parent, 'Video')
#         if self.filename is not None:
#             root.set('filename', self.filename)
#         if self.duration is not None:
#             root.set('duration', str(self.duration))
#         if self.width is not None:
#             root.set('width', str(self.width))
#         if self.height is not None:
#             root.set('height', str(self.height))
#         if self.fps is not None:
#             root.set('fps', str(self.fps))
#         if self.video_soundtrack_type is not None:
#             root.set('soundtrackType', str(self.video_soundtrack_type))
#         return root
# 
# class VideoSoundtrackType(Enum):
#     __slots__ = ()
#     enum_values = dict(enumerate(['Music', 'Dialog', 'MusicAndDialog']))


from xnb_parse.type_reader import TypeReaderPlugin, BaseTypeReader
from xnb_parse.type_readers.xna_primitive import StringReader, Int32Reader, SingleReader
from xnb_parse.xna_types.xna_media import SoundEffect, Song, Video, VideoSoundtrackType
"""
media type readers
"""

from __future__ import print_function



class SoundEffectReader(BaseTypeReader, TypeReaderPlugin):
    target_type = 'Microsoft.Xna.Framework.Audio.SoundEffect'
    reader_name = 'Microsoft.Xna.Framework.Content.SoundEffectReader'

    def read(self):
        format_size = self.stream.read_int32()
        wave_format = self.stream.read(format_size)
        data_size = self.stream.read_int32()
        wave_data = self.stream.read(data_size)
        loop_start = self.stream.read_int32()
        loop_length = self.stream.read_int32()
        duration = self.stream.read_int32()

# Path: xnb_parse/type_reader.py
# class TypeReaderPlugin(Plugin):
#     """
#     type reader plugins
#     """
# 
# class BaseTypeReader(object):
#     target_type = None
#     reader_name = None
#     is_value_type = False
#     is_generic_type = False
#     is_enum_type = False
#     file_platform = None
#     file_version = None
# 
#     def __init__(self, stream=None, version=None):
#         self.stream = stream
#         self.version = version
# 
#     def __str__(self):
#         return self.reader_name
# 
#     def read(self):
#         raise ReaderError("Unimplemented type reader: '{}'".format(self.reader_name))
# 
#     def init_reader(self, file_platform=None, file_version=None):
#         self.file_platform = file_platform
#         self.file_version = file_version
# 
# Path: xnb_parse/type_readers/xna_primitive.py
# class StringReader(BaseTypeReader, TypeReaderPlugin):
#     target_type = 'System.String'
#     reader_name = 'Microsoft.Xna.Framework.Content.StringReader'
# 
#     def read(self):
#         return self.stream.read_string()
# 
# class Int32Reader(ValueTypeReader, TypeReaderPlugin):
#     target_type = 'System.Int32'
#     reader_name = 'Microsoft.Xna.Framework.Content.Int32Reader'
# 
#     def read(self):
#         return self.stream.read_int32()
# 
# class SingleReader(ValueTypeReader, TypeReaderPlugin):
#     target_type = 'System.Single'
#     reader_name = 'Microsoft.Xna.Framework.Content.SingleReader'
# 
#     def read(self):
#         return self.stream.read_single()
# 
# Path: xnb_parse/xna_types/xna_media.py
# class SoundEffect(object):
#     def __init__(self, sound_format, sound_data, loop_start, loop_length, duration, needs_swap=False):
#         self.sound_format = sound_format
#         self.sound_data = sound_data
#         self.loop_start = loop_start
#         self.loop_length = loop_length
#         self.duration = duration
#         self.needs_swap = needs_swap
# 
#     def __str__(self):
#         return "SoundEffect fs:{} ds:{} d:{}ms ls:{} ll:{}".format(len(self.sound_format), len(self.sound_data),
#                                                                    self.duration, self.loop_start, self.loop_length)
# 
#     def export(self, filename):
#         write_wav(filename, self.sound_format, self.sound_data, self.needs_swap)
# 
#     def xml(self, parent=None):
#         if parent is None:
#             root = ET.Element('SoundEffect')
#         else:
#             root = ET.SubElement(parent, 'SoundEffect')
#         root.set('loopStart', str(self.loop_start))
#         root.set('loopLength', str(self.loop_length))
#         root.set('duration', str(self.duration))
#         return root
# 
# class Song(object):
#     def __init__(self, filename, duration):
#         self.filename = filename
#         self.duration = duration
# 
#     def __str__(self):
#         return "Song f:'{}' d:{}ms".format(self.filename, self.duration)
# 
#     def xml(self, parent=None):
#         if parent is None:
#             root = ET.Element('Song')
#         else:
#             root = ET.SubElement(parent, 'Song')
#         root.set('filename', self.filename)
#         root.set('duration', str(self.duration))
#         return root
# 
# class Video(object):
#     def __init__(self, filename, duration, width, height, fps, video_soundtrack_type):
#         self.filename = filename
#         self.duration = duration
#         self.width = width
#         self.height = height
#         self.fps = fps
#         self.video_soundtrack_type = video_soundtrack_type
# 
#     def __str__(self):
#         return "Video f:'{}' d:{}ms s:{}x{} f:{:.2f} t:{}".format(self.filename, self.duration, self.width, self.height,
#                                                                   self.fps, self.video_soundtrack_type)
# 
#     def xml(self, parent=None):
#         if parent is None:
#             root = ET.Element('Video')
#         else:
#             root = ET.SubElement(parent, 'Video')
#         if self.filename is not None:
#             root.set('filename', self.filename)
#         if self.duration is not None:
#             root.set('duration', str(self.duration))
#         if self.width is not None:
#             root.set('width', str(self.width))
#         if self.height is not None:
#             root.set('height', str(self.height))
#         if self.fps is not None:
#             root.set('fps', str(self.fps))
#         if self.video_soundtrack_type is not None:
#             root.set('soundtrackType', str(self.video_soundtrack_type))
#         return root
# 
# class VideoSoundtrackType(Enum):
#     __slots__ = ()
#     enum_values = dict(enumerate(['Music', 'Dialog', 'MusicAndDialog']))


# Path: xnb_parse/type_readers/xna_media.py
from xnb_parse.type_reader import TypeReaderPlugin, BaseTypeReader
from xnb_parse.type_readers.xna_primitive import StringReader, Int32Reader, SingleReader
from xnb_parse.xna_types.xna_media import SoundEffect, Song, Video, VideoSoundtrackType

"""
media type readers
"""

from __future__ import print_function



class SoundEffectReader(BaseTypeReader, TypeReaderPlugin):
    target_type = 'Microsoft.Xna.Framework.Audio.SoundEffect'
    reader_name = 'Microsoft.Xna.Framework.Content.SoundEffectReader'

    def read(self):
        format_size = self.stream.read_int32()
        wave_format = self.stream.read(format_size)
        data_size = self.stream.read_int32()
        wave_data = self.stream.read(data_size)
        loop_start = self.stream.read_int32()
        loop_length = self.stream.read_int32()
        duration = self.stream.read_int32()

        return SoundEffect(wave_format, wave_data, loop_start, loop_length, duration, self.stream.needs_swap)