コード例 #1
0
        public Neg_BufferPositions(int _BufferLen, IRecording p_recordingObj)
        {
            _PositionsBuffer.Clear();
            BufferLen = _BufferLen;

            _recordingObj = p_recordingObj;
        }
コード例 #2
0
 /// <summary>Adds a barcode to the request.</summary>
 /// <param name="recording">The recording to which <paramref name="isrcs"/> should be added.</param>
 /// <param name="isrcs">One or more (valid) ISRCs to add to the recording.</param>
 /// <returns>This submission request.</returns>
 public IsrcSubmission Add(IRecording recording, params string[] isrcs)
 {
     if (recording == null || isrcs == null || isrcs.Length == 0)
     {
         return(this);
     }
     return(this.Add(recording.MbId, isrcs));
 }
コード例 #3
0
ファイル: RecordingActor.cs プロジェクト: tdwalther/AkkaTest
        public RecordingActor(IRecording rec)
        {
            _irecord = rec;

            Receive <StringMessage>(msg =>
            {
                _irecord.Record($"{msg.Message}");
            });
        }
コード例 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="recognition"></param>
        /// <param name="recording"></param>
        /// <param name="exceptionsBag"></param>
        /// <param name="cancellationToken"></param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="ArgumentException"></exception>
        /// <returns></returns>
        public static async Task BindRecordingAsync(
            this IStreamingRecognition recognition,
            IRecording recording,
            ExceptionsBag?exceptionsBag         = null,
            CancellationToken cancellationToken = default)
        {
            recognition = recognition ?? throw new ArgumentNullException(nameof(recognition));
            recording   = recording ?? throw new ArgumentNullException(nameof(recording));

            if (recording.Settings.Format is not AudioFormat.Raw)
            {
                if (!recording.Header.Any())
                {
                    throw new ArgumentException("recording.Header is empty.");
                }

                await recognition.WriteAsync(recording.Header, cancellationToken).ConfigureAwait(false);
            }

            if (recording.Data.Any())
            {
                await recognition.WriteAsync(recording.Data, cancellationToken).ConfigureAwait(false);
            }

            async void OnDataReceived(object?_, byte[] bytes)
            {
                try
                {
                    await recognition.WriteAsync(bytes, cancellationToken).ConfigureAwait(false);
                }
                catch (Exception exception)
                {
                    exceptionsBag?.OnOccurred(exception);
                }
            }

            void OnStopped(object?o, byte[] bytes)
            {
                try
                {
                    recording.DataReceived -= OnDataReceived;
                    recording.Stopped      -= OnStopped;
                }
                catch (Exception exception)
                {
                    exceptionsBag?.OnOccurred(exception);
                }
            }

            recording.DataReceived += OnDataReceived;
            recording.Stopped      += OnStopped;
        }
コード例 #5
0
        /// <summary>
        /// Saves the <paramref name="recording"/> to the file.
        /// </summary>
        /// <param name="recording">The recording that should be saved.</param>
        public void SaveRecording(IRecording recording)
        {
            if (recording == null)
            {
                throw new ArgumentNullException(nameof(recording));
            }

            var serializedRecording = Serialize(recording);

            // Write the serialized recording to the specified file.
            var file = new JsonEntityFile <SerializedRecording>(recording.FilePath, _fileSystem);

            file.WriteEntity(serializedRecording);
        }
コード例 #6
0
ファイル: RecordingExtensions.cs プロジェクト: H-Core/H.Core
        /// <summary>
        /// Waits <seealso cref="IRecording.Stopped"/> events. <br/>
        /// Can be used with <seealso cref="StopWhenSilence"/> extension.
        /// </summary>
        /// <param name="recording"></param>
        /// <param name="cancellationToken"></param>
        public static async Task WaitStopAsync(
            this IRecording recording,
            CancellationToken cancellationToken = default)
        {
            recording = recording ?? throw new ArgumentNullException(nameof(recording));

            var source = new TaskCompletionSource <bool>();

            using var registration = cancellationToken.Register(() => source.TrySetCanceled());
            recording.Stopped     += (_, _) =>
            {
                source.TrySetResult(true);
            };

            await source.Task.ConfigureAwait(false);
        }
