Skip to content

Commit

Permalink
Fix raw values not being properly sent in Output.channelAfterTouch() (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Philippe Côté committed Dec 16, 2023
1 parent 2743325 commit 19faf78
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/OutputChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
);
Expand Down
27 changes: 26 additions & 1 deletion test/OutputChannel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 19faf78

Please sign in to comment.