internal SoundRecorderDialog(ILogger logger, ModuleSchema schema, RolandMidiClient midiClient)
            : this()
        {
            this.logger                   = logger;
            this.schema                   = schema;
            this.midiClient               = midiClient;
            kitNumber.PreviewTextInput   += TextConversions.CheckDigits;
            userSamples.PreviewTextInput += TextConversions.CheckDigits;
            cancellationTokenSource       = new CancellationTokenSource();

            kitNumber.Text = TextConversions.Format(schema.KitRoots.Count);

            // Capture the input device names, and attempt to guess a reasonable default.
            var allInputDevices      = AudioDevices.GetInputDeviceNames();
            var midiName             = midiClient.OutputName;
            var expectedInputDevices = new[] { $"MASTER ({midiName})", $"IN ({midiName})", $"KICK ({midiName})" };

            inputDevice.ItemsSource   = allInputDevices;
            inputDevice.SelectedIndex = allInputDevices.FindIndex(inputName => expectedInputDevices.Contains(inputName));

            foreach (var group in schema.InstrumentGroups)
            {
                instrumentGroupSelector.Items.Add(group.Description);
            }
        }
Example #2
0
 private void HandleKitNumberChanged(object sender, TextChangedEventArgs e)
 {
     TextConversions.TryGetKitRoot(kitNumber.Text, schema, null, out var root);
     SelectedKit            = root;
     acceptButton.IsEnabled = root != null;
     kitName.Content        = root?.KitOnlyDescription.Format(root.Context, data);
 }
Example #3
0
        internal InstrumentAudioExplorer(ILogger logger, ModuleAudio audio, string fileName) : this()
        {
            this.audio      = audio;
            this.logger     = logger;
            Title           = $"{Title} - {fileName}";
            capturesByGroup = audio.Captures.ToLookup(c => c.Instrument.Group);
            var allOutputDeviceNames = AudioDevices.GetOutputDeviceNames();

            outputDevice.ItemsSource = allOutputDeviceNames;

            // Assume that device 0 is the default. That will usually be the case.
            if (allOutputDeviceNames.Count > 0)
            {
                outputDevice.SelectedIndex = 0;
            }

            moduleId.Content    = audio.Schema.Identifier.Name;
            userSamples.Content = TextConversions.Format(capturesByGroup[null].Count());
            var format = audio.Format;

            audioFormat.Content       = $"Channels: {format.Channels}; Bits: {format.Bits}; Frequency: {format.Frequency}";
            timePerInstrument.Content = TextConversions.Format(audio.DurationPerInstrument.TotalSeconds);

            var groups = capturesByGroup.Select(c => new InstrumentGroupOrUserSample(c.Key)).Distinct();

            treeView.ItemsSource           = groups;
            instrumentsGroupBox.Visibility = Visibility.Collapsed;
        }
Example #4
0
 internal KitExplorer(ILogger logger, Kit kit, SysExClient midiClient, string fileName)
     : base(logger, kit.Schema, kit.Data, kit.KitRoot, midiClient, fileName, SaveFileFilter, "Kit explorer")
 {
     this.kit = kit;
     copyToDeviceButton.Content = "Copy kit to device";
     defaultKitNumber.Text      = TextConversions.Format(kit.DefaultKitNumber);
     copyToDeviceKitNumber.Text = defaultKitNumber.Text;
 }
Example #5
0
 protected override void SaveToStream(Stream stream)
 {
     if (!TextConversions.TryGetKitRoot(defaultKitNumber.Text, Schema, Logger, out var targetKitRoot))
     {
         MessageBox.Show("The default kit number is invalid; please correct before saving.", "Invalid kit number");
         return;
     }
     kit.DefaultKitNumber = targetKitRoot.KitNumber.Value;
     kit.Save(stream);
 }
Example #6
0
 internal SoundRecorderDialog(ILogger logger, ModuleSchema schema, RolandMidiClient midiClient)
     : this()
 {
     this.logger                   = logger;
     this.schema                   = schema;
     this.midiClient               = midiClient;
     kitNumber.PreviewTextInput   += TextConversions.CheckDigits;
     userSamples.PreviewTextInput += TextConversions.CheckDigits;
     cancellationTokenSource       = new CancellationTokenSource();
     inputDevice.ItemsSource       = AudioDevices.GetInputDeviceNames();
     kitNumber.Text                = TextConversions.Format(schema.KitRoots.Count);
 }
        private Config TryCreateConfig()
        {
            if (inputDevice.SelectedIndex == -1)
            {
                return(null);
            }
            string deviceName = (string)inputDevice.Items[inputDevice.SelectedIndex];
            int?   deviceId   = AudioDevices.GetAudioInputDeviceId(deviceName);

            if (deviceId == null)
            {
                return(null);
            }
            int midiChannel = int.Parse(midiChannelSelector.Text);

            if (!TextConversions.TryParseDecimal(recordingTime.Text, out var recordingSeconds))
            {
                return(null);
            }
            TimeSpan recordingDuration = TimeSpan.FromSeconds((double)recordingSeconds);

            if (!TextConversions.TryGetKitRoot(kitNumber.Text, schema, logger, out var kit))
            {
                return(null);
            }
            if (outputFile == null)
            {
                return(null);
            }
            if (!TextConversions.TryParseInt32(userSamples.Text, out int parsedUserSamples))
            {
                return(null);
            }
            if (parsedUserSamples < 0 || parsedUserSamples > schema.UserSampleInstruments.Count)
            {
                return(null);
            }

            return(new Config
            {
                KitRoot = kit,
                RecordingDuration = recordingDuration,
                OutputFile = outputFile,
                AudioDeviceId = deviceId.Value,
                InstrumentGroup = instrumentGroupSelector.SelectedIndex - 1,
                UserSamples = parsedUserSamples,
                MidiChannel = midiChannel,
                Attack = (int)attackSlider.Value,
            });
        }
Example #8
0
        protected override async void CopyToDevice(object sender, RoutedEventArgs e)
        {
            if (!TextConversions.TryGetKitRoot(copyToDeviceKitNumber.Text, Schema, Logger, out var targetKitRoot))
            {
                return;
            }

            // It's simplest to clone our root node into a new ModuleData at the right place,
            // then send all those segments. It does involve copying the data in memory
            // twice, but that's much quicker than sending it to the kit anyway.
            var clonedData = RootNode.Context.CloneData(Data, targetKitRoot.Context.Address);
            var segments   = clonedData.GetSegments();

            await CopySegmentsToDeviceAsync(segments);
        }
Example #9
0
        internal InstrumentAudioExplorer(ILogger logger, ModuleAudio audio) : this()
        {
            this.audio               = audio;
            this.logger              = logger;
            capturesByGroup          = audio.Captures.ToLookup(c => c.Instrument.Group);
            outputDevice.ItemsSource = AudioDevices.GetOutputDeviceNames();

            moduleId.Content    = audio.Schema.Identifier.Name;
            userSamples.Content = TextConversions.Format(capturesByGroup[null].Count());
            var format = audio.Format;

            audioFormat.Content       = $"Channels: {format.Channels}; Bits: {format.Bits}; Frequency: {format.Frequency}";
            timePerInstrument.Content = TextConversions.Format(audio.DurationPerInstrument.TotalSeconds);

            var groups = capturesByGroup.Select(c => new InstrumentGroupOrUserSample(c.Key)).Distinct();

            treeView.ItemsSource           = groups;
            instrumentsGroupBox.Visibility = Visibility.Collapsed;
        }