Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1270)

Unified Diff: Source/modules/webmidi/MIDIAccess.cpp

Issue 18858006: Implement MIDIOutput.send() (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: forward declare MIDIAccess Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/modules/webmidi/MIDIAccess.h ('k') | Source/modules/webmidi/MIDIOutput.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/webmidi/MIDIAccess.cpp
diff --git a/Source/modules/webmidi/MIDIAccess.cpp b/Source/modules/webmidi/MIDIAccess.cpp
index 220d597412f7372671353c319847c91460e2f170..d579ba34b674408e0967ed9aa69573294c90074f 100644
--- a/Source/modules/webmidi/MIDIAccess.cpp
+++ b/Source/modules/webmidi/MIDIAccess.cpp
@@ -61,17 +61,17 @@ MIDIAccess::MIDIAccess(ScriptExecutionContext* context, MIDIAccessPromise* promi
: ActiveDOMObject(context)
, m_promise(promise)
, m_hasAccess(false)
- , m_enableSysEx(false)
+ , m_sysExEnabled(false)
, m_requesting(false)
{
ScriptWrappable::init(this);
m_accessor = MIDIAccessor::create(this);
}
-void MIDIAccess::enableSysEx(bool enable)
+void MIDIAccess::setSysExEnabled(bool enable)
{
m_requesting = false;
- m_enableSysEx = enable;
+ m_sysExEnabled = enable;
if (enable)
m_accessor->startSession();
else
@@ -82,7 +82,7 @@ void MIDIAccess::didAddInputPort(const String& id, const String& manufacturer, c
{
ASSERT(isMainThread());
- // FIXME: Pass m_enableSysEx flag to filter system exclusive messages correctly.
+ // FIXME: Pass in |this| to create() method so we can filter system exclusive messages correctly.
m_inputs.append(MIDIInput::create(scriptExecutionContext(), id, manufacturer, name, version));
}
@@ -90,8 +90,8 @@ void MIDIAccess::didAddOutputPort(const String& id, const String& manufacturer,
{
ASSERT(isMainThread());
- // FIXME: Pass m_enableSysEx flag to filter system exclusive messages correctly.
- m_outputs.append(MIDIOutput::create(scriptExecutionContext(), id, manufacturer, name, version));
+ unsigned portIndex = m_outputs.size();
+ m_outputs.append(MIDIOutput::create(this, portIndex, scriptExecutionContext(), id, manufacturer, name, version));
}
void MIDIAccess::didStartSession()
@@ -119,6 +119,28 @@ void MIDIAccess::didReceiveMIDIData(unsigned portIndex, const unsigned char* dat
}
}
+void MIDIAccess::sendMIDIData(unsigned portIndex, const unsigned char* data, size_t length, double timeStampInMilliseconds)
+{
+ if (m_hasAccess && portIndex < m_outputs.size() && data && length > 1) {
+ // Convert from a time in milliseconds (a DOMHighResTimeStamp) according to the same time coordinate system as performance.now()
+ // into a time in seconds which is based on the time coordinate system of monotonicallyIncreasingTime().
+ double timeStamp;
+
+ if (!timeStampInMilliseconds) {
+ // We treat a value of 0 (which is the default value) as special, meaning "now".
+ // We need to translate it exactly to 0 seconds.
+ timeStamp = 0;
+ } else {
+ Document* document = toDocument(scriptExecutionContext());
+ ASSERT(document);
+ double documentStartTime = document->loader()->timing()->referenceMonotonicTime();
+ timeStamp = documentStartTime + 0.001 * timeStampInMilliseconds;
+ }
+
+ m_accessor->sendMIDIData(portIndex, data, length, timeStamp);
+ }
+}
+
void MIDIAccess::stop()
{
m_hasAccess = false;
@@ -130,6 +152,8 @@ void MIDIAccess::stop()
MIDIController* controller = MIDIController::from(document->page());
ASSERT(controller);
controller->cancelSysExPermissionRequest(this);
+
+ m_accessor.clear();
}
void MIDIAccess::startRequest()
@@ -158,6 +182,4 @@ void MIDIAccess::permissionDenied()
m_promise->reject(error);
}
-
-
} // namespace WebCore
« no previous file with comments | « Source/modules/webmidi/MIDIAccess.h ('k') | Source/modules/webmidi/MIDIOutput.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698