<reponame>PGkids/pyMidiate<gh_stars>1-10
# -*- coding: utf-8 -*-
#  This file is part of pymidiate.

#############################################################
##             pymidiate / midiate.zoom.g1on               ##
## Copyright (C) 2019 PGkids Laboratory <<EMAIL>> ##
#############################################################

import collections

# ５エフェクトを使い全てがバイパス状態のパッチデータ
# 本ライブラリでは、これをプロトタイプとして使う
# パッチのボリュームレベルは 220,221のポジションである
# パッチネームの開始は242から終端F7ターミネータまで、４文字と６文字のヌル終端文字列で表す
# 長さは268 (134bytes)
init5 = b'F0520063280001000000000000000000000000000000000000000100000000000000000000000000000000000000000100000000000000000000000000000000000000010000000000000000000000000000000000000000010000000000000000000000000100000000000020006401000000200300000000202020200020202020202000F7'

# p1..p5は第一エフェクトから第５エフェクトまでそれぞれ１００種類のエフェクトの初期パタンである。

# 10-42
p1 = (b'000100000000000000000000000000000',
      b'081100000201300000640000000000000',
      b'0A6100004201300100320000000000000',
      b'0A6B000002097000100600000C0000000',
      b'400100000205500000640000000000000',
      b'402100004202080000640000000000000',
      b'404100004202200300000000000000000',
      b'00210000040360003C0C000101010C000',
      b'00410000040208002C0C602100010C000',
      b'006100000400000000640000000000000',
      b'402100004404400000640000000000000',
      b'48610000040140003010000C0C0000000',
      b'00210100040E28000607402000000C0C0',
      b'02410100040F4800100840010C0000000',
      b'086101000401300008194041010C00000',
      b'4A0101000408100104064020400B0C000',
      b'40210100440118002064000C010000000',
      b'021100000614100100640000000000000',
      b'02210000060F100100640000000000000',
      b'0A4100000611100100640000000000000',
      b'02610000060F100100640000000000000',
      b'420100000614100100640000000000000',
      b'42210000060F100100640000000000000',
      b'42410000060A100100640000000000000',
      b'4A6100000611100100640000000000000',
      b'0A0101000611100100640000000000000',
      b'02210100060F100100640000000000000',
      b'02410100060F100100640000000000000',
      b'02610100060F100100640000000000000',
      b'42010100060F100100640000000000000',
      b'42610100060F100100640000000000000',
      b'02210200060F100100640000000000000',
      b'02410200060F100100640000000000000',
      b'02610200060F100100640000000000000',
      b'420102000614100100640000000000000',
      b'02110000080670001C560026050506012',
      b'0A210000080C700000644046464606022',
      b'02410000080E70002C624046660506042',
      b'0A610000480E7000206B4045064607062',
      b'4A0100004807700024640045262606082',
      b'4A210000080C7000006440464646060A2',
      b'42410000480E7000046340464606070C2',
      b'42610000080770003C6440452525060E2',
      b'0A010100480C7000004A4046464606102',
      b'02210100480D7000005F4046664606122',
      b'0A410100081370002C594046460506142',
      b'0A610100080D7000246A4045060706162',
      b'4A0101000811700028630046264506182',
      b'42210100480F7800086440460666061A2',
      b'42410100081270002C6240452646061C2',
      b'4A610100080E7000006440464646061E2',
      b'0A0102000814700024672045062706202',
      b'0221020008157000205B0046264606222',
      b'0A410200480B700008610046060606242',
      b'02610200480B7000345D2066656606262',
      b'4A010200080F70002C570046064506282',
      b'4221020008107000005940466666062A2',
      b'001100000C14080160022002000000000',
      b'024100000C00400020640042100000000',
      b'086100004C02180000640000000000000',
      b'086B00000C0B280016640040000044070',
      b'020102000C0A7000204860000F0000000',
      b'420100004C06600108300023000C00000',
      b'080101004C080000103400010C0000000',
      b'426100000C0A4000303260000C0000000',
      b'024101000C146800303C60000C0000000',
      b'026101000C0A6800103C00010C0000000',
      b'4A2101000C0C100100324006000000000',
      b'000104004C0620032064002C000000000',
      b'484101004C0B380028120020080C00000',
      b'483101004C0B380028120020080C00000',
      b'002102000C1478002864000C010C00000',
      b'084102004C043800102820030C0000000',
      b'006102000C003000103220030C0000000',
      b'480102000C010000304640000C0000000',
      b'422102000C0A100108640000010C00000',
      b'486102004C0650000032000F000000000',
      b'484100000E0C000020640002000000000',
      b'002100004E011000105A00010C0000000',
      b'0A4100004E0008011C0F004503000C000',
      b'4A0100000E11000208506000010C00000',
      b'0E110000500B700008464001000C00000',
      b'486101005060780118452060030300000',
      b'4A0101001007200004670100002000000',
      b'0C210000500B0002303820000C0000000',
      b'4E01000010772000103200010C0000000',
      b'4C210000506D0A00101440010C0000000',
      b'4A610000507C1001345A40000C010C000',
      b'02010100501628000850000A010C00000',
      b'022101001029400F3E646026040C0C0C0',
      b'0011000012146801103E0044080000000',
      b'0021000052022800102E00060C0000000',
      b'0041000052024000303C00000C0000000',
      b'0861000052042000102E20010C0000000',
      b'48210000120338001038200B0C0000000',
      b'02210100120220010A2C40276C0B000C0',
      b'4A01010052081801203A000C000000000',
      b'4861000052044000303C20000C0000000',
      b'4A41000012032000303240000C0000000',
      b'0A410100120918001C2D604220030C000',
      b'00210300120A200320000007000000000')

# 43-83
p2 = (b'00000000001000000000000000000000000000000',
      b'00000000011000040020130006400000000000000',
    b'00000000061000050420130013200000000000000',
    b'0000000006B00005102097000060000000C000000',
    b'40000000001000000020550006400000000000000',
    b'40000000021000000420208006400000000000000',
    b'40000000041000000420220030000000000000000',
    b'00000000021000003040360000C00016001010C00',
    b'00000000041000002040208000C60216000010C00',
    b'00000000061000000040000006400000000000000',
    b'40000000021000000440440006400000000000000',
    b'400000000610000430401400010000C000C000000',
    b'00000000021010000040E28000740203000000C0C',
    b'00000000041010011040F4800084001000C000000',
    b'000000000610100400401300019404140010C0000',
    b'400000000010100500408100106402020400B0C00',
    b'400000000210100024401180064000C0001000000',
    b'00000000011000010061410016400000000000000',
    b'00000000021000010060F10016400000000000000',
    b'00000000041000050061110016400000000000000',
    b'00000000061000010060F10016400000000000000',
    b'40000000001000010061410016400000000000000',
    b'40000000021000010060F10016400000000000000',
    b'40000000041000010060A10016400000000000000',
    b'40000000061000050061110016400000000000000',
    b'00000000001010050061110016400000000000000',
    b'00000000021010010060F10016400000000000000',
    b'00000000041010010060F10016400000000000000',
    b'00000000061010010060F10016400000000000000',
    b'40000000001010010060F10016400000000000000',
    b'40000000061010010060F10016400000000000000',
    b'00000000021020010060F10016400000000000000',
    b'00000000041020010060F10016400000000000000',
    b'00000000061020010060F10016400000000000000',
    b'40000000001020010061410016400000000000000',
    b'00000000011000011080670005600266205050601',
    b'00000000021000050080C70006440460246460602',
    b'00000000041000012080E70006240466266050604',
    b'00000000061000052480E70006B40450206460706',
    b'40000000001000052480770006400452226260608',
    b'40000000021000050080C7000644046024646060A',
    b'40000000041000010480E7000634046224606070C',
    b'4000000006100001308077000644045622525060E',
    b'00000000001010050480C70004A40460246460610',
    b'00000000021010010480D70005F40460266460612',
    b'00000000041010052081370005940466246050614',
    b'00000000061010052080D70006A40452206070616',
    b'40000000001010052081170006300464226450618',
    b'40000000021010010480F7800644046420666061A',
    b'4000000004101001208127000624045622646061C',
    b'40000000061010050080E7000644046024646061E',
    b'00000000001020052081470006720452206270620',
    b'00000000021020012081570005B00460226460622',
    b'00000000041020050480B70006100464206060624',
    b'00000000061020013480B70005D20662265660626',
    b'40000000001020052080F70005700466206450628',
    b'4000000002102001008107000594046026666062A',
    b'000000000110000060C1408010220020000000000',
    b'000000000410000120C0040006400420010000000',
    b'000000000610000404C0218006400000000000000',
    b'0000000006B0000410C0B28006400403000004407',
    b'000000000010200120C0A7000486000000F000000',
    b'400000000010000104C06600130002340000C0000',
    b'000000000010100414C080000340001000C000000',
    b'400000000610000130C0A4000326000000C000000',
    b'000000000410100130C1468003C6000000C000000',
    b'000000000610100110C0A68003C0001000C000000',
    b'400000000210100500C0C10013240060000000000',
    b'000000000010400024C06200364002C0000000000',
    b'400000000410100424C0B380012002040080C0000',
    b'400000000310100424C0B380012002040080C0000',
    b'000000000210200020C14780064000C40010C0000',
    b'000000000410200414C043800282003000C000000',
    b'000000000610200010C003000322003000C000000',
    b'400000000010200430C010000464000000C000000',
    b'400000000210200100C0A100164000040010C0000',
    b'400000000610200404C06500032000F0000000000',
    b'400000000410000420E0C00006400020000000000',
    b'000000000210000014E0110005A0001000C000000',
    b'000000000410000514E0008010F00456003000C00',
    b'400000000010000500E11000250600040010C0000',
    b'00000000011000070500B700046400140000C0000',
    b'40000000061010041506078014520604003030000',
    b'40000000001010050100720006701002000200000',
    b'00000000021000063500B0002382000000C000000',
    b'4000000000100007110772000320001000C000000',
    b'40000000021000061506D0A00144001000C000000',
    b'40000000061000053507C10015A4000200C010C00',
    b'000000000010100105016280050000A40010C0000',
    b'000000000210100131029400F64602670040C0C0C',
    b'00000000011000001121468013E00440008000000',
    b'00000000021000001520228002E0006000C000000',
    b'00000000041000003520240003C0000000C000000',
    b'00000000061000041520420002E2001000C000000',
    b'400000000210000411203380038200B000C000000',
    b'00000000021010010120220012C4027506C0B000C',
    b'40000000001010052520818013A000C0000000000',
    b'40000000061000043520440003C2000000C000000',
    b'4000000004100005312032000324000000C000000',
    b'00000000041010051120918002D60426020030C00',
    b'00000000021030002120A20030000070000000000')

