# Path: pylsdj/instrument.py
# class Instrument(object):
# 
#     def __init__(self, song, index):
#         self.song = song
#         self.data = song.song_data.instruments[index]
#         self.index = index
# 
#     def __eq__(self, other):
#         return (isinstance(other, Instrument) and
#                 self.name == other.name and
#                 self.type == other.type and
#                 self.table == other.table and
#                 self.automate == other.automate and
#                 self.pan == other.pan)
# 
#     @property
#     def name(self):
#         """the instrument's name (5 characters, zero-padded)"""
#         instr_name = self.song.song_data.instrument_names[self.index]
# 
#         if type(instr_name) == bytes:
#             instr_name = instr_name.decode('utf-8')
# 
#         return instr_name
# 
#     @name.setter
#     def name(self, val):
#         if type(val) != bytes:
#             val = val.encode('utf-8')
# 
#         self.song.song_data.instrument_names[self.index] = val
# 
#     @property
#     def type(self):
#         """the instrument's type (``pulse``, ``wave``, ``kit`` or ``noise``)"""
#         return self.data.instrument_type
# 
#     @type.setter
#     def type(self, value):
#         self.data.instrument_type = value
# 
#     @property
#     def table(self):
#         """a ```pylsdj.Table``` referencing the instrument's table, or None
#         if the instrument doesn't have a table"""
#         if hasattr(self.data, 'table_on') and self.data.table_on:
#             assert_index_sane(self.data.table, len(self.song.tables))
#             return self.song.tables[self.data.table]
# 
#     @table.setter
#     def table(self, value):
#         if not hasattr(self.data, "table_on"):
#             raise ValueError("This instrument doesn't have a table")
# 
#         self.data.table_on = True
#         self.data.table = value.index
# 
#     @property
#     def automate(self):
#         """if True, automation is on"""
#         return self.data.automate
# 
#     @automate.setter
#     def automate(self, value):
#         self.data.automate = value
# 
#     @property
#     def pan(self):
#         return self.data.pan
# 
#     @pan.setter
#     def pan(self, value):
#         self.data.pan = value
# 
#     def import_lsdinst(self, struct_data):
#         """import from an lsdinst struct"""
#         self.name = struct_data['name']
#         self.automate = struct_data['data']['automate']
#         self.pan = struct_data['data']['pan']
# 
#         if self.table is not None:
#             self.table.import_lsdinst(struct_data)
# 
#     def export_to_file(self, filename):
#         """Export this instrument's settings to a file.
# 
#         :param filename: the name of the file
#         """
#         instr_json = self.export_struct()
# 
#         with open(filename, 'w') as fp:
#             json.dump(instr_json, fp, indent=2)
# 
#     def export_struct(self):
#         export_struct = {}
# 
#         export_struct['name'] = self.name
#         export_struct['data'] = {}
# 
#         data_json = json.loads(self.data.as_json())
# 
#         for key, value in list(data_json.items()):
#             if key[0] != '_' and key not in ('synth', 'table'):
#                 export_struct['data'][key] = value
# 
#         if self.table is not None:
#             export_struct['table'] = self.table.export()
# 
#         return export_struct
# 
# Path: pylsdj/instrument_mixins.py
# class VibratoMixin(object):
# 
#     @property
#     def vibrato(self):
#         """instrument's vibrato settings"""
#         return Vibrato(self.data.vibrato)
# 
#     @staticmethod
#     def import_lsdinst(obj, struct_data):
#         Vibrato(obj.data.vibrato).import_lsdinst(struct_data)
# 
#     @staticmethod
#     def equal(a, b):
#         return (isinstance(a, VibratoMixin) and isinstance(b, VibratoMixin)
#                 and a.vibrato == b.vibrato)


from .instrument import Instrument
from .instrument_mixins import VibratoMixin

    @property
    def half_speed(self):
        """if true, play samples at half their normal speed"""
        return self.data.half_speed

    @half_speed.setter
    def half_speed(self, value):
        self.data.half_speed = value

    def import_lsdinst(self, lsdinst_struct):
        super(KitInstrument, self).import_lsdinst(lsdinst_struct)

        self.volume = lsdinst_struct['data']['volume']

        self.kit_1 = lsdinst_struct['data']['kit_1']
        self.loop_1 = lsdinst_struct['data']['loop_1']
        self.keep_attack_1 = lsdinst_struct['data']['keep_attack_1']
        self.length_1 = lsdinst_struct['data']['length_1']
        self.offset_1 = lsdinst_struct['data']['offset_1']

        self.kit_2 = lsdinst_struct['data']['kit_2']
        self.loop_2 = lsdinst_struct['data']['loop_2']
        self.keep_attack_2 = lsdinst_struct['data']['keep_attack_2']
        self.length_2 = lsdinst_struct['data']['length_2']
        self.offset_2 = lsdinst_struct['data']['offset_2']

        self.pitch = lsdinst_struct['data']['pitch']
        self.dist_type = lsdinst_struct['data']['dist_type']


