Exemplo n.º 1
0
        public void AddSamples(SampleArray samples)
        {
            var        uint8        = new Uint8Array(samples.Buffer);
            JsFunction fromCharCode = JsCode("String.fromCharCode").As <JsFunction>();
            var        b64          = window.btoa(fromCharCode.apply(null, uint8.As <object[]>()).As <string>());

            document.getElementById(_swfId).As <IFlashSynthOutput>().AlphaSynthAddSamples(b64);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Loads a score asynchronously from the given datasource
        /// </summary>
        /// <param name="path">the source path to load the binary file from</param>
        /// <param name="success">this function is called if the Score was successfully loaded from the datasource</param>
        /// <param name="error">this function is called if any error during the loading occured.</param>
        public static void LoadScoreAsync(string path, Action <Score> success, Action <Exception> error)
        {
            var xhr = new XMLHttpRequest();

            xhr.open("GET", path);
            xhr.responseType       = "arraybuffer";
            xhr.onreadystatechange = e =>
            {
                if (xhr.readyState == 4)
                {
                    if (xhr.status == 200)
                    {
                        try
                        {
                            var reader = new Uint8Array(xhr.response.As <ArrayBuffer>());
                            var score  = LoadScoreFromBytes(reader.As <byte[]>());
                            success(score);
                        }
                        catch (Exception exception)
                        {
                            error(exception);
                        }
                    }
                    // Error handling
                    else if (xhr.status == 0)
                    {
                        error(new FileLoadException("You are offline!!\n Please Check Your Network.", xhr));
                    }
                    else if (xhr.status == 404)
                    {
                        error(new FileLoadException("Requested URL not found.", xhr));
                    }
                    else if (xhr.status == 500)
                    {
                        error(new FileLoadException("Internel Server Error.", xhr));
                    }
                    else if (xhr.statusText == "parsererror")
                    {
                        error(new FileLoadException("Error.\nParsing JSON Request failed.", xhr));
                    }
                    else if (xhr.statusText == "timeout")
                    {
                        error(new FileLoadException("Request Time out.", xhr));
                    }
                    else
                    {
                        error(new FileLoadException("Unknow Error: " + xhr.responseText, xhr));
                    }
                }
            };

            xhr.open("GET", path, true);
            xhr.responseType = "arraybuffer";
            // IE fallback
            if (xhr.responseType != "arraybuffer")
            {
                // use VB Loader to load binary array
                dynamic vbArr        = VbAjaxLoader("GET", path);
                var     fileContents = vbArr.toArray();

                // decode byte array to string
                var data = new StringBuilder();
                var i    = 0;
                while (i < (fileContents.length - 1))
                {
                    data.Append(((char)(fileContents[i])));
                    i++;
                }

                var reader = GetBytesFromString(data.ToString());
                var score  = LoadScoreFromBytes(reader.As <byte[]>());
                success(score);
                return;
            }
            xhr.send();
        }
Exemplo n.º 3
0
        private void PlatformSetData <T>(int level, T[] data, int startIndex, int elementCount) where T : struct
        {
            int w, h;

            GetSizeForLevel(Width, Height, level, out w, out h);

            // Store the current bound texture.
            var prevTexture = GraphicsExtensions.GetBoundTexture2D();

            if (prevTexture != glTexture)
            {
                gl.bindTexture(gl.TEXTURE_2D, glTexture);
                GraphicsExtensions.CheckGLError();
            }

            GenerateGLTextureIfRequired();
            gl.pixelStorei(gl.UNPACK_ALIGNMENT, Math.Min(_format.GetSize(), 8));

            ArrayBufferView arrayBuffer = null;
            var             size        = Utilities.ReflectionHelpers.SizeOf <T> .Get();

            if (size == 1)
            {
                var subarr = new Uint8Array(data.As <ArrayBuffer>(), startIndex.As <uint>(), elementCount.As <uint>());
                arrayBuffer = subarr.As <ArrayBufferView>();
            }
            else if (size == 4 && typeof(T) == typeof(Color))
            {
                var  subarr      = new Uint8Array(4 * elementCount.As <uint>());
                uint subarrindex = 0;

                for (uint i = startIndex.As <uint>(); i < startIndex.As <uint>() + elementCount; i++)
                {
                    var col = data[i].As <Color>();

                    subarr[subarrindex + 0] = col.R;
                    subarr[subarrindex + 1] = col.G;
                    subarr[subarrindex + 2] = col.B;
                    subarr[subarrindex + 3] = col.A;

                    subarrindex += 4;
                }

                arrayBuffer = subarr.As <ArrayBufferView>();
            }
            else
            {
                throw new NotImplementedException();
            }

            if (glFormat == gl.COMPRESSED_TEXTURE_FORMATS)
            {
                gl.compressedTexImage2D(gl.TEXTURE_2D, level, glInternalFormat, w, h, 0, arrayBuffer.As <Int8Array>());
            }
            else
            {
                gl.texImage2D(gl.TEXTURE_2D, level, glInternalFormat, w, h, 0, glFormat, glType, arrayBuffer);
            }

            GraphicsExtensions.CheckGLError();

            // Restore the bound texture.
            if (prevTexture != glTexture)
            {
                gl.bindTexture(gl.TEXTURE_2D, prevTexture);
                GraphicsExtensions.CheckGLError();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Loads a score asynchronously from the given datasource
        /// </summary>
        /// <param name="path">the source path to load the binary file from</param>
        /// <param name="success">this function is called if the Score was successfully loaded from the datasource</param>
        /// <param name="error">this function is called if any error during the loading occured.</param>
        /// <param name="settings">settings for the score import</param>
        public static void LoadScoreAsync(string path, Action <Score> success, Action <Exception> error, Settings settings = null)
        {
            var xhr = new XMLHttpRequest();

            xhr.Open("GET", path, true);
            xhr.ResponseType       = XMLHttpRequestResponseType.ARRAYBUFFER;
            xhr.OnReadyStateChange = (Action)(() =>
            {
                if (xhr.ReadyState == XMLHttpRequest.DONE)
                {
                    object response = xhr.Response;
                    if (xhr.Status == 200 || (xhr.Status == 0 && response.IsTruthy()))
                    {
                        try
                        {
                            ArrayBuffer buffer = xhr.Response;
                            var reader = new Uint8Array(buffer);
                            var score = LoadScoreFromBytes(reader.As <byte[]>(), settings);
                            success(score);
                        }
                        catch (Exception exception)
                        {
                            error(exception);
                        }
                    }
                    // Error handling
                    else if (xhr.Status == 0)
                    {
                        error(new FileLoadException("You are offline!!\n Please Check Your Network.", xhr));
                    }
                    else if (xhr.Status == 404)
                    {
                        error(new FileLoadException("Requested URL not found.", xhr));
                    }
                    else if (xhr.Status == 500)
                    {
                        error(new FileLoadException("Internel Server Error.", xhr));
                    }
                    else if (xhr.StatusText == "parsererror")
                    {
                        error(new FileLoadException("Error.\nParsing JSON Request failed.", xhr));
                    }
                    else if (xhr.StatusText == "timeout")
                    {
                        error(new FileLoadException("Request Time out.", xhr));
                    }
                    else
                    {
                        error(new FileLoadException("Unknow Error: " + xhr.ResponseText, xhr));
                    }
                }
            });
            // IE fallback
            if (xhr.ResponseType != XMLHttpRequestResponseType.ARRAYBUFFER)
            {
                // use VB Loader to load binary array
                dynamic vbArr        = Script.Write <dynamic>("untyped VbAjaxLoader(\"GET\", path)");
                var     fileContents = vbArr.toArray();

                // decode byte array to string
                var data = new StringBuilder();
                var i    = 0;
                while (i < (fileContents.length - 1))
                {
                    data.Append(((char)(fileContents[i])));
                    i++;
                }

                var reader = GetBytesFromString(data.ToString());
                var score  = LoadScoreFromBytes(reader, settings);
                success(score);
            }
            xhr.Send();
        }
Exemplo n.º 5
0
        private void PlatformSetData <T>(CubeMapFace face, int level, Rectangle rect, T[] data, int startIndex, int elementCount)
        {
            var subarr = new Uint8Array(data.As <ArrayBuffer>(), startIndex.As <uint>(), elementCount.As <uint>());

            gl.bindTexture(gl.TEXTURE_CUBE_MAP, this.glTexture);
            GraphicsExtensions.CheckGLError();

            var target = GetGLCubeFace(face);

            if (glFormat == gl.COMPRESSED_TEXTURE_FORMATS)
            {
                gl.compressedTexSubImage2D(target, level, rect.X, rect.Y, rect.Width, rect.Height, glInternalFormat, subarr);
                GraphicsExtensions.CheckGLError();
            }
            else
            {
                gl.texSubImage2D(target, level, rect.X, rect.Y, rect.Width, rect.Height, glFormat, glType, subarr.As <ArrayBufferView>());
                GraphicsExtensions.CheckGLError();
            }
        }
Exemplo n.º 6
0
        public void LoadSoundFontFromUrl(string data)
        {
            var url = data.As <string>();

            Logger.Info("AlphaSynth", "Start loading Soundfont from url " + url);
            var request = new XMLHttpRequest();

            request.Open("GET", url, true);
            request.ResponseType = XMLHttpRequestResponseType.ARRAYBUFFER;
            request.OnLoad       = (Action <Event>)(e =>
            {
                var buffer = new Uint8Array(request.Response);
                _synth.PostMessage(new { cmd = AlphaSynthWebWorker.CmdLoadSoundFontBytes, data = buffer.As <byte[]>() });
            });
            request.OnError = (Action <Event>)(e =>
            {
                Logger.Error("AlphaSynth", "Loading failed: " + e.Member <string>("message"));
                TriggerEvent("soundFontLoadFailed");
            });
            request.OnProgress = (Action <Event>)(e =>
            {
                Logger.Debug("AlphaSynth", "Soundfont downloading: " + e.Member <int>("loaded") + "/" + e.Member <int>("total") + " bytes");
                TriggerEvent("soundFontLoad", new object[] { new
                                                             {
                                                                 loaded = e.Member <int>("loaded"),
                                                                 total  = e.Member <int>("total")
                                                             } });
            });
            request.Send();
        }
Exemplo n.º 7
0
 /// <inheritdoc />
 public void LoadSoundFont(byte[] data)
 {
     if (@typeof(data) == "string")
     {
         var url = data.As <string>();
         Logger.Info("Start loading Soundfont from url " + url);
         var request = new XMLHttpRequest();
         request.open("GET", url, true);
         request.responseType = "arraybuffer";
         request.onload       = e =>
         {
             var buffer = new Uint8Array(request.response.As <ArrayBuffer>());
             _synth.postMessage(new { cmd = AlphaSynthWebWorker.CmdLoadSoundFontBytes, data = buffer.As <byte[]>() });
         };
         request.onerror = e =>
         {
             Logger.Error("Loading failed: " + e.message);
             TriggerEvent("soundFontLoadFailed");
         };
         request.onprogress = e =>
         {
             Logger.Debug("Soundfont downloading: " + e.loaded + "/" + e.total + " bytes");
             TriggerEvent("soundFontLoad", new object[] { new
                                                          {
                                                              loaded = e.loaded,
                                                              total  = e.total
                                                          } });
         };
         request.send();
     }
     else
     {
         _synth.postMessage(new { cmd = AlphaSynthWebWorker.CmdLoadSoundFontBytes, data = data });
     }
 }