1 /**
  2  * This file is part of the Web Enabled Audio and Sound Enhancement Library (aka the Weasel audio library) Copyright 2011 - 2013 Warren Willmey. It is covered by the GNU General Public License version 3 as published by the Free Software Foundation, you should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
  3  */
  4 
  5 if( undefined == window.weasel ) window.weasel = {};
  6 
  7 // ---------------------------------------------------------------------------
  8 /** Object containing constants that a  Lars "Zap" Hamre Protracker module that uses the M.K. format requires, in 
  9  * addition to those defined in FormatUltimateSoundTracker121, FormatDOCSoundTracker9, FormatDOCSoundTracker22, Spreadpoint Soundtracker 2.3, FormatNoiseTracker11, , FormatNoiseTracker20.
 10  * 
 11  * @constructor
 12  * @const
 13  */
 14 weasel.FormatProTrackerMK =
 15 {
 16 	/** The supported effects in a Lars "Zap" Hamre Protracker module in addition to those in Noisetracker 2.0,Noisetracker 1.1, Spreadpoint Soundtracker 2.3, DOC Soundtracker 2.2 & DOC Soundtracker 9.
 17 	 * 
 18 	 * @const
 19 	 * @enum {int}
 20 	 */
 21 	Effects: {
 22 			  Tremolo				:		7
 23 			, SetSampleOffset		:		9
 24 			
 25 			, ExtendedCommands		:		14
 26 			// Extended Commands.
 27 			//
 28 			, Filter				:		0x0
 29 			, FineSlideUp			:		0x10
 30 			, FineSlideDown			:		0x20
 31 			, GlissandoControl		:		0x30
 32 			, SetVibratoWaveform	:		0x40
 33 			, SetFineTune			:		0x50
 34 			, PatternLoop			:		0x60
 35 			, SetTremoloWaveform	:		0x70
 36 			, RetriggerNote			:		0x90
 37 			, FineVolumeSlideUp		:		0xa0
 38 			, FineVolumeSlideDown	:		0xb0
 39 			, NoteCut				:		0xc0
 40 			, NoteDelay				:		0xd0
 41 			, PatternDelay			:		0xe0
 42 			, InvertLoop			:		0xf0
 43 	}
 44 	/** The offset in bytes, from the beginning of the module, to where the 
 45 	 * Protracker marker can be found who's value is always 127.
 46 	 * 
 47 	 * @const
 48 	 * @enum {int}
 49 	 */
 50 	, ProtrackerMarker:	951
 51 
 52 	/** The maximum size of a sample (in bytes) in a Protracker M.K. module.
 53 	 * @const
 54 	 * @type {int}
 55 	 */
 56 	, MaxSampleSize:	131070
 57 
 58 	/** Fine tune note period table, store in the order of a 4bit twos complement
 59 	 * (so positive fine tuning first before negative fine tuning).
 60 	 *
 61 	 * @const
 62 	 * @type {array}
 63 	 */
 64 	, FineTunePeriodTables:[ 
 65 		// Fine tuning 0, normal.
 66 		  856, 808, 762, 720, 678, 640, 604, 570, 538, 508, 480, 453
 67 		, 428, 404, 381, 360, 339, 320, 302, 285, 269, 254, 240, 226
 68 		, 214, 202, 190, 180, 170, 160, 151, 143, 135, 127, 120, 113
 69 		, 0
 70 		// Fine tuning 1
 71 		, 850, 802, 757, 715, 674, 637, 601, 567, 535, 505, 477, 450
 72 		, 425, 401, 379, 357, 337, 318, 300, 284, 268, 253, 239, 225
 73 		, 213, 201, 189, 179, 169, 159, 150, 142, 134, 126, 119, 113
 74 		, 0
 75 		// Fine tuning 2
 76 		, 844, 796, 752, 709, 670, 632, 597, 563, 532, 502, 474, 447
 77 		, 422, 398, 376, 355, 335, 316, 298, 282, 266, 251, 237, 224
 78 		, 211, 199, 188, 177, 167, 158, 149, 141, 133, 125, 118, 112
 79 		, 0
 80 		// Fine tuning 3
 81 		, 838, 791, 746, 704, 665, 628, 592, 559, 528, 498, 470, 444
 82 		, 419, 395, 373, 352, 332, 314, 296, 280, 264, 249, 235, 222
 83 		, 209, 198, 187, 176, 166, 157, 148, 140, 132, 125, 118, 111
 84 		, 0
 85 		// Fine tuning 4
 86 		, 832, 785, 741, 699, 660, 623, 588, 555, 524, 495, 467, 441
 87 		, 416, 392, 370, 350, 330, 312, 294, 278, 262, 247, 233, 220
 88 		, 208, 196, 185, 175, 165, 156, 147, 139, 131, 124, 117, 110
 89 		, 0
 90 		// Fine tuning 5
 91 		, 826, 779, 736, 694, 655, 619, 584, 551, 520, 491, 463, 437
 92 		, 413, 390, 368, 347, 328, 309, 292, 276, 260, 245, 232, 219
 93 		, 206, 195, 184, 174, 164, 155, 146, 138, 130, 123, 116, 109
 94 		, 0
 95 		// Fine tuning 6
 96 		, 820, 774, 730, 689, 651, 614, 580, 547, 516, 487, 460, 434
 97 		, 410, 387, 365, 345, 325, 307, 290, 274, 258, 244, 230, 217
 98 		, 205, 193, 183, 172, 163, 154, 145, 137, 129, 122, 115, 109
 99 		, 0
100 		// Fine tuning 7
101 		, 814, 768, 725, 684, 646, 610, 575, 543, 513, 484, 457, 431
102 		, 407, 384, 363, 342, 323, 305, 288, 272, 256, 242, 228, 216
103 		, 204, 192, 181, 171, 161, 152, 144, 136, 128, 121, 114, 108
104 		, 0
105 		// Fine tuning -8
106 		, 907, 856, 808, 762, 720, 678, 640, 604, 570, 538, 508, 480
107 		, 453, 428, 404, 381, 360, 339, 320, 302, 285, 269, 254, 240
108 		, 226, 214, 202, 190, 180, 170, 160, 151, 143, 135, 127, 120
109 		, 0
110 		// Fine tuning -7
111 		, 900, 850, 802, 757, 715, 675, 636, 601, 567, 535, 505, 477
112 		, 450, 425, 401, 379, 357, 337, 318, 300, 284, 268, 253, 238
113 		, 225, 212, 200, 189, 179, 169, 159, 150, 142, 134, 126, 119
114 		, 0
115 		// Fine tuning -6
116 		, 894, 844, 796, 752, 709, 670, 632, 597, 563, 532, 502, 474
117 		, 447, 422, 398, 376, 355, 335, 316, 298, 282, 266, 251, 237
118 		, 223, 211, 199, 188, 177, 167, 158, 149, 141, 133, 125, 118
119 		, 0
120 		// Fine tuning -5
121 		, 887, 838, 791, 746, 704, 665, 628, 592, 559, 528, 498, 470
122 		, 444, 419, 395, 373, 352, 332, 314, 296, 280, 264, 249, 235
123 		, 222, 209, 198, 187, 176, 166, 157, 148, 140, 132, 125, 118
124 		, 0
125 		// Fine tuning -4
126 		, 881, 832, 785, 741, 699, 660, 623, 588, 555, 524, 494, 467
127 		, 441, 416, 392, 370, 350, 330, 312, 294, 278, 262, 247, 233
128 		, 220, 208, 196, 185, 175, 165, 156, 147, 139, 131, 123, 117
129 		, 0
130 		// Fine tuning -3
131 		, 875, 826, 779, 736, 694, 655, 619, 584, 551, 520, 491, 463
132 		, 437, 413, 390, 368, 347, 328, 309, 292, 276, 260, 245, 232
133 		, 219, 206, 195, 184, 174, 164, 155, 146, 138, 130, 123, 116
134 		, 0
135 		// Fine tuning -2
136 		, 868, 820, 774, 730, 689, 651, 614, 580, 547, 516, 487, 460
137 		, 434, 410, 387, 365, 345, 325, 307, 290, 274, 258, 244, 230
138 		, 217, 205, 193, 183, 172, 163, 154, 145, 137, 129, 122, 115
139 		, 0
140 		// Fine tuning -1
141 		, 862, 814, 768, 725, 684, 646, 610, 575, 543, 513, 484, 457
142 		, 431, 407, 384, 363, 342, 323, 305, 288, 272, 256, 242, 228
143 		, 216, 203, 192, 181, 171, 161, 152, 144, 136, 128, 121, 114
144 		, 0
145 		// Technically Protracker at this point is reaching into dynamic data
146 		// (variable storage space for channel 0) IF the provided replay routine
147 		// is used, this data can be replicated 100%. HOWEVER this data area is
148 		// different if the Protracker Editor is used as directly after the fine
149 		// tune table is a static Cursor Position Table and a static Unshifted
150 		// Keymap Table which is easy to replicate.
151 		//
152 		// Cursor Position Table.
153 		,  0x306,  0x708,  0x90a,  0xc0f, 0x1011, 0x1213, 0x1518, 0x191a
154 		, 0x1b1c, 0x1e21, 0x2223, 0x2425
155 		// Unshifted Key Map, which is a raw ascii table - the characters have been paired and converted to hex.
156 		, 0x6031		// "`", "1"
157 		, 0x3233		// "2", "3"
158 		//
159 		// For those interested in the behaviour of the original provided replay
160 		// routine here is the data it accesses in Channel 0 variable space.
161 		// But as its a real edge case bug (fine tuning must be -1 and
162 		// note with arpeggio > note 37) its not worth wasting the time to code
163 		// or the cpu to update this dynamic data area. Here is an
164 		// approximation of what *might* appear.
165 		//
166 //		, 214		// Note Period from current pattern position.
167 //		, 0x2047	// Instrument + Effect command & parameter from current pattern position.
168 //		, 0x0002	// Sample starting address in Chip Ram for current instrument.
169 //		, 0x3456	// Sample starting addr.
170 //		, 0x1900	// Sample length of current instrument.
171 //		, 0x0002	// Sample loop start address in Chip Ram for current instrument.
172 //		, 0x3856	// Sample loop start addr.
173 //		, 0x0a80	// Sample repeat length.
174 //		, 214		// Note Period
175 //		, 0xff40	// Fine tune (-1) and volume.
176 //		, 1			// DMA bit for channel 0.
177 //		, 0			// Tone portamento direction and speed flags.
178 //		, 0			// Tone portamento wanted note period.
179 //		, 0			// last Vibrato command and position bytes.
180 	]
181 
182 	/** The Extended Effect Command "Invert Loop" (often mistakenly referred to as "FunkIt")
183 	 * uses a look up table for the TIMING for when to invert the next byte within
184 	 * the sample data.
185 	 *
186 	 * @const
187 	 * @type {array}
188 	 */
189 	, InvertSampleLoop : [
190 		   0,  5,  6,  7,  8, 10, 11,  13
191 		, 16, 19, 22, 26, 32, 43, 64, 128
192 	]
193 
194 };