# 90 - 125
p3 = (b'000001000000000000000000000000000000',
      b'040011000002013000006400000000000000',
    b'050061000042013000013200000000000000',
    b'05006B000002097008000600000C00000000',
    b'200001000002055000006400000000000000',
    b'200021000042020800006400000000000000',
    b'200041000042022000030000000000000000',
    b'00002100000403601E000C000101010C0000',
    b'000041000004020816000C602100010C0000',
    b'000061000004000000006400000000000000',
    b'200021000044044000006400000000000000',
    b'2400610000040140180010000C0C00000000',
    b'0000210100040E28030007402000000C000C',
    b'0100410100040F4808000840010C00000000',
    b'04006101000401300400194041010C000000',
    b'25000101000408100201064020400B0C0000',
    b'2000210100440118100064000C0100000000',
    b'010011000006141000016400000000000000',
    b'0100210000060F1000016400000000000000',
    b'050041000006111000016400000000000000',
    b'0100610000060F1000016400000000000000',
    b'210001000006141000016400000000000000',
    b'2100210000060F1000016400000000000000',
    b'2100410000060A1000016400000000000000',
    b'250061000006111000016400000000000000',
    b'050001010006111000016400000000000000',
    b'0100210100060F1000016400000000000000',
    b'0100410100060F1000016400000000000000',
    b'0100610100060F1000016400000000000000',
    b'2100010100060F1000016400000000000000',
    b'2100610100060F1000016400000000000000',
    b'0100210200060F1000016400000000000000',
    b'0100410200060F1000016400000000000000',
    b'0100610200060F1000016400000000000000',
    b'210001020006141000016400000000000000',
    b'01001100000806700E005600260505061001',
    b'0500210000080C7000006440464646061002',
    b'0100410000080E7016006240466605061004',
    b'0500610000480E7010006B40450646071006',
    b'250001000048077012006400452626061008',
    b'2500210000080C700000644046464606100A',
    b'2100410000480E700200634046460607100C',
    b'21006100000807701E00644045252506100E',
    b'0500010100480C7000004A40464646061010',
    b'0100210100480D7000005F40466646061012',
    b'050041010008137016005940464605061014',
    b'0500610100080D7012006A40450607061016',
    b'250001010008117014006300462645061018',
    b'2100210100480F780400644046066606101A',
    b'21004101000812701600624045264606101C',
    b'2500610100080E700000644046464606101E',
    b'050001020008147012006720450627061020',
    b'010021020008157010005B00462646061022',
    b'0500410200480B7004006100460606061024',
    b'0100610200480B701A005D20666566061026',
    b'2500010200080F7016005700460645061028',
    b'21002102000810700000594046666606102A',
    b'00001100000C140830010220020000000000',
    b'01004100000C004010006400421000000000',
    b'04006100004C021800006400000000000000',
    b'04006B00000C0B280B006400400000440007',
    b'01000102000C0A7010004860000F00000000',
    b'21000100004C06600401300023000C000000',
    b'04000101004C080008003400010C00000000',
    b'21006100000C0A4018003260000C00000000',
    b'01004101000C146818003C60000C00000000',
    b'01006101000C0A6808003C00010C00000000',
    b'25002101000C0C1000013240060000000000',
    b'00000104004C0620100364002C0000000000',
    b'24004101004C0B381400120020080C000000',
    b'24003101004C0B381400120020080C000000',
    b'00002102000C1478140064000C010C000000',
    b'04004102004C043808002820030C00000000',
    b'00006102000C003008003220030C00000000',
    b'24000102000C010018004640000C00000000',
    b'21002102000C0A100401640000010C000000',
    b'24006102004C0650000032000F0000000000',
    b'24004100000E0C0010006400020000000000',
    b'00002100004E011008005A00010C00000000',
    b'05004100004E00080E010F004503000C0000',
    b'25000100000E11000402506000010C000000',
    b'0700110000500B700400464001000C000000',
    b'24006101005060780C014520600303000000',
    b'250001010010072002006701000020000000',
    b'0600210000500B0018023820000C00000000',
    b'270001000010772008003200010C00000000',
    b'2600210000506D0A08001440010C00000000',
    b'2500610000507C101A015A40000C010C0000',
    b'0100010100501628040050000A010C000000',
    b'01002101001029401F0F646026040C0C000C',
    b'000011000012146808013E00440800000000',
    b'000021000052022808002E00060C00000000',
    b'000041000052024018003C00000C00000000',
    b'040061000052042008002E20010C00000000',
    b'2400210000120338080038200B0C00000000',
    b'010021010012022005012C40276C0B00000C',
    b'250001010052081810013A000C0000000000',
    b'240061000052044018003C20000C00000000',
    b'250041000012032018003240000C00000000',
    b'05004101001209180E002D604220030C0000',
    b'0000210300120A2010030000070000000000')

# 123 - 165
p4 = (b'0000000000001000000000000000000000000000000',
      b'0000000000011002000020130006400000000000000',
     b'0000000000061002800420130013200000000000000',
     b'000000000006B00280002097000060040000C000000',
     b'2000000000001000000020550006400000000000000',
     b'2000000000021000000420208006400000000000000',
     b'2000000000041000000420220030000000000000000',
     b'0000000000021000100040360000C00700101010C00',
     b'0000000000041000100040208000C60302100010C00',
     b'0000000000061000000040000006400000000000000',
     b'2000000000021000000440440006400000000000000',
     b'2000000000061002100040140001000400C0C000000',
     b'0000000000021010000040E28000740182000000C0C',
     b'0000000000041010800040F4800084040010C000000',
     b'00000000000610120000401300019402041010C0000',
     b'20000000000010128000408100106401020400B0C00',
     b'2000000000021010100440118006400000C01000000',
     b'0000000000011000800061410016400000000000000',
     b'0000000000021000800060F10016400000000000000',
     b'0000000000041002800061110016400000000000000',
     b'0000000000061000800060F10016400000000000000',
     b'2000000000001000800061410016400000000000000',
     b'2000000000021000800060F10016400000000000000',
     b'2000000000041000800060A10016400000000000000',
     b'2000000000061002800061110016400000000000000',
     b'0000000000001012800061110016400000000000000',
     b'0000000000021010800060F10016400000000000000',
     b'0000000000041010800060F10016400000000000000',
     b'0000000000061010800060F10016400000000000000',
     b'2000000000001010800060F10016400000000000000',
     b'2000000000061010800060F10016400000000000000',
     b'0000000000021020800060F10016400000000000000',
     b'0000000000041020800060F10016400000000000000',
     b'0000000000061020800060F10016400000000000000',
     b'2000000000001020800061410016400000000000000',
     b'0000000000011000800080670005600712605050601',
     b'0000000000021002800080C70006440014646460602',
     b'0000000000041000900080E70006240314666050604',
     b'0000000000061002900480E70006B40014506460706',
     b'2000000000001002900480770006400114526260608',
     b'2000000000021002800080C7000644001464646060A',
     b'2000000000041000800480E7000634011464606070C',
     b'200000000006100090008077000644071452525060E',
     b'0000000000001012800480C70004A40014646460610',
     b'0000000000021010800480D70005F40014666460612',
     b'0000000000041012900081370005940314646050614',
     b'0000000000061012900080D70006A40114506070616',
     b'2000000000001012900081170006300214626450618',
     b'2000000000021010800480F7800644021460666061A',
     b'200000000004101090008127000624031452646061C',
     b'2000000000061012800080E7000644001464646061E',
     b'0000000000001022900081470006720114506270620',
     b'0000000000021020900081570005B00014626460622',
     b'0000000000041022800480B70006100214606060624',
     b'0000000000061020900480B70005D20516665660626',
     b'2000000000001022900080F70005700314606450628',
     b'200000000002102080008107000594001466666062A',
     b'00000000000110003000C1408010220000200000000',
     b'00000000000410009000C0040006400004210000000',
     b'00000000000610020004C0218006400000000000000',
     b'000000000006B0020000C0B28006400584000004407',
     b'00000000000010209000C0A7000486000000F000000',
     b'20000000000010008004C06600130002023000C0000',
     b'00000000000010120004C080000340040010C000000',
     b'20000000000610009000C0A4000326040000C000000',
     b'00000000000410109000C1468003C6040000C000000',
     b'00000000000610108000C0A68003C0040010C000000',
     b'20000000000210128000C0C10013240000600000000',
     b'00000000000010401004C0620036400002C00000000',
     b'20000000000410121004C0B380012002020080C0000',
     b'20000000000310121004C0B380012002020080C0000',
     b'00000000000210201000C1478006400200C010C0000',
     b'00000000000410220004C043800282040030C000000',
     b'00000000000610200000C003000322040030C000000',
     b'20000000000010221000C010000464040000C000000',
     b'20000000000210208000C0A100164002000010C0000',
     b'20000000000610220004C0650003200000F00000000',
     b'20000000000410021000E0C00006400000200000000',
     b'00000000000210000004E0110005A0040010C000000',
     b'00000000000410028004E0008010F00704503000C00',
     b'20000000000010028000E11000250602000010C0000',
     b'0000000000011003800500B700046402001000C0000',
     b'2000000000061012000506078014520606003030000',
     b'2000000000001012800100720006701100000200000',
     b'0000000000021003100500B0002382040000C000000',
     b'200000000000100380010772000320040010C000000',
     b'2000000000021003000506D0A00144040010C000000',
     b'2000000000061002900507C10015A4050000C010C00',
     b'0000000000001010800501628005000200A010C0000',
     b'00000000000210109001029400F64607826040C0C0C',
     b'0000000000011000000121468013E00404408000000',
     b'0000000000021000000520228002E0040060C000000',
     b'0000000000041000100520240003C0040000C000000',
     b'0000000000061002000520420002E2040010C000000',
     b'2000000000021002000120338003820400B0C000000',
     b'0000000000021010800120220012C4028276C0B000C',
     b'2000000000001012900520818013A00000C00000000',
     b'2000000000061002100520440003C2040000C000000',
     b'200000000004100290012032000324040000C000000',
     b'0000000000041012800120918002D60704220030C00',
     b'0000000000021030100120A20030000000700000000')

