Skip to content

Commit

Permalink
fix mtsBytesToHex style and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vsicurella committed Nov 16, 2023
1 parent b64b7c0 commit 83e63d5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
9 changes: 6 additions & 3 deletions src/__tests__/conversion.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,13 @@ 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"', () => {

Check failure on line 226 in src/__tests__/conversion.spec.ts

View workflow job for this annotation

GitHub Actions / build (17.x)

Delete `·`
expect(mtsBytesToHex(new Uint8Array([127, 127, 127]))).toEqual('7f7f7f')

Check failure on line 227 in src/__tests__/conversion.spec.ts

View workflow job for this annotation

GitHub Actions / build (17.x)

Insert `;`
})

Check failure on line 228 in src/__tests__/conversion.spec.ts

View workflow job for this annotation

GitHub Actions / build (17.x)

Insert `;`
});

describe('Frequency to MIDI converter', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/conversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
);
}

Expand Down

0 comments on commit 83e63d5

Please sign in to comment.