Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 


Quelle  MIDIOutput.cpp   Sprache: C

 
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */


#include "mozilla/dom/MIDIOutput.h"
#include "mozilla/dom/MIDIPortChild.h"
#include "mozilla/dom/MIDITypes.h"
#include "mozilla/dom/MIDIOutputBinding.h"
#include "mozilla/dom/MIDIUtils.h"
#include "nsDOMNavigationTiming.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/dom/Document.h"
#include "mozilla/dom/Performance.h"
#include "nsGlobalWindowInner.h"

namespace mozilla::dom {

MIDIOutput::MIDIOutput(nsPIDOMWindowInner* aWindow) : MIDIPort(aWindow) {}

// static
RefPtr<MIDIOutput> MIDIOutput::Create(nsPIDOMWindowInner* aWindow,
                                      MIDIAccess* aMIDIAccessParent,
                                      const MIDIPortInfo& aPortInfo,
                                      const bool aSysexEnabled) {
  MOZ_ASSERT(static_cast<MIDIPortType>(aPortInfo.type()) ==
             MIDIPortType::Output);
  RefPtr<MIDIOutput> port = new MIDIOutput(aWindow);
  if (NS_WARN_IF(
          !port->Initialize(aPortInfo, aSysexEnabled, aMIDIAccessParent))) {
    return nullptr;
  }
  return port;
}

JSObject* MIDIOutput::WrapObject(JSContext* aCx,
                                 JS::Handle<JSObject*> aGivenProto) {
  return MIDIOutput_Binding::Wrap(aCx, this, aGivenProto);
}

void MIDIOutput::Send(const Sequence<uint8_t>& aData,
                      const Optional<double>& aTimestamp, ErrorResult& aRv) {
  if (Port()->DeviceState() == MIDIPortDeviceState::Disconnected) {
    aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
    return;
  }
  // The timestamp passed to us is a DOMHighResTimestamp, which is in relation
  // to the start of navigation timing. This needs to be turned into a
  // TimeStamp before it hits the platform specific MIDI service.
  //
  // If timestamp is either not set or zero, set timestamp to now and send the
  // message ASAP.
  TimeStamp timestamp;
  if (aTimestamp.WasPassed() && aTimestamp.Value() != 0) {
    nsCOMPtr<Document> doc = GetOwnerWindow()->GetDoc();
    if (!doc) {
      aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
      return;
    }
    TimeDuration ts_diff = TimeDuration::FromMilliseconds(aTimestamp.Value());
    timestamp = GetOwnerWindow()
                    ->GetPerformance()
                    ->GetDOMTiming()
                    ->GetNavigationStartTimeStamp() +
                ts_diff;
  } else {
    timestamp = TimeStamp::Now();
  }

  nsTArray<MIDIMessage> msgArray;
  bool ret = MIDIUtils::ParseMessages(aData, timestamp, msgArray);
  if (!ret) {
    aRv.ThrowTypeError("Invalid MIDI message");
    return;
  }

  if (msgArray.IsEmpty()) {
    aRv.ThrowTypeError("Empty message array");
    return;
  }

  // TODO Move this check back to parse message so we don't have to iterate
  // twice.
  if (!SysexEnabled()) {
    for (auto& msg : msgArray) {
      if (MIDIUtils::IsSysexMessage(msg)) {
        aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
        return;
      }
    }
  }
  Port()->SendSend(msgArray);
}

void MIDIOutput::Clear() {
  if (Port()->ConnectionState() == MIDIPortConnectionState::Closed) {
    return;
  }
  Port()->SendClear();
}

}  // namespace mozilla::dom

Messung V0.5
C=88 H=95 G=91

¤ Dauer der Verarbeitung: 0.11 Sekunden  (vorverarbeitet)  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Produkte
     Quellcodebibliothek

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....

Besucherstatistik

Besucherstatistik

Monitoring

Montastic status badge