# 170-207
p5 = (b'00000001000000000000000000000000010000',
      b'02000011000002010030006400000000010000',
    b'02000061000042014030013200000000010000',
    b'0200006B000002094470000600000C00010000',
    b'10000001000002050050006400000000010000',
    b'10000021000042020008006400000000010000',
    b'10000041000042020020030000000000010000',
    b'00000021000004030F60000C00010101010C00',
    b'00000041000004020B08000C60210001010C00',
    b'00000061000004000000006400000000010000',
    b'10000021000044040040006400000000010000',
    b'12000061000004010C400010000C0C00010000',
    b'000000210100040E0128000740200000410C0C',
    b'000000410100040F4448000840010C00010000',
    b'0200006101000401023000194041010C010000',
    b'1200000101000408411001064020400B010C00',
    b'100000210100440108180064000C0100010000',
    b'00000011000006144010016400000000010000',
    b'000000210000060F4010016400000000010000',
    b'02000041000006114010016400000000010000',
    b'000000610000060F4010016400000000010000',
    b'10000001000006144010016400000000010000',
    b'100000210000060F4010016400000000010000',
    b'100000410000060A4010016400000000010000',
    b'12000061000006114010016400000000010000',
    b'02000001010006114010016400000000010000',
    b'000000210100060F4010016400000000010000',
    b'000000410100060F4010016400000000010000',
    b'000000610100060F4010016400000000010000',
    b'100000010100060F4010016400000000010000',
    b'100000610100060F4010016400000000010000',
    b'000000210200060F4010016400000000010000',
    b'000000410200060F4010016400000000010000',
    b'000000610200060F4010016400000000010000',
    b'10000001020006144010016400000000010000',
    b'00000011000008064770005600260505090601',
    b'020000210000080C4070006440464646090602',
    b'000000410000080E4B70006240466605090604',
    b'020000610000480E4870006B40450646090706',
    b'12000001000048074970006400452626090608',
    b'120000210000080C407000644046464609060A',
    b'100000410000480E417000634046460609070C',
    b'10000061000008074F7000644045252509060E',
    b'020000010100480C4070004A40464646090610',
    b'000000210100480D4070005F40466646090612',
    b'02000041010008134B70005940464605090614',
    b'020000610100080D4970006A40450607090616',
    b'12000001010008114A70006300462645090618',
    b'100000210100480F427800644046066609061A',
    b'10000041010008124B7000624045264609061C',
    b'120000610100080E407000644046464609061E',
    b'02000001020008144970006720450627090620',
    b'00000021020008154870005B00462646090622',
    b'020000410200480B4270006100460606090624',
    b'000000610200480B4D70005D20666566090626',
    b'120000010200080F4B70005700460645090628',
    b'1000002102000810407000594046666609062A',
    b'0000001100000C141808010220020000010000',
    b'0000004100000C004840006400421000010000',
    b'0200006100004C020018006400000000010000',
    b'0200006B00000C0B0528006400400000414407',
    b'0000000102000C0A4870004860000F00010000',
    b'1000000100004C06426001300023000C010000',
    b'0200000101004C080400003400010C00010000',
    b'1000006100000C0A4C40003260000C00010000',
    b'0000004101000C144C68003C60000C00010000',
    b'0000006101000C0A4468003C00010C00010000',
    b'1200002101000C0C4010013240060000010000',
    b'0000000104004C0608200364002C0000010000',
    b'1200004101004C0B0A3800120020080C010000',
    b'1200003101004C0B0A3800120020080C010000',
    b'0000002102000C140A780064000C010C010000',
    b'0200004102004C040438002820030C00010000',
    b'0000006102000C000430003220030C00010000',
    b'1200000102000C010C00004640000C00010000',
    b'1000002102000C0A421001640000010C010000',
    b'1200006102004C0600500032000F0000010000',
    b'1200004100000E0C0800006400020000010000',
    b'0000002100004E010410005A00010C00010000',
    b'0200004100004E004708010F00450300010C00',
    b'1200000100000E11420002506000010C010000',
    b'030000110000500B427000464001000C010000',
    b'12000061010050600678014520600303010000',
    b'12000001010010074120006701000020010000',
    b'030000210000500B0C00023820000C00010000',
    b'13000001000010774420003200010C00010000',
    b'130000210000506D040A001440010C00010000',
    b'120000610000507C4D10015A40000C01010C00',
    b'000000010100501642280050000A010C010000',
    b'00000021010010294F400F646026040C410C0C',
    b'00000011000012140468013E00440800010000',
    b'00000021000052020428002E00060C00010000',
    b'00000041000052020C40003C00000C00010000',
    b'02000061000052040420002E20010C00010000',
    b'120000210000120304380038200B0C00010000',
    b'00000021010012024220012C40276C0B41000C',
    b'12000001010052084818013A000C0000010000',
    b'12000061000052040C40003C20000C00010000',
    b'12000041000012034C20003240000C00010000',
    b'02000041010012094718002D60422003010C00',
    b'000000210300120A0820030000070000010000')

_Mix = ('Mix',100)
_Level = ('Level',150)
_dicONOFF = ('OFF','ON')
_Tail = ('Tail',_dicONOFF)
_stomp = (('Gain',100),('Tone',100),('Level',150))
_reverb = (('Decay',1,30),('Tone',10),_Mix,('PreD',100),_Level,_Tail)

_dicCAB = {'FDCOMBO':   0x08,
           'DELUXE-R':  0x10,
           'FDVIBRO':   0x20,
           'USBLUES':   0x30,
           'VXCOMBO':   0x40,
           'VXJMI':     0x50,
           'BGCRUNCH':  0x60,
           'MATCH30':   0x70,
           'CARDRIVE': (0x00,0x01),
           'TWROCK':   (0x10,0x01),
           'TONECITY': (0x20,0x01),
           'HWSTACK':  (0x30,0x01),
           'TANGERINE':(0x40,0x01),
           'B-BRAkER': (0x50,0x01),
           'MSCRUNCH': (0x60,0x01),
           'MS1959':   (0x70,0x01),
           'MSDRIVE':  (0x00,0x02),
           'BGNDRIVE': (0x10,0x02),
           'BGDRIVE':  (0x20,0x02),
           'DZDRIVE':  (0x30,0x02),
           'ALIEN':    (0x40,0x02),
           'REVO-1':   (0x50,0x02)}

_amp = (('Gain',0,100),('Tube',0,100), _Level,
        ('Trebl',0,100),('Middl',0,100),('Bass',0,100),
        ('Prese',0,100),('CAB',_dicCAB),('OUT',('LINE','ComboFront','StackFront',
                                             'ComboPowerAmp', 'StackPowerAmp')))
_paraeqQ = (0.5,1,2,4,8,16)
_paraeqFreq = ('20Hz','25Hz','32Hz','40Hz','50Hz','63Hz','80Hz','100Hz','125Hz','160Hz',
                '200Hz','250Hz','320Hz','400Hz','500Hz','630Hz','800Hz','1.0KHz','1.2KHz','1.6KHz',
                '2.0KHz','2.5KHz','3.2KHz','4.0KHz','5.0KHz','6.3KHz','8.0KHz','10KHz','12KHz','16KHz','20KHz')

_chorus = (('Depth',100),('Rate',1,50),_Mix,('Tone',10),_Level)
_flanger = (('Depth',100),('Rate',50),('Reso',-10,10),('PreD',50),_Mix,_Level)


_Sense = tuple(list(range(-10,0))+list(range(1,11)))
_pitch = (('Shift',tuple(list(range(-12,13))+[24])),
          ('Tone',10),('Bal',100),('Fine',-25,25),_Level)

