diff --git a/src/__tests__/conversion.spec.ts b/src/__tests__/conversion.spec.ts index 7a6f5bb..1c6ff4e 100644 --- a/src/__tests__/conversion.spec.ts +++ b/src/__tests__/conversion.spec.ts @@ -219,9 +219,12 @@ describe('MTS data hex string converter', () => { expect(mtsBytesToHex(new Uint8Array([69, 0, 0]))).toEqual('450000'); expect(mtsBytesToHex(new Uint8Array([69, 10, 6]))).toEqual('450a06'); }); - it('masks int values above 0x7f by 0x7f', () => { - expect(mtsBytesToHex(new Uint8Array([69, 240, 6]))).toEqual('457006'); - expect(mtsBytesToHex(new Uint8Array([69, 255, 6]))).toEqual('457f06'); + it('clamps int values above 0x7f to 0x7f', () => { + expect(mtsBytesToHex(new Uint8Array([69, 240, 6]))).toEqual('457f06'); + expect(mtsBytesToHex(new Uint8Array([128, 255, 128]))).toEqual('7f7f7f'); + }); + it('allow value reserved for "no tuning change"', () => { + expect(mtsBytesToHex(new Uint8Array([127, 127, 127]))).toEqual('7f7f7f'); }); }); diff --git a/src/conversion.ts b/src/conversion.ts index bee8a67..34d1fae 100644 --- a/src/conversion.ts +++ b/src/conversion.ts @@ -147,9 +147,9 @@ export function mtsBytesToHex(mtsBytes: Uint8Array): String { const msb = mtsBytes[1] > 0x7f ? 0x7f : mtsBytes[1]; const lsb = mtsBytes[2] > 0x7f ? 0x7f : mtsBytes[2]; return ( - (noteNumber).toString(16).padStart(2, '0') + - (msb).toString(16).padStart(2, '0') + - (lsb).toString(16).padStart(2, '0') + noteNumber.toString(16).padStart(2, '0') + + msb.toString(16).padStart(2, '0') + + lsb.toString(16).padStart(2, '0') ); }