Пример #1
0
 public void GetNext(byte[] buffer)
 {
     CrossPlatformHelper.Assert(sampleBuffer.Length * 2 == buffer.Length, "Output buffer length must equal RawBufferSize!");
     Array.Clear(sampleBuffer, 0, sampleBuffer.Length);
     FillWorkingBuffer();
     ConvertWorkingBuffer(buffer, sampleBuffer);
 }
Пример #2
0
        public void LoadPatch(string patchFile, int bankNumber, int startRange, int endRange)
        {
            string patchName = Path.GetFileNameWithoutExtension(patchFile);
            string directory = Path.GetDirectoryName(patchFile);
            //check for duplicate patch
            PatchAsset patchAsset = assets.FindPatch(patchName);

            if (patchAsset != null)
            {
                AssignPatchToBank(patchAsset.Patch, bankNumber, startRange, endRange);
                return;
            }
            //load patch here
            Patch patch;

            switch (Path.GetExtension(patchFile).ToLower())
            {
            case ".patch":
                patch = LoadMyPatch(CrossPlatformHelper.OpenResource(patchFile), patchName, directory);
                break;

            case ".sfz":
                patch = LoadSfzPatch(CrossPlatformHelper.OpenResource(patchFile), patchName, directory);
                break;

            default:
                throw new InvalidDataException("The patch: " + Path.GetFileName(patchFile) + " is unsupported.");
            }
            AssignPatchToBank(patch, bankNumber, startRange, endRange);
            assets.PatchAssetList.Add(new PatchAsset(patchName, patch));
        }
Пример #3
0
        public SampleDataAsset(string name, WaveFile wave)
        {
            if (name == null)
            {
                throw new ArgumentNullException("An asset must be given a valid name.");
            }
            assetName = name;
            SamplerChunk smpl = wave.FindChunk <SamplerChunk>();

            if (smpl != null)
            {
                sampleRate = (int)(44100.0 * (1.0 / (smpl.SamplePeriod / 22675.0)));
                rootKey    = (short)smpl.UnityNote;
                tune       = (short)(smpl.PitchFraction * 100);
                if (smpl.Loops.Length > 0)
                {
                    CrossPlatformHelper.Assert(smpl.Loops[0].Type == SamplerChunk.SampleLoop.LoopType.Forward, "Warning: Unsupported LoopType in " + assetName);
                    loopStart = smpl.Loops[0].Start;
                    loopEnd   = smpl.Loops[0].End + smpl.Loops[0].Fraction + 1;
                }
            }
            else
            {
                sampleRate = wave.Format.SampleRate;
            }
            sampleData = WaveHelper.GetSampleData(wave, audioChannels);
            start      = 0;
            end        = sampleData.Length;
        }
Пример #4
0
 //--Methods
 public SoundFont(string fileName)
 {
     if (!Path.GetExtension(fileName).ToLower().Equals(".sf2"))
     {
         throw new InvalidDataException("Invalid soundfont : " + fileName + ".");
     }
     Load(CrossPlatformHelper.OpenResource(fileName));
 }
Пример #5
0
        //--Properties

        //--Methods
        public WaveFileReader(string fileName)
        {
            if (!Path.GetExtension(fileName).ToLower().Equals(".wav") || !CrossPlatformHelper.ResourceExists(fileName))
            {
                throw new InvalidDataException("Invalid wave file : " + fileName);
            }
            reader = new BinaryReader(CrossPlatformHelper.OpenResource(fileName));
        }
Пример #6
0
 public void Write(float[] left_buffer, float[] right_buffer)
 {
     CrossPlatformHelper.Assert(channels == 2, "Mismatched channels! Output expects : " + channels + " channels.");
     if (left_buffer == null || right_buffer == null)
     {
         throw new ArgumentException("One or more input buffers were null!");
     }
     Write(WaveHelper.GetRawData(left_buffer, right_buffer, bits));
 }
Пример #7
0
 //--Methods
 public WaveFileWriter(int sampleRate, int channels, int bitsPerSample, string fileName)
 {
     this.sRate    = sampleRate;
     this.channels = channels;
     this.bits     = bitsPerSample;
     this.fname    = fileName;
     this.ftemp    = GetTemporaryFileName(Path.GetDirectoryName(fileName));
     this.writer   = new BinaryWriter(CrossPlatformHelper.CreateResource(ftemp));
 }