# Path: pylsdj/instrument.py
# class Instrument(object):
# 
#     def __init__(self, song, index):
#         self.song = song
#         self.data = song.song_data.instruments[index]
#         self.index = index
# 
#     def __eq__(self, other):
#         return (isinstance(other, Instrument) and
#                 self.name == other.name and
#                 self.type == other.type and
#                 self.table == other.table and
#                 self.automate == other.automate and
#                 self.pan == other.pan)
# 
#     @property
#     def name(self):
#         """the instrument's name (5 characters, zero-padded)"""
#         instr_name = self.song.song_data.instrument_names[self.index]
# 
#         if type(instr_name) == bytes:
#             instr_name = instr_name.decode('utf-8')
# 
#         return instr_name
# 
#     @name.setter
#     def name(self, val):
#         if type(val) != bytes:
#             val = val.encode('utf-8')
# 
#         self.song.song_data.instrument_names[self.index] = val
# 
#     @property
#     def type(self):
#         """the instrument's type (``pulse``, ``wave``, ``kit`` or ``noise``)"""
#         return self.data.instrument_type
# 
#     @type.setter
#     def type(self, value):
#         self.data.instrument_type = value
# 
#     @property
#     def table(self):
#         """a ```pylsdj.Table``` referencing the instrument's table, or None
#         if the instrument doesn't have a table"""
#         if hasattr(self.data, 'table_on') and self.data.table_on:
#             assert_index_sane(self.data.table, len(self.song.tables))
#             return self.song.tables[self.data.table]
# 
#     @table.setter
#     def table(self, value):
#         if not hasattr(self.data, "table_on"):
#             raise ValueError("This instrument doesn't have a table")
# 
#         self.data.table_on = True
#         self.data.table = value.index
# 
#     @property
#     def automate(self):
#         """if True, automation is on"""
#         return self.data.automate
# 
#     @automate.setter
#     def automate(self, value):
#         self.data.automate = value
# 
#     @property
#     def pan(self):
#         return self.data.pan
# 
#     @pan.setter
#     def pan(self, value):
#         self.data.pan = value
# 
#     def import_lsdinst(self, struct_data):
#         """import from an lsdinst struct"""
#         self.name = struct_data['name']
#         self.automate = struct_data['data']['automate']
#         self.pan = struct_data['data']['pan']
# 
#         if self.table is not None:
#             self.table.import_lsdinst(struct_data)
# 
#     def export_to_file(self, filename):
#         """Export this instrument's settings to a file.
# 
#         :param filename: the name of the file
#         """
#         instr_json = self.export_struct()
# 
#         with open(filename, 'w') as fp:
#             json.dump(instr_json, fp, indent=2)
# 
#     def export_struct(self):
#         export_struct = {}
# 
#         export_struct['name'] = self.name
#         export_struct['data'] = {}
# 
#         data_json = json.loads(self.data.as_json())
# 
#         for key, value in list(data_json.items()):
#             if key[0] != '_' and key not in ('synth', 'table'):
#                 export_struct['data'][key] = value
# 
#         if self.table is not None:
#             export_struct['table'] = self.table.export()
# 
#         return export_struct
# 
# Path: pylsdj/instrument_mixins.py
# class VibratoMixin(object):
# 
#     @property
#     def vibrato(self):
#         """instrument's vibrato settings"""
#         return Vibrato(self.data.vibrato)
# 
#     @staticmethod
#     def import_lsdinst(obj, struct_data):
#         Vibrato(obj.data.vibrato).import_lsdinst(struct_data)
# 
#     @staticmethod
#     def equal(a, b):
#         return (isinstance(a, VibratoMixin) and isinstance(b, VibratoMixin)
#                 and a.vibrato == b.vibrato)


# Path: pylsdj/kit_instrument.py
from .instrument import Instrument
from .instrument_mixins import VibratoMixin


    @property
    def half_speed(self):
        """if true, play samples at half their normal speed"""
        return self.data.half_speed

    @half_speed.setter
    def half_speed(self, value):
        self.data.half_speed = value

    def import_lsdinst(self, lsdinst_struct):
        super(KitInstrument, self).import_lsdinst(lsdinst_struct)

        self.volume = lsdinst_struct['data']['volume']

        self.kit_1 = lsdinst_struct['data']['kit_1']
        self.loop_1 = lsdinst_struct['data']['loop_1']
        self.keep_attack_1 = lsdinst_struct['data']['keep_attack_1']
        self.length_1 = lsdinst_struct['data']['length_1']
        self.offset_1 = lsdinst_struct['data']['offset_1']

        self.kit_2 = lsdinst_struct['data']['kit_2']
        self.loop_2 = lsdinst_struct['data']['loop_2']
        self.keep_attack_2 = lsdinst_struct['data']['keep_attack_2']
        self.length_2 = lsdinst_struct['data']['length_2']
        self.offset_2 = lsdinst_struct['data']['offset_2']

        self.pitch = lsdinst_struct['data']['pitch']
        self.dist_type = lsdinst_struct['data']['dist_type']


        VibratoMixin.import_lsdinst(self, lsdinst_struct)