Convert and return the paraters as a MIDI event in bytes.
325668
def midi_event(self, event_type, channel, param1, param2=None):
        """"""
        assert event_type < 0x80 and event_type >= 0
        assert channel < 16 and channel >= 0
        tc = a2b_hex('%x%x' % (event_type, channel))
        if param2 is None:
            params = a2b_hex('%02x' % param1)
        else:
            params = a2b_hex('%02x%02x' % (param1, param2))
        return self.delta_time + tc + params
974716
def mp3(self, sha, **kwargs):
        """"""
        return self._queue_msg({'cmd': cmd.CMD_MESSAGE_MP3,
                                'sha': _get_bytes(sha)}, **kwargs)
801273
def decode(in_bytes):
    """"""
    out_bytes = []
    idx = 0

    if len(in_bytes) > 0:
        while True:
            length = ord(in_bytes[idx])
            if length == 0:
                raise DecodeError("zero byte found in input")
            idx += 1
            end = idx + length - 1
            copy_bytes = in_bytes[idx:end]
            if '\x00' in copy_bytes:
                raise DecodeError("zero byte found in input")
            out_bytes.append(copy_bytes)
            idx = end
            if idx > len(in_bytes):
                raise DecodeError("not enough input bytes for length code")
            if idx < len(in_bytes):
                if length < 0xFF:
                    out_bytes.append('\x00')
            else:
                break
    return ''.join(out_bytes)
887916
def main(source_samplerate, target_samplerate, params, converter_type):
    """"""
    from time import sleep

    ratio = target_samplerate / source_samplerate

    with sr.CallbackResampler(get_input_callback(source_samplerate, params),
                              ratio, converter_type) as resampler, \
            sd.OutputStream(channels=1, samplerate=target_samplerate,
                            callback=get_playback_callback(
                                resampler, target_samplerate, params)):
        print("Playing back...  Ctrl+C to stop.")
        try:
            while True:
                sleep(1)
        except KeyboardInterrupt:
            print("Aborting.")
1202270
def decode_array(input_array):
    """"""
    codec, length, param, input_array = parse_header(input_array)
    return codec_dict[codec].decode(input_array, param)
1300968
def get_midi_data(self):
        """"""
        tracks = [t.get_midi_data() for t in self.tracks if t.track_data != '']
        return self.header() + ''.join(tracks)
1223045
def convert_ints_to_bytes(in_ints, num):
    """"""
    out_bytes= b""
    for val in in_ints:
        out_bytes+=struct.pack(mmtf.utils.constants.NUM_DICT[num], val)
    return out_bytes
901597
def note_off(self, channel, note, velocity):
        """"""
        return self.midi_event(NOTE_OFF, channel, note, velocity)
983644
def controller_event(self, channel, contr_nr, contr_val):
        """"""
        return self.midi_event(CONTROLLER, channel, contr_nr, contr_val)
1032934
def cast_str(s, encoding='utf8', errors='strict'):
    """"""
    if isinstance(s, bytes):
        return s.decode(encoding, errors)
    elif isinstance(s, str):
        return s
    else:
        raise TypeError("Expected unicode or bytes, got %r" % s)
161393
def strtobytes(input, encoding):
    """"""
    py_version = sys.version_info[0]
    if py_version >= 3:
        return _strtobytes_py3(input, encoding)
    return _strtobytes_py2(input, encoding)
690665
def bt_addr_to_string(addr):
    """"""
    addr_str = array.array('B', addr)
    addr_str.reverse()
    hex_str = hexlify(addr_str.tostring()).decode('ascii')
    # insert ":" seperator between the bytes
    return ':'.join(a+b for a, b in zip(hex_str[::2], hex_str[1::2]))
183577
def from_bytes(rawbytes):
        '''
        
        '''
        icmpv6popts = ICMPv6OptionList()

        i = 0
        while i < len(rawbytes):
            opttype = rawbytes[i]
            optnum = ICMPv6OptionNumber(opttype)
            obj = ICMPv6OptionClasses[optnum]()
            eaten = obj.from_bytes(rawbytes[i:])
            i += eaten
            icmpv6popts.append(obj)
        return icmpv6popts
678023
def to_bytes(s):
    
    if sys.version_info < (3,):
        return "".join(map(chr, s))
    else:
        return bytes(s)
1063902
def convert_bytes(bytes_, K=1 << 10, M=1 << 20, G=1 << 30, T=1 << 40):
    """"""
    fn = float(bytes_)
    if bytes_ >= T:
        return '%.1fT' % (fn / T)
    elif bytes_ >= G:
        return '%.1fG' % (fn / G)
    elif bytes_ >= M:
        return '%.1fM' % (fn / M)
    elif bytes_ >= K:
        return '%.1fK' % (fn / K)
    else:
        return '%d' % bytes_
444650
def to_string(x):
    
    if isinstance(x, bytes):
        return x.decode('utf-8')
    if isinstance(x, basestring):
        return x
1306822
Rule MidiProgramNumber() {
		return FirstOf(
			CharRange('1', '9'),
			Sequence(CharRange('1', '9'), CharRange('0', '9')),
			Sequence('1', CharRange('0', '1'), CharRange('0', '9')),
			Sequence("12", CharRange('0', '8'))
		).label(MidiProgramNumber).suppressSubnodes();
	}