Пример #8
0
        public void AddJob(string username, string password, string taskId, int jobId, int priority, string jobXml)
        {
            //decode base64
            //jobXml = Convert.FromBase64String(jobXml).ToString();
            //Html decode the xml
            jobXml = HttpUtility.HtmlDecode(jobXml);

            CrossPlatformHelper.AddJob(Manager, new SecurityCredentials(username, password), taskId, jobId, priority, jobXml);
        }
        public void StartApp()
        {
            CrossPlatformHelper <IImageResizer> .AddImplementation(new ImageResizer());

            CrossPlatformHelper <ICameraPreview> .AddImplementation(new CameraPreview());

            CrossCurrentActivity.Current.Init(this, SavedInstanceState);
            global::Xamarin.Forms.Forms.Init(this, SavedInstanceState);
            LoadApplication(new App());
        }
Пример #10
0
        //
        // This method is invoked when the application has loaded and is ready to run. In this
        // method you should instantiate the window, load the UI into it and then make the window
        // visible.
        //
        // You have 17 seconds to return from this method, or iOS will terminate your application.
        //
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            global::Xamarin.Forms.Forms.Init();
            FFImageLoading.Forms.Platform.CachedImageRenderer.Init();
            CrossPlatformHelper <ICameraPreview> .AddImplementation(new CameraPreview());

            LoadApplication(new App());

            return(base.FinishedLaunching(app, options));
        }
        public MainPage()
        {
            this.InitializeComponent();
            FFImageLoading.Forms.Platform.CachedImageRenderer.Init();
            CrossPlatformHelper <IImageResizer> .AddImplementation(new ImageResizer());

            CrossPlatformHelper <ICameraPreview> .AddImplementation(new CameraPreview());

            LoadApplication(new ObjectDetectionApp.App());
        }
Пример #12
0
        private static string GetTemporaryFileName(string path)
        {
            int    x        = 0;
            string baseName = path + "Raw_Wave_Data_";

            while (CrossPlatformHelper.ResourceExists(baseName + x + ".dat"))
            {
                x++;
            }
            return(baseName + x + ".dat");
        }
Пример #13
0
        public static float[] Deinterleave(float[] data, int channelCount, int channel)
        {
            CrossPlatformHelper.Assert(channel >= 0 && channel < channelCount, "Channel must be non-negative and less than the channel count.");
            CrossPlatformHelper.Assert(data != null && data.Length % channelCount == 0, "The data provided is invalid or channel count is incorrect.");

            float[] sampleData = new float[data.Length / channelCount];

            for (int x = 0; x < sampleData.Length; x++)
            {
                sampleData[x] = data[x * channelCount + channel];
            }
            return(sampleData);
        }
Пример #14
0
        public void LoadSampleAsset(string assetName, string patchName, string directory)
        {
            string assetNameWithoutExtension;
            string extension;

            if (Path.HasExtension(assetName))
            {
                assetNameWithoutExtension = Path.GetFileNameWithoutExtension(assetName);
                extension = Path.GetExtension(assetName).ToLower();
            }
            else
            {
                assetNameWithoutExtension = assetName;
                assetName += ".wav"; //assume .wav
                extension  = ".wav";
            }
            if (FindSample(assetNameWithoutExtension) == null)
            {
                string waveAssetPath;
                if (CrossPlatformHelper.ResourceExists(assetName))
                {
                    waveAssetPath = assetName; //ex. "asset.wav"
                }
                else if (CrossPlatformHelper.ResourceExists(directory + Path.DirectorySeparatorChar + assetName))
                {
                    waveAssetPath = directory + Path.DirectorySeparatorChar + assetName; //ex. "C:\asset.wav"
                }
                else if (CrossPlatformHelper.ResourceExists(directory + "/SAMPLES/" + assetName))
                {
                    waveAssetPath = directory + "/SAMPLES/" + assetName; //ex. "C:\SAMPLES\asset.wav"
                }
                else if (CrossPlatformHelper.ResourceExists(directory + Path.DirectorySeparatorChar + patchName + Path.DirectorySeparatorChar + assetName))
                {
                    waveAssetPath = directory + Path.DirectorySeparatorChar + patchName + Path.DirectorySeparatorChar + assetName; //ex. "C:\Piano\asset.wav"
                }
                else
                {
                    throw new IOException("Could not find sample asset: (" + assetName + ") required for patch: " + patchName);
                }
                using (BinaryReader reader = new BinaryReader(CrossPlatformHelper.OpenResource(waveAssetPath)))
                {
                    switch (extension)
                    {
                    case ".wav":
                        sampleAssets.Add(new SampleDataAsset(assetNameWithoutExtension, WaveFileReader.ReadWaveFile(reader)));
                        break;
                    }
                }
            }
        }
