Exemplo n.º 1
0
        private async void XTimelineThumb_OnDrop(object sender, DragEventArgs e)
        {
            var fileList = ((DataObject)e.Data).GetFileDropList();

            if (fileList == null || fileList.Count != 1)
            {
                return;
            }

            var soundFilePath = fileList[0];

            soundFilePath = UIHelper.ConvertToRelativeFilepath(soundFilePath);
            if (!soundFilePath.EndsWith(".mp3") && !soundFilePath.EndsWith(".ogg"))
            {
                MessageBox.Show("You can only drop .mp3, .ogg, and timeline-images here.");
                return;
            }

            var imageFilePath = await GenerateSoundImageInBackground(soundFilePath);

            if (imageFilePath == null)
            {
                Logger.Warn("Creating sound image failed.");
            }

            var bpmMatchResult = Regex.Match(soundFilePath, @"(\d+)bpm");

            if (bpmMatchResult.Success)
            {
                var bpm = (float)Double.Parse(bpmMatchResult.Groups[1].Value);
                if (!Double.IsNaN(bpm))
                {
                    Logger.Info("Setting {0} BPM  from filename..", bpm);
                    XBeatMarker.BPM           = bpm;
                    XBeatMarker.BPMTimeOffset = 0;

                    App.Current.ProjectSettings["Soundtrack.BPM"]       = bpm;
                    App.Current.ProjectSettings["Soundtrack.BPMOffset"] = 0;
                    //App.Current.UpdateRequiredAfterUserInteraction = true;
                    this.InvalidateVisual();
                }
            }

            XTimeImage.SetTimelineImagePath(imageFilePath);
            App.Current.SetProjectSoundFile(soundFilePath);
            Logger.Info("Sound-Image completed");
            App.Current.ProjectSettings.Save();
        }