Exemplo n.º 1
0
        private async void PlayPreview()
        {
#if !DEBUG
            try
#endif
            {
                if (!wavStream.IsValid)
                {
                    wavStream = null;
                    await Task.Run(() => wavStream = HCA.Decode(awbBytes));

                    SetLoopOnStream();
                }

                if (!audioPlayer.HasAudio(wavStream))
                {
                    audioPlayer.SetAudio(wavStream);
                }

                audioPlayer.Play();
            }
#if !DEBUG
            catch (Exception ex)
            {
                MessageBox.Show($"An error occured while processing the PlayPreview command.\n\nDetails:{ex.Message}", $"PlayPreview failed", MessageBoxButton.OK, MessageBoxImage.Error);
            }
#endif
        }
Exemplo n.º 2
0
        private async void InitValues()
        {
            var awbEntry = WaveformWrapper.WrapperRoot.AcbFile.GetAfs2Entry(WaveformWrapper.WaveformRef.AwbId);

            if (awbEntry != null)
            {
                HcaMetadata metadata = new HcaMetadata(awbEntry.bytes);
                LoopEnabled   = metadata.HasLoopData;
                LoopStartMs   = metadata.LoopStartMs;
                LoopEndMs     = metadata.LoopEndMs;
                TrackLengthMs = metadata.Milliseconds + 1000; //Declared length can be slightly too short, so extend it by 1 second
                ValuesChanged();

                if (metadata.ValidHcaFile)
                {
                    awbBytes = awbEntry.bytes;
                    await Task.Run(() => wavStream = HCA.Decode(awbEntry.bytes));

                    SetLoopOnStream();

                    CommandManager.InvalidateRequerySuggested();
                }
            }
            else
            {
                Close();
            }
        }
Exemplo n.º 3
0
        public ActionResult DeleteConfirmed(int id)
        {
            HCA hca = db.HCAs.Find(id);

            db.HCAs.Remove(hca);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 4
0
        //
        // GET: /HCA/Delete/5

        public ActionResult Delete(int id = 0)
        {
            HCA hca = db.HCAs.Find(id);

            if (hca == null)
            {
                return(HttpNotFound());
            }
            return(View(hca));
        }
Exemplo n.º 5
0
 public ActionResult Edit(HCA hca)
 {
     if (ModelState.IsValid)
     {
         db.Entry(hca).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(hca));
 }
Exemplo n.º 6
0
        public ActionResult Create(HCA hca)
        {
            if (ModelState.IsValid)
            {
                db.HCAs.Add(hca);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(hca));
        }
Exemplo n.º 7
0
        private void LoadAndConvertAudioFile()
        {
            try
            {
                if (File.Exists(AudioFilePath))
                {
                    byte[] bytes = File.ReadAllBytes(AudioFilePath);

                    if (System.IO.Path.GetExtension(AudioFilePath).ToLower() == ".hca")
                    {
                        HcaBytes             = bytes;
                        ConversionSuccessful = true;
                    }
                    else if (System.IO.Path.GetExtension(AudioFilePath).ToLower() == ".wav")
                    {
                        var hcaBytes = HCA.Encode(bytes);
                        hcaBytes = HCA.EncodeLoop(hcaBytes, Loop);

                        HcaBytes             = hcaBytes;
                        ConversionSuccessful = true;
                    }
                    else if (System.IO.Path.GetExtension(AudioFilePath).ToLower() == ".mp3" ||
                             System.IO.Path.GetExtension(AudioFilePath).ToLower() == ".wma" ||
                             System.IO.Path.GetExtension(AudioFilePath).ToLower() == ".aac")
                    {
                        var wavBytes = Audio.CommonFormatsConverter.ConvertToWav(AudioFilePath);
                        var hcaBytes = HCA.Encode(wavBytes);
                        hcaBytes = HCA.EncodeLoop(hcaBytes, Loop);

                        HcaBytes             = hcaBytes;
                        ConversionSuccessful = true;
                    }
                    else
                    {
                        ConversionSuccessful = false;
                        throw new InvalidDataException($"The selected audio file is not a supported format ({System.IO.Path.GetExtension(AudioFilePath)}.");
                    }
                }
            }
            catch (Exception ex)
            {
                ConversionSuccessful = false;
                ConvertException     = ex;
            }
        }
Exemplo n.º 8
0
        private async void PlayTrack(bool loop)
        {
            var track = GetSelectedTrack(TrackType.Track);
            var cue   = GetSelectedCue();

            if (track != null && cue != null)
            {
                if (track.WaveformWrapper != null)
                {
                    var afs2Entry = AcbFile.AcbFile.GetAfs2Entry((track.WaveformWrapper.WaveformRef != null) ? track.WaveformWrapper.WaveformRef.AwbId : ushort.MaxValue);

                    if (afs2Entry != null)
                    {
                        audioPlayer.Stop();

                        await Task.Run(() =>
                        {
                            switch (track.WaveformWrapper.WaveformRef.EncodeType)
                            {
                            case EncodeType.HCA:
                            case EncodeType.HCA_ALT:
                                audioPlayer.SetAudio(HCA.Decode(afs2Entry.bytes));
                                break;

                            case EncodeType.ADX:
                                audioPlayer.SetAudio(ADX.Decode(afs2Entry.bytes));
                                break;

                            case EncodeType.ATRAC9:
                                audioPlayer.SetAudio(AT9.Decode(afs2Entry.bytes));
                                break;

                            case EncodeType.BCWAV:
                                audioPlayer.SetAudio(BC_WAV.Decode(afs2Entry.bytes));
                                break;

                            case EncodeType.DSP:
                                audioPlayer.SetAudio(DSP.Decode(afs2Entry.bytes));
                                break;
                            }
                        });

                        //Set volume
                        float cueBaseVolume    = cue.GetBaseVolume();
                        float cueRandom        = cue.GetRandomVolume();
                        float trackBasekVolume = track.GetBaseVolume();
                        float trackRandom      = track.GetRandomVolume();

                        float cueVolume   = cueBaseVolume + Xv2CoreLib.Random.Range(0, cueRandom);
                        float trackVolume = trackBasekVolume + Xv2CoreLib.Random.Range(0, trackRandom);
                        float finalVolume = ((trackVolume * cueVolume) > 1f) ? 1f : trackVolume * cueVolume;

                        audioPlayer.SetVolume(finalVolume);

                        //Set loop
                        if (loop)
                        {
                            if (track.WaveformWrapper.WaveformRef.EncodeType == EncodeType.HCA || track.WaveformWrapper.WaveformRef.EncodeType == EncodeType.HCA_ALT)
                            {
                                HcaMetadata meta = new HcaMetadata(afs2Entry.bytes);

                                if (meta.HasLoopData)
                                {
                                    audioPlayer.SetLoop(meta.LoopStartMs, meta.LoopEndMs);
                                }
                                else
                                {
                                    audioPlayer.SetLoop();
                                }
                            }
                            else
                            {
                                audioPlayer.SetLoop();
                            }
                        }

                        //Play
                        audioPlayer.Play();

                        //Force Update UI
                        CommandManager.InvalidateRequerySuggested();
                    }
                }
            }
        }