_source = (('BYPASS'    , ()),
           ('Comp'      , (('Sense',10),('Tone',10),_Level,('ATTCK',('Slow','Fast')))),
           ('OptComp'   , (('Drive',10),('Tone',100),_Level)),
           ('160Comp'   , (('THRSH',-60,0),('Ratio',1.0,10.0, lambda x:int((x-1.0)*10)),
                          ('Gain',20),('Knee',('Hard','Soft'),_Level))),
           ('SlowATTCK' , (('Time',1,50),('Curve',10),_Level)),
           ('ZNR'       , (('THRSH',1,25),('DETCT',('GtrIn','EfxIn')),_Level)),
           ('NoiseGate' , (('THRSH',1,25),_Level)),
           ('GraphicEQ' , (('160Hz',-12,12),('400Hz',-12,12),('800Hz',-12,12),
                          ('3.2KHz',-12,12),('6.4KHz',-12,12),('12KHz',-12,12),_Level)),

           ('ParaEQ'    , (('Freq1',_paraeqFreq),('Q1',_paraeqQ),('Gain1',-12,12),
                          ('Freq2',_paraeqFreq),('Q2',_paraeqQ),('Gain2',-12,12),_Level)),
           ('Exciter'   , (('Bass',100),('Trebl',100),_Level)),
           ('AutoWah'   , (('Sense',_Sense),('Reso',10),_Level)),
           ('Cry'       , (('Range',10),('Reso',10),('Sense',_Sense),('Bal',100),_Level)),
           ('M-Filter'  , (('Freq',100),('Sense',10),('Reso',10),('Type',('HPF','BPF','LPF')),
                          ('Chara',('2Pole','4Pole')),('VLCTY',('Fast','Slow')),('Bal',100),_Level)),
           ('Step'      , (('Depth',100),('Rate',50),('Reso',10),('Shape',10),_Level)),

           ('SeqFLTR'   , (('Step',2,8),('PTTRN',1,8),('Speed',1,50),('Shape',10),('Reso',10),_Level)),
           ('RndmFLTR'  , (('Speed',1,50),('Range',100),('Reso',10),('Type',('HPF','BPF','LPF')),
                          ('Chara',('2Pole','4Pole')),('Bal',100),_Level)),
           ('fCycle'    , (('Rate',1,50),('Wave',('Sine','Tri','SawUP','SawDn')),
                          _Level,('Depth',100),('Reso',10))),

           ('Booster'   , _stomp),
           ('OverDrive' , _stomp),
           ('TScream'   , _stomp),
           ('Governor'  , _stomp),
           ('Dist+'     , _stomp),
           ('Dist1'     , _stomp),
           ('Squeak'    , _stomp),
           ('FuzzSmile' , _stomp),
           ('GreatMuff' , _stomp),
           ('MetalWRLD' , _stomp),
           ('HotBox'    , _stomp),
           ('ZClean'    , _stomp),
           ('ZMP1'      , _stomp),
           ('ZScream'   , _stomp),
           ('ZWild'     , _stomp),
           ('Lead'      , _stomp),
           ('ExtremeDS' , _stomp),
           ('Aco.Sim'   , (('Top',100),('Body',100),_Level)),

           ('FDCOMBO'   , _amp),
           ('DELUXE-R'  , _amp),
           ('FDVIBRO'   , _amp),
           ('USBLUES'   , _amp),
           ('VXCOMBO'   , _amp),
           ('VXJMI'     , _amp),
           ('BGCRUNCH'  , _amp),
           ('MATCH30'   , _amp),
           ('CARDRIVE'  , _amp),
           ('TWROCK'    , _amp),
           ('TONECITY'  , _amp),
           ('HWSTACK'   , _amp),
           ('TANGERINE' , _amp),
           ('B-BRAkER'  , _amp),
           ('MSCRUNCH'  , _amp),
           ('MS1959'    , _amp),
           ('MSDRIVE'   , _amp),
           ('BGNDRIVE'  , _amp),
           ('BGDRIVE'   , _amp),
           ('DZDRIVE'   , _amp),
           ('ALIEN'     , _amp),
           ('REVO-1'    , _amp),

           ('Tremolo'   , (('Depth',100),('Rate',50),_Level,
                          ('Wave',[(s%i) for s in ('UP%d','DWN%d','TRI%d') for i in range(10)]))),
           ('Slicer'    , (('PTTRN',1,20),('Speed',1,50),('Bal',100),('THRSH',50),_Level)),
           ('Phaser'    , (('Rate',1,50),('Color',('4STG','8STG','inv4','inv8')),_Level)),
           ('DuoPhase'  , (('RateA',1,50),('RateB',tuple(list(range(1,50))+['SyncA','RvrsA'])),_Level,
                          ('ResoA',10),('ResoB',10),('Link',('Seri','Para','STR')),('DPT_A',100),('DPT_B',100))),
           ('Vibrato'   , (('Depth',100),('Rate',50),('Bal',100),('Tone',10),_Level)),
           ('TheVibe'   , (('Speed',50),('Depth',100),('Bias',100),('Wave',100),('Mode',('VIVRT','CHORS')),_Level)),
           ('Detune'    , (('Cent',-25,25),('preD',50),_Mix,('Tone',10),_Level)),
           ('Chorus'    , _chorus),
           ('StereoCho' , _chorus),
           ('Ensembl'   , _chorus),
           ('SuperCho'  , (('E.LVL',120),('Rate',100),('Depth',100),('EQ',100),('Mode',('MONO','STR')))),
           ('CoronaTri' , (('SPEED',100),('DEPTH',100),('FxLVL',100),('TONE',100),('DRY',_dicONOFF))),
           ('Flanger'   , _flanger),
           ('VinFLNGR'  , _flanger),
           ('Octave'    , (('Oct1',100),('Oct2',100),('Dry',100),('Chara',100),('Tone',10),_Level)),
           ('PitchSHFT' , _pitch),
           ('MonoPitch' , _pitch),
           ('HPS'       , (('Scale',(-6,-5,-4,-3,'-m','m',3,4,5,6)),
                           ('Key',('C','C#','D','D#','E','F','F#','G','G#','A','A#','B')),
                           _Mix,('Tone',10),_Level)),
           ('BendCho'   , (('Depth',100),('Time',50),('Bal',100),('Mode',('Up','Down')),('Tone',10),_Level)),
           ('RingMod'   , (('Freq',1,50),('Tone',10),('Bal',100),_Level)),
           ('RtCloset'  , (('Bal',100),('Mode',('Slow','Fast')),_Level,('Drive',100))),
           ('BitCrush'  , (('Bit',4,16),('SMPL',50),('Bal',100),('Tone',10),_Level)),
           ('Bomber'    , (('PTTRN',('HndGn','Arm','Bomb','Thndr')),('Decay',100),('Bal',100),
                           ('THRSH',50),('Power',30),('Tone,50'),_Level)),
           ('Z-Organ'    , (('Upper',100),('Lower',100),('Dry',100),('HPF',10),('LPF',10),_Level)),

           ('Delay'     , (('Time',1,4000),('F.B',100),_Mix,('HiDMP',10),('P-P',('MONO','P-P')),_Level,_Tail)),
           ## todo 'Sync'
           ('CarbonDly' , (('DELAY',19,581),('REGEN',100),_Mix,('MOD',_dicONOFF),('WIDTH',50),('SPEED',50),_Tail,
                           ('Sync',15))),
           ('StompDly'  , (('E.LVL',120),('FB',100),('Time',1,600),('Sync',15),
                           ('Mode',('MONO','STR')),_Tail,('HiDMP',10))),
           ('TapeEcho'  , (('Time',1,2000),('F.B',100),_Mix,('HiDMP',10),_Level,_Tail)),

           ('ReverseDL' , (('Time',10,2000),('F.B',100),('Bal',100),('HiDMP',10),_Level,_Tail)),
           ('MultiTapD' , (('Time',1,3000),('PTTRN',1,8),_Mix,('Tone',10),_Level,_Tail)),
           ('FilterDly' , (('Time',1,2000),('F.B',100),_Mix,('Rate',1,50),('Depth',100),('Reso',10),_Level,_Tail)),
           ('PitchDly'  , (('Time',1,2000),('Pitch',-12,12),_Mix,('F.B',100),('Tone',10),_Level,_Tail)),
           ('StereoDly' , (('TimeL',1,2000),('TimeR',1,2000),_Mix,('LchFB',100),('RchFB',100),
                           _Level,('LchLv',100),('RchLv',100),_Tail)),

           ('HDHall'    , (('PreD',1,200),('Decay',100),_Mix,('LoDMP',100),('HiDMP',100),_Tail)),
           ('Hall'      , _reverb),
           ('Room'      , _reverb),
           ('TiledRoom' , _reverb),
           ('Arena'     , _reverb),
           ('Plate'     , (('PreD',1,200),('Decay',100),('Color',100),_Mix,('LoDMP',100),('HiDMP',100),_Tail,_Level)),
           ('Spring63'  , (('DWELL',100),('MIXER',100),('TONE',100),('LEVEL',150))),
           ('Air'       , (('Size',1,100),('Tone',10),_Mix,('Ref',10),_Level,_Tail)),
           ('EarlyRef'  , (('Decay',1,30),('Shape',-10,10),_Mix,('Tone',10),_Level,_Tail)),
           ('ModReverb' , (('Depth',100),('Decay',1,30),_Mix,('Rate',1,50),('Tone',10),('PreD',1,100),_Level,_Tail)),
           ('ParricleR' , (('DWELL',100),('GAIN',100),_Mix,('MODE',('STBL','CRTCL','HZD')),
                           _Mix,('MONO',_dicONOFF),_Tail)))

fxinfos = collections.OrderedDict(_source)

fxids = tuple(fxinfos.keys())

_tmpint=0
def _get_for_reset():
    global _tmpint
    if _tmpint == 0: _tmpint = 1
    result = _tmpint
    _tmpint = (_tmpint + 1) % 0x7F
    return result

class G1onFx():
    def __init__(self, g1on, fx_index, fx_name, rules):
        self.__g1on = g1on
        self.__fx_index = fx_index
        self.__name = fx_name
        self.__dic = dict()
        for (param_index,r) in enumerate(rules):
            param_name = r[0]
            m = len(r)
            if m==2 and isinstance(r[1],int):
                fn = self.__mk_int_param(g1on, fx_index, param_index, param_name, 0, r[1])
            elif m==2 and (isinstance(r[1],tuple) or isinstance(r[1],dict)):
                fn = self.__mk_opt_param(g1on, fx_index, param_index, param_name, r[1])
            elif m==3:
                fn = self.__mk_int_param(g1on, fx_index, param_index, param_name, r[1], r[2])
            elif m==4:
                fn = self.__mk_flex_num_param(g1on, fx_index, param_index, param_name, r[1], r[2], r[3])
            else: raise(Exception('Internal Error'))
            self.__dic.update({param_name:fn})
        self.__param_names = tuple(self.__dic.keys())

    def __mk_int_param(self, g1on, fx_index, param_index, param_name, int_min, int_max):
        def fn(value):
            if not isinstance(value,int):
                raise(Exception(f"{self.__name}['{param_name}'] = {value} : not an integer"))
            elif value<int_min or value>int_max:
                raise(Exception(f"{self.__name}['{param_name}'] = {value} : out of range ({int_min} ... {int_max})"))
            else:
                g1on._unsafe_set_fx_param(fx_index, param_index+2, value-int_min)
        return fn

    def __mk_flex_num_param(self, g1on, fx_index, param_index, param_name, num_min, num_max, manipulator):
        def fn(value):
            if not isinstance(value,int) and not isinstance(value,float):
                raise(Exception(f"{self.__name}['{param_name}'] = {value} : not a number"))
            elif value<num_min or value>num_max:
                raise(Exception(f"{self.__name}['{param_name}'] = {value} : out of range ({num_min} ... {num_max})"))
            else:
                g1on._unsafe_set_fx_param(fx_index, param_index+2, manipulator(value))
        return fn

    def __mk_opt_param(self, g1on, fx_index, param_index, param_name, opts):
        if isinstance(opts,tuple):
            dic = dict( zip(opts, range(0,len(opts))) )
        else:
            dic = opts
        keys = tuple(dic.keys())
        def fn(opt):
            value = dic.get(opt)
            if isinstance(value,int):
                g1on._unsafe_set_fx_param(fx_index, param_index+2, value)
            elif isinstance(value,tuple):
                g1on._unsafe_set_fx_param(fx_index, param_index+2, value[0], value[1])
            else:
                raise(Exception(f"{self.__name}['{param_name}'] = {value} : is not in {keys}"))
        return fn
    
    def __setparam(self, param_name, x):
        fn = self.__dic.get(param_name)
        if not fn:
            raise(Exception(f"{self.__name}['{param_name}'] = {x}: '{param_name}' is not in {self.__param_names}"))
        else:
            fn(x)
    
    def __setitem__(self, param_name_or_param_names, x):
        if isinstance(param_name_or_param_names,str):
            self.__setparam(param_name_or_param_names, x)
        elif isinstance(param_name_or_param_names,tuple) and isinstance(x,tuple) and len(param_name_or_param_names) == len(x):
            for (name,v) in zip(param_name_or_param_names,x):
                self.__setparam(name, v)
        else:
            raise(Exception('length'))
            

    def set_state(self, st:bool):
        self.__g1on._unsafe_set_fx_param(self.__fx_index, 0, 1 if st else 0)

    def on(self): self.set_state(True)
    def off(self): self.set_state(False)

    def reset(self):
        self.__g1on._unsafe_set_fx_param(self.__fx_index, 1, _get_for_reset())
        
    def has(self, param_name):
        return param_name in self.__dic
    

# -*- coding: utf-8 -*-
#  This file is part of pymidiate.

#############################################################
##             pymidiate / midiate.zoom.g1on               ##
## Copyright (C) 2019 PGkids Laboratory <<EMAIL>> ##
#############################################################

import collections

