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

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

Issue 18858006: Implement MIDIOutput.send() (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: add support for regular Array 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 2e616069eee0111cc5c8435cc6c65dde87d30dcc..2d24c4f72d47649e43350f01899cc3c838cad79a 100644
--- a/Source/modules/webmidi/MIDIAccess.cpp
+++ b/Source/modules/webmidi/MIDIAccess.cpp
@@ -60,10 +60,11 @@ MIDIAccess::MIDIAccess(ScriptExecutionContext* context, MIDIAccessPromise* promi
: ActiveDOMObject(context)
, m_promise(promise)
, m_hasAccess(false)
+ , m_midiOptions(*promise->options())
{
ScriptWrappable::init(this);
m_accessor = MIDIAccessor::create(this);
- m_accessor->requestAccess(promise->options()->sysex);
+ m_accessor->requestAccess(m_midiOptions.sysex);
}
void MIDIAccess::didAddInputPort(const String& id, const String& manufacturer, const String& name, const String& version)
@@ -77,7 +78,8 @@ void MIDIAccess::didAddOutputPort(const String& id, const String& manufacturer,
{
ASSERT(isMainThread());
- 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::didAllowAccess()
@@ -114,9 +116,37 @@ 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) {
+ // Filter out System Exclusive messages if we're not allowed.
+ // FIXME: implement more extensive filtering.
+ if (data[0] >= 0xf0 && !m_midiOptions.sysex)
Takashi Toyoshima 2013/07/09 10:19:11 It should raise SecurityError if it detects forbid
Chris Rogers 2013/07/17 21:28:12 Done. Now raising SecurityError Also moved this
+ return;
+
+ // 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;
+ m_accessor.clear();
}
} // 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