blob: bc32b8203323c5eb87d180bb335972995178ba2d [file] [log] [blame]
toyoshim2f3a48f2016-10-17 01:54:13 -07001// Copyright 2016 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5module midi.mojom;
6
Adithya Srinivasan052cbb42018-11-28 17:17:34 +00007import "mojo/public/mojom/base/time.mojom";
8
toyoshim2f3a48f2016-10-17 01:54:13 -07009enum Result {
10 NOT_INITIALIZED,
11 OK,
12 NOT_SUPPORTED,
13 INITIALIZATION_ERROR,
toyoshim2f3a48f2016-10-17 01:54:13 -070014};
15
toyoshimec2570a2016-10-21 02:15:27 -070016enum PortState {
17 DISCONNECTED,
18 CONNECTED,
19 OPENED,
toyoshimec2570a2016-10-21 02:15:27 -070020};
21
Adithya Srinivasan33252732018-10-17 15:59:40 +000022struct PortInfo {
23 string id;
24 string manufacturer;
25 string name;
26 string version;
27 PortState state;
28};
29
Adithya Srinivasan052cbb42018-11-28 17:17:34 +000030// Interface for MIDI related browser to renderer messages.
31interface MidiSessionClient {
32 // These functions are called in 2 cases:
33 // (1) Just before calling |SessionStarted|, to notify the recipient about
34 // existing ports.
35 // (2) To notify the recipient that a new device was connected and that new
36 // ports have been created.
37 AddInputPort(PortInfo info);
38 AddOutputPort(PortInfo info);
39
40 // Used to notify clients when a device is disconnected or reconnected. The
41 // ports correspond to ports already sent to the client using AddInputPort/
42 // AddOutputPort.
43 SetInputPortState(uint32 port, PortState state);
44 SetOutputPortState(uint32 port, PortState state);
45
46 // Called in response to StartSession and indicates if a connection with
47 // MIDI hardware was successfully made.
48 SessionStarted(Result result);
49
50 // Used to inform the client incrementally of how many bytes have been
51 // successfully sent. This is only called after the client calls SendData().
52 AcknowledgeSentData(uint32 bytes);
53
54 // Called to send MIDI data to the client.
55 DataReceived(uint32 port,
56 array<uint8> data,
57 mojo_base.mojom.TimeTicks timestamp);
58};
59
60// Interface used by the renderer to start a MIDI session in the browser.
61interface MidiSessionProvider {
62 // Start session to access MIDI hardware.
Gyuyoung Kim5559bb72019-08-27 00:47:10 +000063 StartSession(pending_receiver<MidiSession> receiver,
64 pending_remote<MidiSessionClient> client);
Adithya Srinivasan052cbb42018-11-28 17:17:34 +000065};
66
67// Represents an active MIDI session.
68interface MidiSession {
69 // Send data to a MIDI output port. The output port should be a port already
70 // sent to the client (via AddOutputPort).
71 SendData(uint32 port, array<uint8> data, mojo_base.mojom.TimeTicks timestamp);
72};