# ５エフェクトを使い全てがバイパス状態のパッチデータ
# 本ライブラリでは、これをプロトタイプとして使う
# パッチのボリュームレベルは 220,221のポジションである
# パッチネームの開始は242から終端F7ターミネータまで、４文字と６文字のヌル終端文字列で表す
# 長さは268 (134bytes)
init5 = b'F0520063280001000000000000000000000000000000000000000100000000000000000000000000000000000000000100000000000000000000000000000000000000010000000000000000000000000000000000000000010000000000000000000000000100000000000020006401000000200300000000202020200020202020202000F7'

# p1..p5は第一エフェクトから第５エフェクトまでそれぞれ１００種類のエフェクトの初期パタンである。

# 10-42
p1 = (b'000100000000000000000000000000000',
      b'081100000201300000640000000000000',
      b'0A6100004201300100320000000000000',
      b'0A6B000002097000100600000C0000000',
      b'400100000205500000640000000000000',
      b'402100004202080000640000000000000',
      b'404100004202200300000000000000000',
      b'00210000040360003C0C000101010C000',
      b'00410000040208002C0C602100010C000',
      b'006100000400000000640000000000000',
      b'402100004404400000640000000000000',
      b'48610000040140003010000C0C0000000',
      b'00210100040E28000607402000000C0C0',
      b'02410100040F4800100840010C0000000',
      b'086101000401300008194041010C00000',
      b'4A0101000408100104064020400B0C000',
      b'40210100440118002064000C010000000',
      b'021100000614100100640000000000000',
      b'02210000060F100100640000000000000',
      b'0A4100000611100100640000000000000',
      b'02610000060F100100640000000000000',
      b'420100000614100100640000000000000',
      b'42210000060F100100640000000000000',
      b'42410000060A100100640000000000000',
      b'4A6100000611100100640000000000000',
      b'0A0101000611100100640000000000000',
      b'02210100060F100100640000000000000',
      b'02410100060F100100640000000000000',
      b'02610100060F100100640000000000000',
      b'42010100060F100100640000000000000',
      b'42610100060F100100640000000000000',
      b'02210200060F100100640000000000000',
      b'02410200060F100100640000000000000',
      b'02610200060F100100640000000000000',
      b'420102000614100100640000000000000',
      b'02110000080670001C560026050506012',
      b'0A210000080C700000644046464606022',
      b'02410000080E70002C624046660506042',
      b'0A610000480E7000206B4045064607062',
      b'4A0100004807700024640045262606082',
      b'4A210000080C7000006440464646060A2',
      b'42410000480E7000046340464606070C2',
      b'42610000080770003C6440452525060E2',
      b'0A010100480C7000004A4046464606102',
      b'02210100480D7000005F4046664606122',
      b'0A410100081370002C594046460506142',
      b'0A610100080D7000246A4045060706162',
      b'4A0101000811700028630046264506182',
      b'42210100480F7800086440460666061A2',
      b'42410100081270002C6240452646061C2',
      b'4A610100080E7000006440464646061E2',
      b'0A0102000814700024672045062706202',
      b'0221020008157000205B0046264606222',
      b'0A410200480B700008610046060606242',
      b'02610200480B7000345D2066656606262',
      b'4A010200080F70002C570046064506282',
      b'4221020008107000005940466666062A2',
      b'001100000C14080160022002000000000',
      b'024100000C00400020640042100000000',
      b'086100004C02180000640000000000000',
      b'086B00000C0B280016640040000044070',
      b'020102000C0A7000204860000F0000000',
      b'420100004C06600108300023000C00000',
      b'080101004C080000103400010C0000000',
      b'426100000C0A4000303260000C0000000',
      b'024101000C146800303C60000C0000000',
      b'026101000C0A6800103C00010C0000000',
      b'4A2101000C0C100100324006000000000',
      b'000104004C0620032064002C000000000',
      b'484101004C0B380028120020080C00000',
      b'483101004C0B380028120020080C00000',
      b'002102000C1478002864000C010C00000',
      b'084102004C043800102820030C0000000',
      b'006102000C003000103220030C0000000',
      b'480102000C010000304640000C0000000',
      b'422102000C0A100108640000010C00000',
      b'486102004C0650000032000F000000000',
      b'484100000E0C000020640002000000000',
      b'002100004E011000105A00010C0000000',
      b'0A4100004E0008011C0F004503000C000',
      b'4A0100000E11000208506000010C00000',
      b'0E110000500B700008464001000C00000',
      b'486101005060780118452060030300000',
      b'4A0101001007200004670100002000000',
      b'0C210000500B0002303820000C0000000',
      b'4E01000010772000103200010C0000000',
      b'4C210000506D0A00101440010C0000000',
      b'4A610000507C1001345A40000C010C000',
      b'02010100501628000850000A010C00000',
      b'022101001029400F3E646026040C0C0C0',
      b'0011000012146801103E0044080000000',
      b'0021000052022800102E00060C0000000',
      b'0041000052024000303C00000C0000000',
      b'0861000052042000102E20010C0000000',
      b'48210000120338001038200B0C0000000',
      b'02210100120220010A2C40276C0B000C0',
      b'4A01010052081801203A000C000000000',
      b'4861000052044000303C20000C0000000',
      b'4A41000012032000303240000C0000000',
      b'0A410100120918001C2D604220030C000',
      b'00210300120A200320000007000000000')

# 43-83
p2 = (b'00000000001000000000000000000000000000000',
      b'00000000011000040020130006400000000000000',
    b'00000000061000050420130013200000000000000',
    b'0000000006B00005102097000060000000C000000',
    b'40000000001000000020550006400000000000000',
    b'40000000021000000420208006400000000000000',
    b'40000000041000000420220030000000000000000',
    b'00000000021000003040360000C00016001010C00',
    b'00000000041000002040208000C60216000010C00',
    b'00000000061000000040000006400000000000000',
    b'40000000021000000440440006400000000000000',
    b'400000000610000430401400010000C000C000000',
    b'00000000021010000040E28000740203000000C0C',
    b'00000000041010011040F4800084001000C000000',
    b'000000000610100400401300019404140010C0000',
    b'400000000010100500408100106402020400B0C00',
    b'400000000210100024401180064000C0001000000',
    b'00000000011000010061410016400000000000000',
    b'00000000021000010060F10016400000000000000',
    b'00000000041000050061110016400000000000000',
    b'00000000061000010060F10016400000000000000',
    b'40000000001000010061410016400000000000000',
    b'40000000021000010060F10016400000000000000',
    b'40000000041000010060A10016400000000000000',
    b'40000000061000050061110016400000000000000',
    b'00000000001010050061110016400000000000000',
    b'00000000021010010060F10016400000000000000',
    b'00000000041010010060F10016400000000000000',
    b'00000000061010010060F10016400000000000000',
    b'40000000001010010060F10016400000000000000',
    b'40000000061010010060F10016400000000000000',
    b'00000000021020010060F10016400000000000000',
    b'00000000041020010060F10016400000000000000',
    b'00000000061020010060F10016400000000000000',
    b'40000000001020010061410016400000000000000',
    b'00000000011000011080670005600266205050601',
    b'00000000021000050080C70006440460246460602',
    b'00000000041000012080E70006240466266050604',
    b'00000000061000052480E70006B40450206460706',
    b'40000000001000052480770006400452226260608',
    b'40000000021000050080C7000644046024646060A',
    b'40000000041000010480E7000634046224606070C',
    b'4000000006100001308077000644045622525060E',
    b'00000000001010050480C70004A40460246460610',
    b'00000000021010010480D70005F40460266460612',
    b'00000000041010052081370005940466246050614',
    b'00000000061010052080D70006A40452206070616',
    b'40000000001010052081170006300464226450618',
    b'40000000021010010480F7800644046420666061A',
    b'4000000004101001208127000624045622646061C',
    b'40000000061010050080E7000644046024646061E',
    b'00000000001020052081470006720452206270620',
    b'00000000021020012081570005B00460226460622',
    b'00000000041020050480B70006100464206060624',
    b'00000000061020013480B70005D20662265660626',
    b'40000000001020052080F70005700466206450628',
    b'4000000002102001008107000594046026666062A',
    b'000000000110000060C1408010220020000000000',
    b'000000000410000120C0040006400420010000000',
    b'000000000610000404C0218006400000000000000',
    b'0000000006B0000410C0B28006400403000004407',
    b'000000000010200120C0A7000486000000F000000',
    b'400000000010000104C06600130002340000C0000',
    b'000000000010100414C080000340001000C000000',
    b'400000000610000130C0A4000326000000C000000',
    b'000000000410100130C1468003C6000000C000000',
    b'000000000610100110C0A68003C0001000C000000',
    b'400000000210100500C0C10013240060000000000',
    b'000000000010400024C06200364002C0000000000',
    b'400000000410100424C0B380012002040080C0000',
    b'400000000310100424C0B380012002040080C0000',
    b'000000000210200020C14780064000C40010C0000',
    b'000000000410200414C043800282003000C000000',
    b'000000000610200010C003000322003000C000000',
    b'400000000010200430C010000464000000C000000',
    b'400000000210200100C0A100164000040010C0000',
    b'400000000610200404C06500032000F0000000000',
    b'400000000410000420E0C00006400020000000000',
    b'000000000210000014E0110005A0001000C000000',
    b'000000000410000514E0008010F00456003000C00',
    b'400000000010000500E11000250600040010C0000',
    b'00000000011000070500B700046400140000C0000',
    b'40000000061010041506078014520604003030000',
    b'40000000001010050100720006701002000200000',
    b'00000000021000063500B0002382000000C000000',
    b'4000000000100007110772000320001000C000000',
    b'40000000021000061506D0A00144001000C000000',
    b'40000000061000053507C10015A4000200C010C00',
    b'000000000010100105016280050000A40010C0000',
    b'000000000210100131029400F64602670040C0C0C',
    b'00000000011000001121468013E00440008000000',
    b'00000000021000001520228002E0006000C000000',
    b'00000000041000003520240003C0000000C000000',
    b'00000000061000041520420002E2001000C000000',
    b'400000000210000411203380038200B000C000000',
    b'00000000021010010120220012C4027506C0B000C',
    b'40000000001010052520818013A000C0000000000',
    b'40000000061000043520440003C2000000C000000',
    b'4000000004100005312032000324000000C000000',
    b'00000000041010051120918002D60426020030C00',
    b'00000000021030002120A20030000070000000000')