コード例 #7
0
        private async Task <bool> ActionPerformed(int actionPerformed)
        {
            try
            {
                if (actionPerformed == Constants.ACTION_PERFORMED_RECORD)
                {
                    this.recording = new Recording();
                }

                switch (actionPerformed)
                {
                case Constants.ACTION_PERFORMED_RECORD:
                    await recording.Record();

                    break;

                case Constants.ACTION_PERFORMED_STOP:
                    await recording.Stop(Dispatcher);

                    break;

                case Constants.ACTION_PERFORMED_DISPLAY_CREATE_FILES:
                    StorageFile audio = await recording.DisplayRecording();

                    BuildAudio(audio);
                    break;

                case Constants.ACTION_PERFORMED_PLAY_CREATED_FILES:
                    await PlayDirectory();

                    break;

                default:
                    throw new Exception("Unknown Action Performed - actionPerformed: " + actionPerformed.ToString());
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return(true); //HACK!
        }
コード例 #8
0
        /// <summary>
        /// Converts the <paramref name="recording"/> to the serialized version.
        /// </summary>
        /// <param name="recording">The un-serialized version of the recording.</param>
        /// <returns>Returns the serialized version of the <paramref name="recording"/>.</returns>
        private SerializedRecording Serialize(IRecording recording)
        {
            if (recording.Actions == null)
            {
                throw new InvalidDataException("Unable to serialize the object because it is invalid.");
            }

            return(new SerializedRecording()
            {
                FilePath = recording.FilePath ?? throw new InvalidDataException("Unable to serialize the object because it is invalid."),
                Date = recording.Date,
                Zones = recording.Zones.OfType <ClickZone>()?.ToList() ?? throw new InvalidDataException("Unable to serialize the object because it is invalid."),
                RecordingStarts = recording.Actions.OfType <RecordedStart>().ToList(),
                RecordingStops = recording.Actions.OfType <RecordedStop>().ToList(),
                KeyboardButtonPresses = recording.Actions.OfType <RecordedKeyboardButtonPress>().ToList(),
                KeyboardButtonReleases = recording.Actions.OfType <RecordedKeyboardButtonRelease>().ToList(),
                MouseButtonPresses = recording.Actions.OfType <RecordedMouseButtonPress>().ToList(),
                MouseButtonReleases = recording.Actions.OfType <RecordedMouseButtonRelease>().ToList(),
                MouseMoves = recording.Actions.OfType <RecordedMouseMove>().ToList()
            });
コード例 #9
0
        public MainPage()
        {
            try
            {
                this.InitializeComponent();

                recording                = new Recording();
                dispatcherTimer          = new DispatcherTimer();
                dispatcherTimer.Tick    += DispatcherTimer_Tick;
                dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
                dispatcherTimer.Start();

                ApplicationView.PreferredLaunchViewSize      = new Size(1000, 300);
                ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize;
            }
            catch (Exception e)
            {
                throw e;
            }
        }
コード例 #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="recording"></param>
        /// <param name="settings"></param>
        public static IRecording WithPlayback(this IRecording recording, AudioSettings?settings = null)
        {
            recording = recording ?? throw new ArgumentNullException(nameof(recording));
            settings ??= new AudioSettings();

            var provider = new BufferedWaveProvider(new WaveFormat(settings.Rate, settings.Bits, settings.Channels));

#pragma warning disable CA2000
            var output = new WaveOutEvent();
#pragma warning restore CA2000
            output.Init(provider);
            output.Play();

            recording.DataReceived += (_, bytes) =>
            {
                provider.AddSamples(bytes, 0, bytes.Length);
            };
            recording.Disposed += (_, _) => output.Dispose();

            return(recording);
        }
コード例 #11
0
ファイル: RecordingExtensions.cs プロジェクト: H-Core/H.Core
        /// <summary>
        /// Stop when values for <paramref name="silenceInMilliseconds"></paramref> of
        /// <paramref name="bufferInMilliseconds"/> will be lower than <paramref name="threshold"></paramref>. <br/>
        /// NAudioRecorder produces 100 DataReceived events per seconds. <br/>
        /// It can be set up by NAudioRecorder.Delay property. <br/>
        /// </summary>
        /// <param name="recording"></param>
        /// <param name="bufferInMilliseconds"></param>
        /// <param name="silenceInMilliseconds"></param>
        /// <param name="threshold"></param>
        /// <param name="exceptions"></param>
        public static IRecording StopWhenSilence(
            this IRecording recording,
            int bufferInMilliseconds  = 3000,
            int silenceInMilliseconds = 2500,
            double threshold          = 0.02,
            ExceptionsBag?exceptions  = null)
        {
            recording = recording ?? throw new ArgumentNullException(nameof(recording));

            var delay         = (int)recording.Settings.Delay.TotalMilliseconds;
            var bufferSize    = bufferInMilliseconds / delay;
            var requiredCount = silenceInMilliseconds / delay;

            var detector = new SilenceDetector(recording.Settings, bufferSize, requiredCount, threshold);

            detector.Detected += async(_, _) =>
            {
                try
                {
                    await recording.StopAsync().ConfigureAwait(false);
                }
                catch (Exception exception)
                {
                    exceptions?.OnOccurred(exception);
                }
            };
            recording.DataReceived += (_, bytes) =>
            {
                try
                {
                    detector.Write(bytes);
                }
                catch (Exception exception)
                {
                    exceptions?.OnOccurred(exception);
                }
            };

            return(recording);
        }
コード例 #12
0
 public static void Assign(IConfig config, ISettings settings, IThemes themes, IBackgroundMusic backgroundMusic,
                           IDrawing draw, IGraphics graphics, IFonts fonts, ILanguage language, IGame game, IProfiles profiles, IRecording record,
                           ISongs songs, IVideo video, ISound sound, ICover cover, IDataBase dataBase, IControllers controller, IPlaylist playlist)
 {
     Config          = config;
     Settings        = settings;
     Themes          = themes;
     BackgroundMusic = backgroundMusic;
     Drawing         = draw;
     Graphics        = graphics;
     Fonts           = fonts;
     Language        = language;
     Game            = game;
     Profiles        = profiles;
     Record          = record;
     Songs           = songs;
     Video           = video;
     Sound           = sound;
     Cover           = cover;
     DataBase        = dataBase;
     Controller      = controller;
     Playlist        = playlist;
 }
コード例 #13
0
        public async Task <Dictionary <string, object> > GetRecordingByMBID(Guid MBID)          // Returns exactly one recording's metadata by it's ID
        {
            Query      query     = new Query("TrackTracker", "0.1Alpha", "*****@*****.**"); // TODO: not this mail / version
            IRecording recording = await query.LookupRecordingAsync(MBID,
                                                                    Include.Releases& Include.Tags& Include.Artists& Include.DiscIds& Include.Labels& Include.Media& Include.UserTags);

            Dictionary <string, object> result = new Dictionary <string, object>();

            // JSON conversion tends to be buggy, so we null check everyting

            // Checking album title
            if (recording.Releases != null && recording.Releases.Count > 0)
            {
                if (recording.Releases[0].Title != null)
                {
                    result.Add("Album", recording.Releases[0].Title); // TODO: accepting the first release might be improved
                }
            }

            // Checking album artists
            if (recording.ArtistCredit != null && recording.ArtistCredit.Count > 0)
            {
                List <string> sbArt     = new List <string>();
                List <string> sbArtSort = new List <string>();

                foreach (INameCredit artistCredit in recording.ArtistCredit)
                {
                    if (artistCredit.Artist != null)
                    {
                        if (artistCredit.Artist.Name != null)
                        {
                            sbArt.Add(artistCredit.Artist.Name);
                        }
                        if (artistCredit.Artist.SortName != null)
                        {
                            sbArtSort.Add(artistCredit.Artist.Name);
                        }
                    }
                }
                result.Add("AlbumArtists", sbArt.ToArray());
                result.Add("AlbumArtistsSort", sbArtSort.ToArray());

                if (recording.ArtistCredit.Count == 1) // If we only have exactly 1 artist, we accept its MBID
                {
                    // TODO: improve later
                    result.Add("MusicBrainzArtistId", recording.ArtistCredit[0].Artist.MbId.ToString());
                }
            }

            // Checking track MBID
            if (recording.MbId != null)
            {
                result.Add("MusicBrainzTrackId", recording.MbId.ToString());
            }

            // Checking other data
            if (recording.Releases != null && recording.Releases.Count > 0) // TODO: accepting the first release might be improved
            {
                if (recording.Releases[0].Date != null)
                {
                    result.Add("Year", (uint)recording.Releases[0].Date.Year);
                }
                if (recording.Releases[0].MbId != null)
                {
                    result.Add("MusicBrainzReleaseId", recording.Releases[0].MbId.ToString());
                }
                if (recording.Releases[0].Status != null)
                {
                    result.Add("MusicBrainzReleaseStatus", recording.Releases[0].Status);
                }
                if (recording.Releases[0].Country != null)
                {
                    result.Add("MusicBrainzReleaseCountry", recording.Releases[0].Country);
                }
                if (recording.Releases[0].ArtistCredit != null && recording.Releases[0].ArtistCredit.Count > 0)
                {
                    if (recording.Releases[0].ArtistCredit[0].Artist.MbId != null)
                    {
                        result.Add("MusicBrainzReleaseArtistId", recording.Releases[0].ArtistCredit[0].Artist.MbId.ToString());
                    }
                }
                if (recording.Releases[0].Media != null && recording.Releases[0].Media.Count > 0)
                {
                    result.Add("Track", (uint)recording.Releases[0].Media[0].TrackOffset);
                    result.Add("TrackCount", (uint)recording.Releases[0].Media[0].TrackCount);
                    result.Add("MusicBrainzReleaseType", recording.Releases[0].Media[0].Format);
                }
            }

            return(result);
        }
コード例 #14
0
ファイル: RecordingController.cs プロジェクト: ellisken/Ling
 public RecordingController(IConfiguration configuration, IRecording recordings, ILanguage languages)
 {
     _configuration = configuration;
     _recordings    = recordings;
     _languages     = languages;
 }
コード例 #15
0
 /// <summary>Adds a barcode to the request.</summary>
 /// <param name="recording">The recording to which <paramref name="isrcs"/> should be added.</param>
 /// <param name="isrcs">One or more (valid) ISRCs to add to the recording.</param>
 /// <returns>This submission request.</returns>
 public IsrcSubmission Add(IRecording recording, params string[] isrcs) => this.Add(recording.Id, isrcs);
コード例 #16
0
 public Neg_Actions(IRecording p_recordingObj)
 {
     _recordingObj = p_recordingObj;
 }
コード例 #17
0
 /// <summary>
 ///
 /// </summary>
 protected void OnStopped(IRecording value)
 {
     Stopped?.Invoke(this, value);
 }
コード例 #18
0
ファイル: HomeController.cs プロジェクト: ellisken/Ling
 public HomeController(IConfiguration configuration, IRecording recording)
 {
     _configuration = configuration;
     _recording     = recording;
 }
コード例 #19
0
ファイル: RecordingActor.cs プロジェクト: tdwalther/AkkaTest
 public static Props Create(IRecording rec)
 {
     return(Props.Create(() => new RecordingActor(rec)));
 }