Skip to content

Commit

Permalink
Bug 1856695 - Improve how we handle MIDI port
Browse files Browse the repository at this point in the history
  • Loading branch information
Ponchale committed Oct 23, 2023
1 parent 175d6f4 commit 49119c8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 28 deletions.
16 changes: 8 additions & 8 deletions dom/midi/MIDIInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@

namespace mozilla::dom {

MIDIInput::MIDIInput(nsPIDOMWindowInner* aWindow, MIDIAccess* aMIDIAccessParent)
: MIDIPort(aWindow, aMIDIAccessParent), mKeepAlive(false) {}
MIDIInput::MIDIInput(nsPIDOMWindowInner* aWindow)
: MIDIPort(aWindow), mKeepAlive(false) {}

// static
MIDIInput* MIDIInput::Create(nsPIDOMWindowInner* aWindow,
MIDIAccess* aMIDIAccessParent,
const MIDIPortInfo& aPortInfo,
const bool aSysexEnabled) {
RefPtr<MIDIInput> MIDIInput::Create(nsPIDOMWindowInner* aWindow,
MIDIAccess* aMIDIAccessParent,
const MIDIPortInfo& aPortInfo,
const bool aSysexEnabled) {
MOZ_ASSERT(static_cast<MIDIPortType>(aPortInfo.type()) ==
MIDIPortType::Input);
auto* port = new MIDIInput(aWindow, aMIDIAccessParent);
if (!port->Initialize(aPortInfo, aSysexEnabled)) {
RefPtr<MIDIInput> port = new MIDIInput(aWindow);
if (!port->Initialize(aPortInfo, aSysexEnabled, aMIDIAccessParent)) {
return nullptr;
}
return port;
Expand Down
11 changes: 5 additions & 6 deletions dom/midi/MIDIInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ class MIDIPortInfo;
*/
class MIDIInput final : public MIDIPort {
public:
static MIDIInput* Create(nsPIDOMWindowInner* aWindow,
MIDIAccess* aMIDIAccessParent,
const MIDIPortInfo& aPortInfo,
const bool aSysexEnabled);
~MIDIInput() = default;
static RefPtr<MIDIInput> Create(nsPIDOMWindowInner* aWindow,
MIDIAccess* aMIDIAccessParent,
const MIDIPortInfo& aPortInfo,
const bool aSysexEnabled);

JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
Expand All @@ -37,7 +36,7 @@ class MIDIInput final : public MIDIPort {
void DisconnectFromOwner() override;

private:
MIDIInput(nsPIDOMWindowInner* aWindow, MIDIAccess* aMIDIAccessParent);
explicit MIDIInput(nsPIDOMWindowInner* aWindow);
// Takes an array of IPC MIDIMessage objects and turns them into
// MIDIMessageEvents, which it then fires.
void Receive(const nsTArray<MIDIMessage>& aMsgs) override;
Expand Down
17 changes: 8 additions & 9 deletions dom/midi/MIDIOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,18 @@
using namespace mozilla;
using namespace mozilla::dom;

MIDIOutput::MIDIOutput(nsPIDOMWindowInner* aWindow,
MIDIAccess* aMIDIAccessParent)
: MIDIPort(aWindow, aMIDIAccessParent) {}
MIDIOutput::MIDIOutput(nsPIDOMWindowInner* aWindow) : MIDIPort(aWindow) {}

// static
MIDIOutput* MIDIOutput::Create(nsPIDOMWindowInner* aWindow,
MIDIAccess* aMIDIAccessParent,
const MIDIPortInfo& aPortInfo,
const bool aSysexEnabled) {
RefPtr<MIDIOutput> MIDIOutput::Create(nsPIDOMWindowInner* aWindow,
MIDIAccess* aMIDIAccessParent,
const MIDIPortInfo& aPortInfo,
const bool aSysexEnabled) {
MOZ_ASSERT(static_cast<MIDIPortType>(aPortInfo.type()) ==
MIDIPortType::Output);
auto* port = new MIDIOutput(aWindow, aMIDIAccessParent);
if (NS_WARN_IF(!port->Initialize(aPortInfo, aSysexEnabled))) {
RefPtr<MIDIOutput> port = new MIDIOutput(aWindow);
if (NS_WARN_IF(
!port->Initialize(aPortInfo, aSysexEnabled, aMIDIAccessParent))) {
return nullptr;
}
return port;
Expand Down
10 changes: 5 additions & 5 deletions dom/midi/MIDIOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ class MIDIMessage;
*/
class MIDIOutput final : public MIDIPort {
public:
static MIDIOutput* Create(nsPIDOMWindowInner* aWindow,
MIDIAccess* aMIDIAccessParent,
const MIDIPortInfo& aPortInfo,
const bool aSysexEnabled);
static RefPtr<MIDIOutput> Create(nsPIDOMWindowInner* aWindow,
MIDIAccess* aMIDIAccessParent,
const MIDIPortInfo& aPortInfo,
const bool aSysexEnabled);
~MIDIOutput() = default;

JSObject* WrapObject(JSContext* aCx,
Expand All @@ -43,7 +43,7 @@ class MIDIOutput final : public MIDIPort {
void Clear();

private:
MIDIOutput(nsPIDOMWindowInner* aWindow, MIDIAccess* aMIDIAccessParent);
explicit MIDIOutput(nsPIDOMWindowInner* aWindow);
};

} // namespace dom
Expand Down

0 comments on commit 49119c8

Please sign in to comment.