# 90 - 125
p3 = (b'000001000000000000000000000000000000',
      b'040011000002013000006400000000000000',
    b'050061000042013000013200000000000000',
    b'05006B000002097008000600000C00000000',
    b'200001000002055000006400000000000000',
    b'200021000042020800006400000000000000',
    b'200041000042022000030000000000000000',
    b'00002100000403601E000C000101010C0000',
    b'000041000004020816000C602100010C0000',
    b'000061000004000000006400000000000000',
    b'200021000044044000006400000000000000',
    b'2400610000040140180010000C0C00000000',
    b'0000210100040E28030007402000000C000C',
    b'0100410100040F4808000840010C00000000',
    b'04006101000401300400194041010C000000',
    b'25000101000408100201064020400B0C0000',
    b'2000210100440118100064000C0100000000',
    b'010011000006141000016400000000000000',
    b'0100210000060F1000016400000000000000',
    b'050041000006111000016400000000000000',
    b'0100610000060F1000016400000000000000',
    b'210001000006141000016400000000000000',
    b'2100210000060F1000016400000000000000',
    b'2100410000060A1000016400000000000000',
    b'250061000006111000016400000000000000',
    b'050001010006111000016400000000000000',
    b'0100210100060F1000016400000000000000',
    b'0100410100060F1000016400000000000000',
    b'0100610100060F1000016400000000000000',
    b'2100010100060F1000016400000000000000',
    b'2100610100060F1000016400000000000000',
    b'0100210200060F1000016400000000000000',
    b'0100410200060F1000016400000000000000',
    b'0100610200060F1000016400000000000000',
    b'210001020006141000016400000000000000',
    b'01001100000806700E005600260505061001',
    b'0500210000080C7000006440464646061002',
    b'0100410000080E7016006240466605061004',
    b'0500610000480E7010006B40450646071006',
    b'250001000048077012006400452626061008',
    b'2500210000080C700000644046464606100A',
    b'2100410000480E700200634046460607100C',
    b'21006100000807701E00644045252506100E',
    b'0500010100480C7000004A40464646061010',
    b'0100210100480D7000005F40466646061012',
    b'050041010008137016005940464605061014',
    b'0500610100080D7012006A40450607061016',
    b'250001010008117014006300462645061018',
    b'2100210100480F780400644046066606101A',
    b'21004101000812701600624045264606101C',
    b'2500610100080E700000644046464606101E',
    b'050001020008147012006720450627061020',
    b'010021020008157010005B00462646061022',
    b'0500410200480B7004006100460606061024',
    b'0100610200480B701A005D20666566061026',
    b'2500010200080F7016005700460645061028',
    b'21002102000810700000594046666606102A',
    b'00001100000C140830010220020000000000',
    b'01004100000C004010006400421000000000',
    b'04006100004C021800006400000000000000',
    b'04006B00000C0B280B006400400000440007',
    b'01000102000C0A7010004860000F00000000',
    b'21000100004C06600401300023000C000000',
    b'04000101004C080008003400010C00000000',
    b'21006100000C0A4018003260000C00000000',
    b'01004101000C146818003C60000C00000000',
    b'01006101000C0A6808003C00010C00000000',
    b'25002101000C0C1000013240060000000000',
    b'00000104004C0620100364002C0000000000',
    b'24004101004C0B381400120020080C000000',
    b'24003101004C0B381400120020080C000000',
    b'00002102000C1478140064000C010C000000',
    b'04004102004C043808002820030C00000000',
    b'00006102000C003008003220030C00000000',
    b'24000102000C010018004640000C00000000',
    b'21002102000C0A100401640000010C000000',
    b'24006102004C0650000032000F0000000000',
    b'24004100000E0C0010006400020000000000',
    b'00002100004E011008005A00010C00000000',
    b'05004100004E00080E010F004503000C0000',
    b'25000100000E11000402506000010C000000',
    b'0700110000500B700400464001000C000000',
    b'24006101005060780C014520600303000000',
    b'250001010010072002006701000020000000',
    b'0600210000500B0018023820000C00000000',
    b'270001000010772008003200010C00000000',
    b'2600210000506D0A08001440010C00000000',
    b'2500610000507C101A015A40000C010C0000',
    b'0100010100501628040050000A010C000000',
    b'01002101001029401F0F646026040C0C000C',
    b'000011000012146808013E00440800000000',
    b'000021000052022808002E00060C00000000',
    b'000041000052024018003C00000C00000000',
    b'040061000052042008002E20010C00000000',
    b'2400210000120338080038200B0C00000000',
    b'010021010012022005012C40276C0B00000C',
    b'250001010052081810013A000C0000000000',
    b'240061000052044018003C20000C00000000',
    b'250041000012032018003240000C00000000',
    b'05004101001209180E002D604220030C0000',
    b'0000210300120A2010030000070000000000')

# 123 - 165
p4 = (b'0000000000001000000000000000000000000000000',
      b'0000000000011002000020130006400000000000000',
     b'0000000000061002800420130013200000000000000',
     b'000000000006B00280002097000060040000C000000',
     b'2000000000001000000020550006400000000000000',
     b'2000000000021000000420208006400000000000000',
     b'2000000000041000000420220030000000000000000',
     b'0000000000021000100040360000C00700101010C00',
     b'0000000000041000100040208000C60302100010C00',
     b'0000000000061000000040000006400000000000000',
     b'2000000000021000000440440006400000000000000',
     b'2000000000061002100040140001000400C0C000000',
     b'0000000000021010000040E28000740182000000C0C',
     b'0000000000041010800040F4800084040010C000000',
     b'00000000000610120000401300019402041010C0000',
     b'20000000000010128000408100106401020400B0C00',
     b'2000000000021010100440118006400000C01000000',
     b'0000000000011000800061410016400000000000000',
     b'0000000000021000800060F10016400000000000000',
     b'0000000000041002800061110016400000000000000',
     b'0000000000061000800060F10016400000000000000',
     b'2000000000001000800061410016400000000000000',
     b'2000000000021000800060F10016400000000000000',
     b'2000000000041000800060A10016400000000000000',
     b'2000000000061002800061110016400000000000000',
     b'0000000000001012800061110016400000000000000',
     b'0000000000021010800060F10016400000000000000',
     b'0000000000041010800060F10016400000000000000',
     b'0000000000061010800060F10016400000000000000',
     b'2000000000001010800060F10016400000000000000',
     b'2000000000061010800060F10016400000000000000',
     b'0000000000021020800060F10016400000000000000',
     b'0000000000041020800060F10016400000000000000',
     b'0000000000061020800060F10016400000000000000',
     b'2000000000001020800061410016400000000000000',
     b'0000000000011000800080670005600712605050601',
     b'0000000000021002800080C70006440014646460602',
     b'0000000000041000900080E70006240314666050604',
     b'0000000000061002900480E70006B40014506460706',
     b'2000000000001002900480770006400114526260608',
     b'2000000000021002800080C7000644001464646060A',
     b'2000000000041000800480E7000634011464606070C',
     b'200000000006100090008077000644071452525060E',
     b'0000000000001012800480C70004A40014646460610',
     b'0000000000021010800480D70005F40014666460612',
     b'0000000000041012900081370005940314646050614',
     b'0000000000061012900080D70006A40114506070616',
     b'2000000000001012900081170006300214626450618',
     b'2000000000021010800480F7800644021460666061A',
     b'200000000004101090008127000624031452646061C',
     b'2000000000061012800080E7000644001464646061E',
     b'0000000000001022900081470006720114506270620',
     b'0000000000021020900081570005B00014626460622',
     b'0000000000041022800480B70006100214606060624',
     b'0000000000061020900480B70005D20516665660626',
     b'2000000000001022900080F70005700314606450628',
     b'200000000002102080008107000594001466666062A',
     b'00000000000110003000C1408010220000200000000',
     b'00000000000410009000C0040006400004210000000',
     b'00000000000610020004C0218006400000000000000',
     b'000000000006B0020000C0B28006400584000004407',
     b'00000000000010209000C0A7000486000000F000000',
     b'20000000000010008004C06600130002023000C0000',
     b'00000000000010120004C080000340040010C000000',
     b'20000000000610009000C0A4000326040000C000000',
     b'00000000000410109000C1468003C6040000C000000',
     b'00000000000610108000C0A68003C0040010C000000',
     b'20000000000210128000C0C10013240000600000000',
     b'00000000000010401004C0620036400002C00000000',
     b'20000000000410121004C0B380012002020080C0000',
     b'20000000000310121004C0B380012002020080C0000',
     b'00000000000210201000C1478006400200C010C0000',
     b'00000000000410220004C043800282040030C000000',
     b'00000000000610200000C003000322040030C000000',
     b'20000000000010221000C010000464040000C000000',
     b'20000000000210208000C0A100164002000010C0000',
     b'20000000000610220004C0650003200000F00000000',
     b'20000000000410021000E0C00006400000200000000',
     b'00000000000210000004E0110005A0040010C000000',
     b'00000000000410028004E0008010F00704503000C00',
     b'20000000000010028000E11000250602000010C0000',
     b'0000000000011003800500B700046402001000C0000',
     b'2000000000061012000506078014520606003030000',
     b'2000000000001012800100720006701100000200000',
     b'0000000000021003100500B0002382040000C000000',
     b'200000000000100380010772000320040010C000000',
     b'2000000000021003000506D0A00144040010C000000',
     b'2000000000061002900507C10015A4050000C010C00',
     b'0000000000001010800501628005000200A010C0000',
     b'00000000000210109001029400F64607826040C0C0C',
     b'0000000000011000000121468013E00404408000000',
     b'0000000000021000000520228002E0040060C000000',
     b'0000000000041000100520240003C0040000C000000',
     b'0000000000061002000520420002E2040010C000000',
     b'2000000000021002000120338003820400B0C000000',
     b'0000000000021010800120220012C4028276C0B000C',
     b'2000000000001012900520818013A00000C00000000',
     b'2000000000061002100520440003C2040000C000000',
     b'200000000004100290012032000324040000C000000',
     b'0000000000041012800120918002D60704220030C00',
     b'0000000000021030100120A20030000000700000000')