Пример #15
0
        public string SubmitTask(string username, string password, string taskXml)
        {
            //decode base64
            //taskXml = Convert.FromBase64String(taskXml).ToString();
            //Html decode the xml
            taskXml = HttpUtility.HtmlDecode(taskXml);

            logger.Debug("Task XML recvd = " + taskXml);
            string temp = null;

            try
            {
                temp = CrossPlatformHelper.CreateTask(Manager, new SecurityCredentials(username, password), taskXml);
            }
            catch (Exception e)
            {
                logger.Error("Error Submitting task...", e);
            }
            return(temp);
        }
Пример #16
0
        public void LoadBank(string bankFile)
        {
            bank.Clear();
            assets.PatchAssetList.Clear();
            assets.SampleAssetList.Clear();
            bankName = string.Empty;
            comment  = string.Empty;
            switch (Path.GetExtension(bankFile).ToLower())
            {
            case ".bank":
                bankName = Path.GetFileNameWithoutExtension(bankFile);
                LoadMyBank(CrossPlatformHelper.OpenResource(bankFile));
                break;

            case ".sf2":
                bankName = "SoundFont";
                LoadSf2(CrossPlatformHelper.OpenResource(bankFile));
                break;
            }
            assets.PatchAssetList.TrimExcess();
            assets.SampleAssetList.TrimExcess();
        }
Пример #17
0
        public void Close()
        {
            if (writer == null)
            {
                return;
            }
            writer.Close();
            writer = null;
            BinaryWriter bw2 = new BinaryWriter(CrossPlatformHelper.CreateResource(fname));

            bw2.Write((Int32)1179011410);
            bw2.Write((Int32)44 + length - 8);
            bw2.Write((Int32)1163280727);
            bw2.Write((Int32)544501094);
            bw2.Write((Int32)16);
            bw2.Write((Int16)1);
            bw2.Write((Int16)channels);
            bw2.Write((Int32)sRate);
            bw2.Write((Int32)(sRate * channels * (bits / 8)));
            bw2.Write((Int16)(channels * (bits / 8)));
            bw2.Write((Int16)bits);
            bw2.Write((Int32)1635017060);
            bw2.Write((Int32)length);
            using (BinaryReader br = new BinaryReader(CrossPlatformHelper.OpenResource(ftemp)))
            {
                byte[] buffer = new byte[1024];
                int    count  = br.Read(buffer, 0, buffer.Length);
                while (count > 0)
                {
                    bw2.Write(buffer, 0, count);
                    count = br.Read(buffer, 0, buffer.Length);
                }
            }
            bw2.Close();
            CrossPlatformHelper.RemoveResource(ftemp);
        }
Пример #18
0
 public SfzReader(string sfzFile)
 {
     name = Path.GetFileNameWithoutExtension(sfzFile);
     Load(CrossPlatformHelper.OpenResource(sfzFile));
 }
