diff --git a/src/OutputChannel.js b/src/OutputChannel.js index 491b0ddaa..d3df4600a 100644 --- a/src/OutputChannel.js +++ b/src/OutputChannel.js @@ -1132,10 +1132,13 @@ export class OutputChannel extends EventEmitter { } + // Normalize pressure to integer + if (!options.rawValue) pressure = Utilities.fromFloatTo7Bit(pressure); + this.send( [ (Enumerations.CHANNEL_MESSAGES.channelaftertouch << 4) + (this.number - 1), - Math.round(pressure * 127) + Math.round(pressure) ], {time: Utilities.toTimestamp(options.time)} ); diff --git a/test/OutputChannel.test.js b/test/OutputChannel.test.js index 2c428f2ea..cf643aeb2 100644 --- a/test/OutputChannel.test.js +++ b/test/OutputChannel.test.js @@ -1892,7 +1892,7 @@ describe("OutputChannel Object", function() { describe("sendChannelAftertouch()", function () { - it("should send correct MIDI message when using float", function(done) { + it("should send correct MIDI message when using float (0-1)", function(done) { // Arrange let index = 0; @@ -1924,6 +1924,31 @@ describe("OutputChannel Object", function() { }); + it("should send correct MIDI message when using integer (0-127)", function(done) { + + // Arrange + let index = 0; + VIRTUAL_OUTPUT.on("message", assert); + + // Act + for (let i = 0; i < 128; i++) { + WEBMIDI_OUTPUT.channels[1].sendChannelAftertouch(i, {rawValue: true}); + } + + // Assert + function assert(deltaTime, message) { + + expect(message[1]).to.equal(index++); + + if (index >= 128) { + VIRTUAL_OUTPUT.removeAllListeners(); + done(); + } + + } + + }); + it("should throw error when invalid pressure is specified", function() { // Arrange