// Copyright (c) 2010-2014 SharpDX - Alexandre Mutel // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. using System; namespace SharpDX.DirectInput { public partial class Effect { /// /// Initializes a new instance of the class. /// /// The device. /// The GUID. /// The parameters. public Effect(Device device, Guid guid, EffectParameters parameters) { device.CreateEffect(guid, parameters, this, null); } /// /// Sends a hardware-specific command to the force-feedback driver. /// /// Driver-specific command number. Consult the driver documentation for a list of valid commands. /// Buffer containing the data required to perform the operation. /// Buffer in which the operation's output data is returned. /// Number of bytes written to the output buffer /// /// Because each driver implements different escapes, it is the application's responsibility to ensure that it is sending the escape to the correct driver by comparing the value of the guidFFDriver member of the structure against the value the application is expecting. /// public int Escape(int command, byte[] inData, byte[] outData) { var effectEscape = new EffectEscape(); unsafe { fixed (void* pInData = &inData[0]) fixed (void* pOutData = &outData[0]) { effectEscape.Size = sizeof(EffectEscape); effectEscape.Command = command; effectEscape.InBufferPointer = (IntPtr)pInData; effectEscape.InBufferSize = inData.Length; effectEscape.OutBufferPointer = (IntPtr)pOutData; effectEscape.OutBufferSize = outData.Length; Escape(ref effectEscape); return effectEscape.OutBufferSize; } } } /// /// Gets the characteristics of an effect. /// /// The current parameters of this effect. public EffectParameters GetParameters() { return GetParameters(EffectParameterFlags.All); } /// /// Sets the characteristics of an effect. /// /// The parameters of this effect. /// A object describing the result of the operation. public void SetParameters(EffectParameters parameters) { SetParameters(parameters, EffectParameterFlags.All); } /// /// Begins playing an effect infinitely. If the effect is already playing, it is restarted from the beginning. If the effect has not been downloaded or has been modified since its last download, it is downloaded before being started. This default behavior can be suppressed by passing the flag. /// /// A object describing the result of the operation. public void Start() { Start(-1); } /// /// Begins playing an effect infinitely. If the effect is already playing, it is restarted from the beginning. If the effect has not been downloaded or has been modified since its last download, it is downloaded before being started. This default behavior can be suppressed by passing the flag. /// /// Flags that describe how the effect should be played by the device. /// A object describing the result of the operation. public void Start(EffectPlayFlags flags) { Start(-1, flags); } /// /// Begins playing an effect. If the effect is already playing, it is restarted from the beginning. If the effect has not been downloaded or has been modified since its last download, it is downloaded before being started. This default behavior can be suppressed by passing the flag. /// /// Number of times to play the effect in sequence. The envelope is re-articulated with each iteration. To play the effect exactly once, pass 1. To play the effect repeatedly until explicitly stopped, pass -1. To play the effect until explicitly stopped without re-articulating the envelope, modify the effect parameters with the method, and change the Duration member to -1. /// A object describing the result of the operation. public void Start(int iterations) { Start(iterations, EffectPlayFlags.None); } } }