# 170-207
p5 = (b'00000001000000000000000000000000010000',
      b'02000011000002010030006400000000010000',
    b'02000061000042014030013200000000010000',
    b'0200006B000002094470000600000C00010000',
    b'10000001000002050050006400000000010000',
    b'10000021000042020008006400000000010000',
    b'10000041000042020020030000000000010000',
    b'00000021000004030F60000C00010101010C00',
    b'00000041000004020B08000C60210001010C00',
    b'00000061000004000000006400000000010000',
    b'10000021000044040040006400000000010000',
    b'12000061000004010C400010000C0C00010000',
    b'000000210100040E0128000740200000410C0C',
    b'000000410100040F4448000840010C00010000',
    b'0200006101000401023000194041010C010000',
    b'1200000101000408411001064020400B010C00',
    b'100000210100440108180064000C0100010000',
    b'00000011000006144010016400000000010000',
    b'000000210000060F4010016400000000010000',
    b'02000041000006114010016400000000010000',
    b'000000610000060F4010016400000000010000',
    b'10000001000006144010016400000000010000',
    b'100000210000060F4010016400000000010000',
    b'100000410000060A4010016400000000010000',
    b'12000061000006114010016400000000010000',
    b'02000001010006114010016400000000010000',
    b'000000210100060F4010016400000000010000',
    b'000000410100060F4010016400000000010000',
    b'000000610100060F4010016400000000010000',
    b'100000010100060F4010016400000000010000',
    b'100000610100060F4010016400000000010000',
    b'000000210200060F4010016400000000010000',
    b'000000410200060F4010016400000000010000',
    b'000000610200060F4010016400000000010000',
    b'10000001020006144010016400000000010000',
    b'00000011000008064770005600260505090601',
    b'020000210000080C4070006440464646090602',
    b'000000410000080E4B70006240466605090604',
    b'020000610000480E4870006B40450646090706',
    b'12000001000048074970006400452626090608',
    b'120000210000080C407000644046464609060A',
    b'100000410000480E417000634046460609070C',
    b'10000061000008074F7000644045252509060E',
    b'020000010100480C4070004A40464646090610',
    b'000000210100480D4070005F40466646090612',
    b'02000041010008134B70005940464605090614',
    b'020000610100080D4970006A40450607090616',
    b'12000001010008114A70006300462645090618',
    b'100000210100480F427800644046066609061A',
    b'10000041010008124B7000624045264609061C',
    b'120000610100080E407000644046464609061E',
    b'02000001020008144970006720450627090620',
    b'00000021020008154870005B00462646090622',
    b'020000410200480B4270006100460606090624',
    b'000000610200480B4D70005D20666566090626',
    b'120000010200080F4B70005700460645090628',
    b'1000002102000810407000594046666609062A',
    b'0000001100000C141808010220020000010000',
    b'0000004100000C004840006400421000010000',
    b'0200006100004C020018006400000000010000',
    b'0200006B00000C0B0528006400400000414407',
    b'0000000102000C0A4870004860000F00010000',
    b'1000000100004C06426001300023000C010000',
    b'0200000101004C080400003400010C00010000',
    b'1000006100000C0A4C40003260000C00010000',
    b'0000004101000C144C68003C60000C00010000',
    b'0000006101000C0A4468003C00010C00010000',
    b'1200002101000C0C4010013240060000010000',
    b'0000000104004C0608200364002C0000010000',
    b'1200004101004C0B0A3800120020080C010000',
    b'1200003101004C0B0A3800120020080C010000',
    b'0000002102000C140A780064000C010C010000',
    b'0200004102004C040438002820030C00010000',
    b'0000006102000C000430003220030C00010000',
    b'1200000102000C010C00004640000C00010000',
    b'1000002102000C0A421001640000010C010000',
    b'1200006102004C0600500032000F0000010000',
    b'1200004100000E0C0800006400020000010000',
    b'0000002100004E010410005A00010C00010000',
    b'0200004100004E004708010F00450300010C00',
    b'1200000100000E11420002506000010C010000',
    b'030000110000500B427000464001000C010000',
    b'12000061010050600678014520600303010000',
    b'12000001010010074120006701000020010000',
    b'030000210000500B0C00023820000C00010000',
    b'13000001000010774420003200010C00010000',
    b'130000210000506D040A001440010C00010000',
    b'120000610000507C4D10015A40000C01010C00',
    b'000000010100501642280050000A010C010000',
    b'00000021010010294F400F646026040C410C0C',
    b'00000011000012140468013E00440800010000',
    b'00000021000052020428002E00060C00010000',
    b'00000041000052020C40003C00000C00010000',
    b'02000061000052040420002E20010C00010000',
    b'120000210000120304380038200B0C00010000',
    b'00000021010012024220012C40276C0B41000C',
    b'12000001010052084818013A000C0000010000',
    b'12000061000052040C40003C20000C00010000',
    b'12000041000012034C20003240000C00010000',
    b'02000041010012094718002D60422003010C00',
    b'000000210300120A0820030000070000010000')

_Mix = ('Mix',100)
_Level = ('Level',150)
_dicONOFF = ('OFF','ON')
_Tail = ('Tail',_dicONOFF)
_stomp = (('Gain',100),('Tone',100),('Level',150))
_reverb = (('Decay',1,30),('Tone',10),_Mix,('PreD',100),_Level,_Tail)

_dicCAB = {'FDCOMBO':   0x08,
           'DELUXE-R':  0x10,
           'FDVIBRO':   0x20,
           'USBLUES':   0x30,
           'VXCOMBO':   0x40,
           'VXJMI':     0x50,
           'BGCRUNCH':  0x60,
           'MATCH30':   0x70,
           'CARDRIVE': (0x00,0x01),
           'TWROCK':   (0x10,0x01),
           'TONECITY': (0x20,0x01),
           'HWSTACK':  (0x30,0x01),
           'TANGERINE':(0x40,0x01),
           'B-BRAkER': (0x50,0x01),
           'MSCRUNCH': (0x60,0x01),
           'MS1959':   (0x70,0x01),
           'MSDRIVE':  (0x00,0x02),
           'BGNDRIVE': (0x10,0x02),
           'BGDRIVE':  (0x20,0x02),
           'DZDRIVE':  (0x30,0x02),
           'ALIEN':    (0x40,0x02),
           'REVO-1':   (0x50,0x02)}

_amp = (('Gain',0,100),('Tube',0,100), _Level,
        ('Trebl',0,100),('Middl',0,100),('Bass',0,100),
        ('Prese',0,100),('CAB',_dicCAB),('OUT',('LINE','ComboFront','StackFront',
                                             'ComboPowerAmp', 'StackPowerAmp')))
_paraeqQ = (0.5,1,2,4,8,16)
_paraeqFreq = ('20Hz','25Hz','32Hz','40Hz','50Hz','63Hz','80Hz','100Hz','125Hz','160Hz',
                '200Hz','250Hz','320Hz','400Hz','500Hz','630Hz','800Hz','1.0KHz','1.2KHz','1.6KHz',
                '2.0KHz','2.5KHz','3.2KHz','4.0KHz','5.0KHz','6.3KHz','8.0KHz','10KHz','12KHz','16KHz','20KHz')

_chorus = (('Depth',100),('Rate',1,50),_Mix,('Tone',10),_Level)
_flanger = (('Depth',100),('Rate',50),('Reso',-10,10),('PreD',50),_Mix,_Level)


_Sense = tuple(list(range(-10,0))+list(range(1,11)))
_pitch = (('Shift',tuple(list(range(-12,13))+[24])),
          ('Tone',10),('Bal',100),('Fine',-25,25),_Level)

