Beispiel #1
0
        private void SaveAt(MuseReciever reciever, string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                return;
            }
            if (reciever.Tokens == 0)
            {
                return;
            }

            MidiAsset asset = MidiAsset.CreateInstance <MidiAsset>();

            asset.MidiFile = MuseDecoder.DecodeMuseEncoding(reciever.EncodedMidi);

            //int i = 1;
            //string org = Path.GetDirectoryName(path) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(path);
            //string ext = Path.GetExtension(path);
            //while (File.Exists(path)) {
            //    path = org + i + ext;
            //    i++;
            //        }
            if (File.Exists(path))
            {
                File.Delete(path);
            }
            AssetDatabase.CreateAsset(asset, path);
        }
        public async Task Recieve(CancellationToken cancellation)
        {
            int durration;

            string[]   encoding;
            HttpClient client = MuseNetworkRequest.GetClient();

            lock (threadLock)
            {
                encoding  = (string[])encodedMidi.Clone();
                durration = currentDurration;
            }

            while (durration < totalDurration)
            {
                if (cancellation.IsCancellationRequested)
                {
                    return;
                }

                encoding = await MuseNetworkRequest.MakeMuseRequest(encoding, genre, instruments, temperature, trunication, cancellation);

                if (encoding == null)
                {
                    break;
                }
                else if (encoding.Length == 1 && Equals(encoding[0], "noresponse"))
                {
                    IsNoResponse = true;
                    break;
                }
                durration = MuseDecoder.GetDurration(encoding);

                lock (threadLock)
                {
                    encodedMidi      = encoding;
                    currentDurration = durration;
                }
            }

            client.Dispose();
        }
        public MuseReciever(MidiFile startMelodie, string genre, Instruments instruments, int temperature, int turnication, float length, string startMelodieName = "")
        {
            if (startMelodie != null)
            {
                encodedMidi = MuseEncoder.Encode(startMelodie);
            }
            else
            {
                encodedMidi = new string[0];
            }

            currentDurration = MuseDecoder.GetDurration(encodedMidi);

            this.genre          = genre;
            this.instruments    = instruments;
            this.temperature    = temperature;
            this.trunication    = turnication;
            this.totalDurration = (int)(length * 60 * 1000);

            this.startMelodieName = startMelodieName.Replace("F-" + genre, "");
        }
 public void Play()
 {
     //Debug.Log("Play L: "+encodedMidi.Length);
     //DebugTask();
     MidiPlayer.Play(MuseDecoder.DecodeMuseEncoding(EncodedMidi));
 }