Пример #19
0
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(DefaultErrorHandler);

            Console.WriteLine("\nAlchemi [.NET Grid Computing Framework]");
            Console.WriteLine("http://www.alchemi.net\n");

            Console.WriteLine("Job Submitter v{0}", Utils.AssemblyVersion);

            IManager            manager;
            SecurityCredentials sc;

            if (args.Length < 4)
            {
                Usage();
                return;
            }

            try
            {
                manager = (IManager)GNode.GetRemoteRef(new RemoteEndPoint(args[0], int.Parse(args[1]), RemotingMechanism.TcpBinary));
                manager.PingManager();
                sc = new SecurityCredentials(args[2], args[3]);
                manager.AuthenticateUser(sc);
                Console.Write("Connected to Manager at {0}:{1}\n", args[0], args[1]);
            }
            catch (Exception e)
            {
                Error("Could not connect to Manager", e);
                return;
            }

            Aliases aliases = Aliases.FromFile(Path.Combine(System.Windows.Forms.Application.StartupPath, "aliases.dat"));

            string[] cmd;
            bool     interactive;

            if (args.Length > 4)
            {
                cmd = new string[args.Length - 4];
                for (int i = 0; i < args.Length - 4; i++)
                {
                    cmd[i] = args[i + 4];
                }
                interactive = false;
            }
            else
            {
                cmd         = new string[] { "" };
                interactive = true;
            }

            while (true)
            {
                if (interactive)
                {
                    Console.Write("\n> ");
                    string line = Console.ReadLine();
                    cmd    = line.Split();
                    cmd[0] = cmd[0].ToLower();
                }

                try
                {
                    string appId;

                    switch (cmd[0])
                    {
                    case "st":
                    case "submittask":     // taskXmlFile
                        string task = EmbedFiles(Utils.ReadStringFromFile(cmd[1]));
                        appId = CrossPlatformHelper.CreateTask(manager, sc, task);
                        string newAlias = aliases.NewAlias(appId);
                        try
                        {
                            WriteLine("Task submitted (alias = {1}).", appId, newAlias);
                        }
                        catch
                        {
                        }
                        break;

                    case "gfj":
                    case "getfinishedjobs":     // alias, (directory, default=".")
                        appId = (string)aliases.Table[cmd[1]];

                        string taskDir = cmd.Length > 2 ? cmd[2] : ".";

                        string      taskXml = CrossPlatformHelper.GetFinishedJobs(manager, sc, appId);
                        XmlDocument fin     = new XmlDocument();
                        fin.LoadXml(taskXml);

                        WriteLine("Got {0} job(s).", fin.SelectNodes("task/job").Count);
                        Console.WriteLine("Job XML: \n" + taskXml);

                        foreach (XmlNode outputFileNode in fin.SelectNodes("task/job/output/embedded_file"))
                        {
                            //string jobDir = string.Format("{0}\\job_{1}", taskDir, outputFileNode.ParentNode.ParentNode.Attributes["id"].Value);
                            string jobDir = taskDir;
                            if (!Directory.Exists(jobDir))
                            {
                                Directory.CreateDirectory(jobDir);
                            }

                            //if (outputFileNode.InnerText != "")
                            //{
                            string filePath = string.Format("{0}\\{1}", jobDir, outputFileNode.Attributes["name"].Value);
                            Utils.WriteBase64EncodedToFile(
                                filePath,
                                outputFileNode.InnerText
                                );
                            WriteLine("Wrote file {0} for job {1}.", filePath, outputFileNode.ParentNode.ParentNode.Attributes["id"].Value);
                            // }
                        }
                        break;

                    // TODO: (allow option to specify alias)
                    case "ct":
                    case "createtask":     // no arguments
                        appId = manager.Owner_CreateApplication(sc);
                        WriteLine(appId);
                        WriteLine("Task created (alias = {1}).", appId, aliases.NewAlias(appId));
                        break;

                    case "aj":
                    case "addjob":     // alias, jobXml, jobId, (priority, default=0)
                        appId = (string)aliases.Table[cmd[1]];
                        int priority = 0;
                        if (cmd.Length > 4)
                        {
                            priority = int.Parse(cmd[4]);
                        }
                        CrossPlatformHelper.AddJob(manager, sc, appId, int.Parse(cmd[3]), priority, EmbedFiles(Utils.ReadStringFromFile(cmd[2])));
                        WriteLine("Job added.");
                        break;

                    /*
                     * case "listapps": // no arguments
                     *  DataTable apps = manager.Owner_GetLiveApplicationList(null).Tables[0];
                     *  apps.Columns.Add("alias", typeof(string));
                     *  apps.Columns.Add("state_disp", typeof(string));
                     *  foreach (DataRow app in apps.Rows)
                     *  {
                     *      string alias = aliases.GetAlias(app["application_id"].ToString());
                     *      if (alias == "")
                     *      {
                     *          alias = aliases.NewAlias(app["application_id"].ToString());
                     *      }
                     *      app["alias"] = alias;
                     *      app["state_disp"] = Enum.Parse(typeof(ApplicationState), app["state"].ToString()).ToString();
                     *  }
                     *  Console.WriteLine(ConsoleFormatter.FormatDataTable(
                     *      apps,
                     *      new string[] {"alias", "state_disp", "time_created"},
                     *      new string[] {"alias", "state", "time_created"}
                     *      ));
                     *  break;
                     *
                     * case "listthreads": // alias
                     *  appId = (string) aliases.Table[cmd[1]];
                     *  DataTable threads = manager.Owner_GetThreadList(null, appId).Tables[0];
                     *
                     *  threads.Columns.Add("state_disp", typeof(string));
                     *  foreach (DataRow thread in threads.Rows)
                     *  {
                     *      thread["state_disp"] = Enum.Parse(typeof(ThreadState), thread["state"].ToString());
                     *  }
                     *
                     *  Console.WriteLine(ConsoleFormatter.FormatDataTable(
                     *      threads,
                     *      new string[] {"thread_id", "state_disp", "time_started", "time_finished"},
                     *      new string[] {"thread_id", "state", "time_started", "time_finished"}
                     *      ));
                     *  break;
                     *
                     * case "getthreadstate": // alias, threadId
                     *  appId = (string) aliases.Table[cmd[1]];
                     *  ThreadState state = manager.Owner_GetThreadState(null, new ThreadIdentifier(appId, int.Parse(cmd[2])));
                     *  WriteLine("State = {0}.", state);
                     *  break;
                     *
                     * case "abortthread": // alias, threadId
                     *  appId = (string) aliases.Table[cmd[1]];
                     *  manager.Owner_AbortThread(null, new ThreadIdentifier(appId, int.Parse(cmd[2])));
                     *  WriteLine("Thread aborted.");
                     *  break;
                     *
                     * case "stoptask": // alias
                     *  appId = (string) aliases.Table[cmd[1]];
                     *  manager.Owner_StopApplication(null, appId);
                     *  WriteLine("Task stopped.");
                     *  break;
                     *
                     */

                    case "h":
                    case "help":
                    case "?":
                        if (cmd.Length == 2)
                        {
                            Usage(cmd[1]);
                        }
                        else
                        {
                            Usage();
                        }
                        break;

                    case "quit":
                    case "q":
                    case "exit":
                    case "x":
                        return;

                    default:
                        Error("Unknown command '{0}'", cmd[0]);
                        break;
                    }
                }
                catch (Exception e)
                {
                    Error("Incorrect syntax or parameter (" + e.Message.ToString() + ")");
                }

                if (!interactive)
                {
                    return;
                }
            }
        }