_source = (('BYPASS'    , ()),
           ('Comp'      , (('Sense',10),('Tone',10),_Level,('ATTCK',('Slow','Fast')))),
           ('OptComp'   , (('Drive',10),('Tone',100),_Level)),
           ('160Comp'   , (('THRSH',-60,0),('Ratio',1.0,10.0, lambda x:int((x-1.0)*10)),
                          ('Gain',20),('Knee',('Hard','Soft'),_Level))),
           ('SlowATTCK' , (('Time',1,50),('Curve',10),_Level)),
           ('ZNR'       , (('THRSH',1,25),('DETCT',('GtrIn','EfxIn')),_Level)),
           ('NoiseGate' , (('THRSH',1,25),_Level)),
           ('GraphicEQ' , (('160Hz',-12,12),('400Hz',-12,12),('800Hz',-12,12),
                          ('3.2KHz',-12,12),('6.4KHz',-12,12),('12KHz',-12,12),_Level)),

           ('ParaEQ'    , (('Freq1',_paraeqFreq),('Q1',_paraeqQ),('Gain1',-12,12),
                          ('Freq2',_paraeqFreq),('Q2',_paraeqQ),('Gain2',-12,12),_Level)),
           ('Exciter'   , (('Bass',100),('Trebl',100),_Level)),
           ('AutoWah'   , (('Sense',_Sense),('Reso',10),_Level)),
           ('Cry'       , (('Range',10),('Reso',10),('Sense',_Sense),('Bal',100),_Level)),
           ('M-Filter'  , (('Freq',100),('Sense',10),('Reso',10),('Type',('HPF','BPF','LPF')),
                          ('Chara',('2Pole','4Pole')),('VLCTY',('Fast','Slow')),('Bal',100),_Level)),
           ('Step'      , (('Depth',100),('Rate',50),('Reso',10),('Shape',10),_Level)),

           ('SeqFLTR'   , (('Step',2,8),('PTTRN',1,8),('Speed',1,50),('Shape',10),('Reso',10),_Level)),
           ('RndmFLTR'  , (('Speed',1,50),('Range',100),('Reso',10),('Type',('HPF','BPF','LPF')),
                          ('Chara',('2Pole','4Pole')),('Bal',100),_Level)),
           ('fCycle'    , (('Rate',1,50),('Wave',('Sine','Tri','SawUP','SawDn')),
                          _Level,('Depth',100),('Reso',10))),

           ('Booster'   , _stomp),
           ('OverDrive' , _stomp),
           ('TScream'   , _stomp),
           ('Governor'  , _stomp),
           ('Dist+'     , _stomp),
           ('Dist1'     , _stomp),
           ('Squeak'    , _stomp),
           ('FuzzSmile' , _stomp),
           ('GreatMuff' , _stomp),
           ('MetalWRLD' , _stomp),
           ('HotBox'    , _stomp),
           ('ZClean'    , _stomp),
           ('ZMP1'      , _stomp),
           ('ZScream'   , _stomp),
           ('ZWild'     , _stomp),
           ('Lead'      , _stomp),
           ('ExtremeDS' , _stomp),
           ('Aco.Sim'   , (('Top',100),('Body',100),_Level)),

           ('FDCOMBO'   , _amp),
           ('DELUXE-R'  , _amp),
           ('FDVIBRO'   , _amp),
           ('USBLUES'   , _amp),
           ('VXCOMBO'   , _amp),
           ('VXJMI'     , _amp),
           ('BGCRUNCH'  , _amp),
           ('MATCH30'   , _amp),
           ('CARDRIVE'  , _amp),
           ('TWROCK'    , _amp),
           ('TONECITY'  , _amp),
           ('HWSTACK'   , _amp),
           ('TANGERINE' , _amp),
           ('B-BRAkER'  , _amp),
           ('MSCRUNCH'  , _amp),
           ('MS1959'    , _amp),
           ('MSDRIVE'   , _amp),
           ('BGNDRIVE'  , _amp),
           ('BGDRIVE'   , _amp),
           ('DZDRIVE'   , _amp),
           ('ALIEN'     , _amp),
           ('REVO-1'    , _amp),

           ('Tremolo'   , (('Depth',100),('Rate',50),_Level,
                          ('Wave',[(s%i) for s in ('UP%d','DWN%d','TRI%d') for i in range(10)]))),
           ('Slicer'    , (('PTTRN',1,20),('Speed',1,50),('Bal',100),('THRSH',50),_Level)),
           ('Phaser'    , (('Rate',1,50),('Color',('4STG','8STG','inv4','inv8')),_Level)),
           ('DuoPhase'  , (('RateA',1,50),('RateB',tuple(list(range(1,50))+['SyncA','RvrsA'])),_Level,
                          ('ResoA',10),('ResoB',10),('Link',('Seri','Para','STR')),('DPT_A',100),('DPT_B',100))),
           ('Vibrato'   , (('Depth',100),('Rate',50),('Bal',100),('Tone',10),_Level)),
           ('TheVibe'   , (('Speed',50),('Depth',100),('Bias',100),('Wave',100),('Mode',('VIVRT','CHORS')),_Level)),
           ('Detune'    , (('Cent',-25,25),('preD',50),_Mix,('Tone',10),_Level)),
           ('Chorus'    , _chorus),
           ('StereoCho' , _chorus),
           ('Ensembl'   , _chorus),
           ('SuperCho'  , (('E.LVL',120),('Rate',100),('Depth',100),('EQ',100),('Mode',('MONO','STR')))),
           ('CoronaTri' , (('SPEED',100),('DEPTH',100),('FxLVL',100),('TONE',100),('DRY',_dicONOFF))),
           ('Flanger'   , _flanger),
           ('VinFLNGR'  , _flanger),
           ('Octave'    , (('Oct1',100),('Oct2',100),('Dry',100),('Chara',100),('Tone',10),_Level)),
           ('PitchSHFT' , _pitch),
           ('MonoPitch' , _pitch),
           ('HPS'       , (('Scale',(-6,-5,-4,-3,'-m','m',3,4,5,6)),
                           ('Key',('C','C#','D','D#','E','F','F#','G','G#','A','A#','B')),
                           _Mix,('Tone',10),_Level)),
           ('BendCho'   , (('Depth',100),('Time',50),('Bal',100),('Mode',('Up','Down')),('Tone',10),_Level)),
           ('RingMod'   , (('Freq',1,50),('Tone',10),('Bal',100),_Level)),
           ('RtCloset'  , (('Bal',100),('Mode',('Slow','Fast')),_Level,('Drive',100))),
           ('BitCrush'  , (('Bit',4,16),('SMPL',50),('Bal',100),('Tone',10),_Level)),
           ('Bomber'    , (('PTTRN',('HndGn','Arm','Bomb','Thndr')),('Decay',100),('Bal',100),
                           ('THRSH',50),('Power',30),('Tone,50'),_Level)),
           ('Z-Organ'    , (('Upper',100),('Lower',100),('Dry',100),('HPF',10),('LPF',10),_Level)),

           ('Delay'     , (('Time',1,4000),('F.B',100),_Mix,('HiDMP',10),('P-P',('MONO','P-P')),_Level,_Tail)),
           ## todo 'Sync'
           ('CarbonDly' , (('DELAY',19,581),('REGEN',100),_Mix,('MOD',_dicONOFF),('WIDTH',50),('SPEED',50),_Tail,
                           ('Sync',15))),
           ('StompDly'  , (('E.LVL',120),('FB',100),('Time',1,600),('Sync',15),
                           ('Mode',('MONO','STR')),_Tail,('HiDMP',10))),
           ('TapeEcho'  , (('Time',1,2000),('F.B',100),_Mix,('HiDMP',10),_Level,_Tail)),

           ('ReverseDL' , (('Time',10,2000),('F.B',100),('Bal',100),('HiDMP',10),_Level,_Tail)),
           ('MultiTapD' , (('Time',1,3000),('PTTRN',1,8),_Mix,('Tone',10),_Level,_Tail)),
           ('FilterDly' , (('Time',1,2000),('F.B',100),_Mix,('Rate',1,50),('Depth',100),('Reso',10),_Level,_Tail)),
           ('PitchDly'  , (('Time',1,2000),('Pitch',-12,12),_Mix,('F.B',100),('Tone',10),_Level,_Tail)),
           ('StereoDly' , (('TimeL',1,2000),('TimeR',1,2000),_Mix,('LchFB',100),('RchFB',100),
                           _Level,('LchLv',100),('RchLv',100),_Tail)),

           ('HDHall'    , (('PreD',1,200),('Decay',100),_Mix,('LoDMP',100),('HiDMP',100),_Tail)),
           ('Hall'      , _reverb),
           ('Room'      , _reverb),
           ('TiledRoom' , _reverb),
           ('Arena'     , _reverb),
           ('Plate'     , (('PreD',1,200),('Decay',100),('Color',100),_Mix,('LoDMP',100),('HiDMP',100),_Tail,_Level)),
           ('Spring63'  , (('DWELL',100),('MIXER',100),('TONE',100),('LEVEL',150))),
           ('Air'       , (('Size',1,100),('Tone',10),_Mix,('Ref',10),_Level,_Tail)),
           ('EarlyRef'  , (('Decay',1,30),('Shape',-10,10),_Mix,('Tone',10),_Level,_Tail)),
           ('ModReverb' , (('Depth',100),('Decay',1,30),_Mix,('Rate',1,50),('Tone',10),('PreD',1,100),_Level,_Tail)),
           ('ParricleR' , (('DWELL',100),('GAIN',100),_Mix,('MODE',('STBL','CRTCL','HZD')),
                           _Mix,('MONO',_dicONOFF),_Tail)))

fxinfos = collections.OrderedDict(_source)

fxids = tuple(fxinfos.keys())

_tmpint=0
def _get_for_reset():
    global _tmpint
    if _tmpint == 0: _tmpint = 1
    result = _tmpint
    _tmpint = (_tmpint + 1) % 0x7F
    return result

class G1onFx():
    def __init__(self, g1on, fx_index, fx_name, rules):
        self.__g1on = g1on
        self.__fx_index = fx_index
        self.__name = fx_name
        self.__dic = dict()
        for (param_index,r) in enumerate(rules):
            param_name = r[0]
            m = len(r)
            if m==2 and isinstance(r[1],int):
                fn = self.__mk_int_param(g1on, fx_index, param_index, param_name, 0, r[1])
            elif m==2 and (isinstance(r[1],tuple) or isinstance(r[1],dict)):
                fn = self.__mk_opt_param(g1on, fx_index, param_index, param_name, r[1])
            elif m==3:
                fn = self.__mk_int_param(g1on, fx_index, param_index, param_name, r[1], r[2])
            elif m==4:
                fn = self.__mk_flex_num_param(g1on, fx_index, param_index, param_name, r[1], r[2], r[3])
            else: raise(Exception('Internal Error'))
            self.__dic.update({param_name:fn})
        self.__param_names = tuple(self.__dic.keys())

    def __mk_int_param(self, g1on, fx_index, param_index, param_name, int_min, int_max):
        def fn(value):
            if not isinstance(value,int):
                raise(Exception(f"{self.__name}['{param_name}'] = {value} : not an integer"))
            elif value<int_min or value>int_max:
                raise(Exception(f"{self.__name}['{param_name}'] = {value} : out of range ({int_min} ... {int_max})"))
            else:
                g1on._unsafe_set_fx_param(fx_index, param_index+2, value-int_min)
        return fn

    def __mk_flex_num_param(self, g1on, fx_index, param_index, param_name, num_min, num_max, manipulator):
        def fn(value):
            if not isinstance(value,int) and not isinstance(value,float):
                raise(Exception(f"{self.__name}['{param_name}'] = {value} : not a number"))
            elif value<num_min or value>num_max:
                raise(Exception(f"{self.__name}['{param_name}'] = {value} : out of range ({num_min} ... {num_max})"))
            else:
                g1on._unsafe_set_fx_param(fx_index, param_index+2, manipulator(value))
        return fn

    def __mk_opt_param(self, g1on, fx_index, param_index, param_name, opts):
        if isinstance(opts,tuple):
            dic = dict( zip(opts, range(0,len(opts))) )
        else:
            dic = opts
        keys = tuple(dic.keys())
        def fn(opt):
            value = dic.get(opt)
            if isinstance(value,int):
                g1on._unsafe_set_fx_param(fx_index, param_index+2, value)
            elif isinstance(value,tuple):
                g1on._unsafe_set_fx_param(fx_index, param_index+2, value[0], value[1])
            else:
                raise(Exception(f"{self.__name}['{param_name}'] = {value} : is not in {keys}"))
        return fn
    
    def __setparam(self, param_name, x):
        fn = self.__dic.get(param_name)
        if not fn:
            raise(Exception(f"{self.__name}['{param_name}'] = {x}: '{param_name}' is not in {self.__param_names}"))
        else:
            fn(x)
    
    def __setitem__(self, param_name_or_param_names, x):
        if isinstance(param_name_or_param_names,str):
            self.__setparam(param_name_or_param_names, x)
        elif isinstance(param_name_or_param_names,tuple) and isinstance(x,tuple) and len(param_name_or_param_names) == len(x):
            for (name,v) in zip(param_name_or_param_names,x):
                self.__setparam(name, v)
        else:
            raise(Exception('length'))
            

    def set_state(self, st:bool):
        self.__g1on._unsafe_set_fx_param(self.__fx_index, 0, 1 if st else 0)

    def on(self): self.set_state(True)
    def off(self): self.set_state(False)

    def reset(self):
        self.__g1on._unsafe_set_fx_param(self.__fx_index, 1, _get_for_reset())
        
    def has(self, param_name):
        return param_name in self.__dic
# -*- coding: utf-8 -*- #  This file is part of pymidiate. ############################################################# ##             pymidiate / midiate.zoom.g1on               ## ## Copyright (C) 2019 PGkids Laboratory <<EMAIL>> ## ############################################################# # ５エフェクトを使い全てがバイパス状態のパッチデータ # 本ライブラリでは、これをプロトタイプとして使う # パッチのボリュームレベルは 220,221のポジションである # パッチネームの開始は242から終端F7ターミネータまで、４文字と６文字のヌル終端文字列で表す # 長さは268 (134bytes) # p1..p5は第一エフェクトから第５エフェクトまでそれぞれ１００種類のエフェクトの初期パタンである。 # 10-42 # 43-83 # 90 - 125 # 123 - 165 # 170-207 #','D','D#','E','F','F#','G','G#','A','A#','B')), ## todo 'Sync'