Пример #20
0
 public MidiFile(string fileName)
     : this(CrossPlatformHelper.OpenResource(fileName))
 {
 }
Пример #21
0
 public string CreateTask(string username, string password)
 {
     return(CrossPlatformHelper.CreateTask(Manager, new SecurityCredentials(username, password)));
 }
Пример #22
0
 public string GetFailedJobException(string username, string password, string taskId, int jobId)
 {
     return(CrossPlatformHelper.GetFailedThreadException(Manager, new SecurityCredentials(username, password), new ThreadIdentifier(taskId, jobId)));
 }
Пример #23
0
 public void AbortJob(string username, string password, string taskId, int jobId)
 {
     CrossPlatformHelper.AbortJob(Manager, new SecurityCredentials(username, password), new ThreadIdentifier(taskId, jobId));
 }
Пример #24
0
 public void AbortTask(string username, string password, string taskId)
 {
     CrossPlatformHelper.AbortTask(Manager, new SecurityCredentials(username, password), taskId);
 }
Пример #25
0
 public int GetApplicationState(string username, string password, string taskId)
 {
     return(CrossPlatformHelper.GetApplicationState(Manager, new SecurityCredentials(username, password), taskId));
 }
Пример #26
0
 public string GetFinishedJobs(string username, string password, string taskId)
 {
     return(CrossPlatformHelper.GetFinishedJobs(Manager, new SecurityCredentials(username, password), taskId));
 }