diff --git a/Content/UniversalEditor.Content.PlatformIndependent/Editors/Multimedia/Audio/Waveform/Commands.uexml b/Content/UniversalEditor.Content.PlatformIndependent/Editors/Multimedia/Audio/Waveform/Commands.uexml index db27dc7b..0ce997a4 100644 --- a/Content/UniversalEditor.Content.PlatformIndependent/Editors/Multimedia/Audio/Waveform/Commands.uexml +++ b/Content/UniversalEditor.Content.PlatformIndependent/Editors/Multimedia/Audio/Waveform/Commands.uexml @@ -2,7 +2,13 @@ - + + + + + + + diff --git a/Content/UniversalEditor.Content.PlatformIndependent/Editors/Multimedia/Audio/Waveform/Dialogs/MultiTrackMappingDialog.glade b/Content/UniversalEditor.Content.PlatformIndependent/Editors/Multimedia/Audio/Waveform/Dialogs/MultiTrackMappingDialog.glade new file mode 100644 index 00000000..e6e2899a --- /dev/null +++ b/Content/UniversalEditor.Content.PlatformIndependent/Editors/Multimedia/Audio/Waveform/Dialogs/MultiTrackMappingDialog.glade @@ -0,0 +1,272 @@ + + + + + + 1 + 256 + 1 + 10 + + + + + + + + + + + Mono + 1 + + + Stereo + 2 + + + 5.1 Surround Sound + 6 + + + 7.1 Surround Sound + 8 + + + Dolby Atmos Basic + 10 + + + Dolby Atmos Full + 128 + + + + + + + + + + + + + + + False + Multi-Track Mapping + 500 + 400 + dialog + + + False + vertical + 2 + + + False + end + + + gtk-ok + True + True + True + True + + + + True + True + 0 + + + + + gtk-cancel + True + True + True + True + + + True + True + 1 + + + + + False + False + 0 + + + + + + True + False + 16 + 16 + 16 + 16 + + + True + False + 8 + Preset + 0 + + + 0 + 0 + + + + + True + False + 8 + 8 + 8 + 8 + True + tmChannelPresets + 1 + + + + 0 + + + + + ( + + + + + + 1 + + + + + channels) + + + + + 1 + 0 + + + + + True + True + True + True + in + + + True + True + tmChannels + + + + + + True + Track + True + True + + + + 0 + + + + + + + True + Channel + True + True + + + 96 + + + 2 + + + + + + 1 + + + + + + + + + 0 + 2 + 2 + + + + + True + False + 8 + Number of channels + 0 + + + 0 + 1 + + + + + True + True + 8 + 8 + 8 + 8 + adjChannelCount + 2 + + + 1 + 1 + + + + + True + True + 1 + + + + + + cmdExport + cmdCancel + + + diff --git a/Content/UniversalEditor.Content.PlatformIndependent/Editors/Multimedia/Audio/Waveform/MultiTrackMapping.uexml b/Content/UniversalEditor.Content.PlatformIndependent/Editors/Multimedia/Audio/Waveform/MultiTrackMapping.uexml new file mode 100644 index 00000000..9fd3f0e8 --- /dev/null +++ b/Content/UniversalEditor.Content.PlatformIndependent/Editors/Multimedia/Audio/Waveform/MultiTrackMapping.uexml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Plugins.UserInterface/UniversalEditor.Plugins.Multimedia.UserInterface/Editors/Multimedia/Audio/Waveform/Dialogs/MultiTrackMappingDialog.cs b/Plugins.UserInterface/UniversalEditor.Plugins.Multimedia.UserInterface/Editors/Multimedia/Audio/Waveform/Dialogs/MultiTrackMappingDialog.cs new file mode 100644 index 00000000..8bc75b79 --- /dev/null +++ b/Plugins.UserInterface/UniversalEditor.Plugins.Multimedia.UserInterface/Editors/Multimedia/Audio/Waveform/Dialogs/MultiTrackMappingDialog.cs @@ -0,0 +1,200 @@ +// +// MultiTrackMappingDialog.cs +// +// Author: +// Michael Becker +// +// Copyright (c) 2022 Mike Becker's Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +using System.Collections.Generic; +using System.Linq; +using MBS.Framework.UserInterface; +using MBS.Framework.UserInterface.Controls; +using MBS.Framework.UserInterface.Controls.ListView; +using UniversalEditor.ObjectModels.Markup; +using UniversalEditor.UserInterface; + +namespace UniversalEditor.Plugins.Multimedia.UserInterface.Editors.Multimedia.Audio.Waveform.Dialogs +{ + [ContainerLayout("~/Editors/Multimedia/Audio/Waveform/Dialogs/MultiTrackMappingDialog.glade")] + public class MultiTrackMappingDialog : CustomDialog + { + private ComboBox cboChannelPresets; + private ListViewControl lvChannels; + private NumericTextBox txtChannelCount; + private Label lblChannelCount; + + private string[][] knownChannelNames = new string[][] + { + new string[] { "Mono" }, + new string[] { "Left", "Right" }, + new string[] { "Front left", "Front right", "Center", "Rear left", "Rear right" }, + new string[] { "Front left", "Front right", "Center", "Rear left", "Rear right" } + }; + + public Editor Editor { get; internal set; } = null; + + private class MultiTrackMappingChannelPreset + { + public string Title { get; } + public List Channels { get; } = new List(); + + public MultiTrackMappingChannelPreset(string title, IEnumerable list) + { + Title = title; + Channels.AddRange(list); + } + } + private class MultiTrackMappingChannel + { + public Guid ID { get; } = Guid.Empty; + public string Title { get; } = null; + public MBS.Framework.Drawing.Color Color { get; set; } = MBS.Framework.Drawing.Color.Empty; + + public MultiTrackMappingChannel(Guid id, string title) + { + ID = id; + Title = title; + } + } + + private List channelPresets = new List(); + + private TreeModelRow rowCustom = null; + protected override void OnCreated(EventArgs e) + { + base.OnCreated(e); + + ((DefaultTreeModel)cboChannelPresets.Model).Rows.Clear(); + + EditorReference _er = Editor?.MakeReference(); + if (_er != null) + { + if (_er.Configuration.Elements["MultiTrackMapping"] is MarkupTagElement tagMultiTrackMapping) + { + if (tagMultiTrackMapping.Elements["ChannelPresets"] is MarkupTagElement tagChannelPresets) + { + foreach (MarkupTagElement tagChannelPreset in tagChannelPresets.Elements.OfType()) + { + MarkupAttribute attTitle = tagChannelPreset.Attributes["Title"]; + string title = attTitle?.Value; + + List channels = new List(); + + if (tagChannelPreset.Elements["Channels"] is MarkupTagElement tagChannels) + { + foreach (MarkupTagElement tagChannel in tagChannels.Elements.OfType()) + { + MultiTrackMappingChannel channel = new MultiTrackMappingChannel(new Guid(tagChannel.Attributes["ID"].Value), tagChannel.Attributes["Title"].Value); + string colorName = tagChannel.Attributes["Color"]?.Value; + if (colorName != null) + { + channel.Color = MBS.Framework.Drawing.Color.Parse(colorName); + } + channels.Add(channel); + } + } + + MultiTrackMappingChannelPreset preset = new MultiTrackMappingChannelPreset(title, channels); + channelPresets.Add(preset); + + TreeModelRow row = new TreeModelRow(new TreeModelRowColumn[] + { + new TreeModelRowColumn(cboChannelPresets.Model.Columns[0], title), + new TreeModelRowColumn(cboChannelPresets.Model.Columns[1], channels.Count) + }); + row.SetExtraData("preset", preset); + + ((DefaultTreeModel)cboChannelPresets.Model).Rows.Add(row); + } + } + } + } + + rowCustom = new TreeModelRow(new TreeModelRowColumn[] + { + new TreeModelRowColumn(cboChannelPresets.Model.Columns[0], "(custom)") + }); + ((DefaultTreeModel)cboChannelPresets.Model).Rows.Add(rowCustom); + + cboChannelPresets.SelectedItem = rowCustom; + } + + [EventHandler(nameof(cboChannelPresets), nameof(ComboBox.Changed))] + private void cboChannelPresets_Changed(object sender, EventArgs e) + { + inhibitChannelChange = true; + MultiTrackMappingChannelPreset preset = cboChannelPresets.SelectedItem?.GetExtraData("preset"); + if (preset != null) + { + lblChannelCount.Visible = false; + txtChannelCount.Visible = false; + txtChannelCount.Value = preset.Channels.Count; + } + else + { + lblChannelCount.Visible = true; + txtChannelCount.Visible = true; + } + inhibitChannelChange = false; + + UpdateChannels(); + } + + private bool inhibitChannelChange = false; + + [EventHandler(nameof(txtChannelCount), nameof(NumericTextBox.Changed))] + private void txtChannelCount_Changed(object sender, EventArgs e) + { + if (!inhibitChannelChange) + { + cboChannelPresets.SelectedItem = rowCustom; + } + UpdateChannels(); + } + + private void UpdateChannels() + { + MultiTrackMappingChannelPreset preset = cboChannelPresets.SelectedItem?.GetExtraData("preset"); + + lvChannels.Model.Rows.Clear(); + for (int i = 0; i < txtChannelCount.Value; i++) + { + string channelName = String.Format("Channel {0}", (i + 1)); + if (preset != null) + { + channelName = preset.Channels[i].Title; + } + + MBS.Framework.UserInterface.Drawing.Image channelColorImage = null; + if (preset != null) + { + channelColorImage = MBS.Framework.UserInterface.Drawing.Image.Create(24, 24); + MBS.Framework.UserInterface.Drawing.Graphics g = MBS.Framework.UserInterface.Drawing.Graphics.FromImage(channelColorImage); + g.Clear(preset.Channels[i].Color); + } + + TreeModelRow row = new TreeModelRow(new TreeModelRowColumn[] + { + new TreeModelRowColumn(lvChannels.Model.Columns[0], String.Format("Track {0}", (i + 1))), + new TreeModelRowColumn(lvChannels.Model.Columns[1], channelName), + new TreeModelRowColumn(lvChannels.Model.Columns[2], channelColorImage) + }); + lvChannels.Model.Rows.Add(row); + } + } + } +} diff --git a/Plugins.UserInterface/UniversalEditor.Plugins.Multimedia.UserInterface/Editors/Multimedia/Audio/Waveform/WaveformAudioEditor.cs b/Plugins.UserInterface/UniversalEditor.Plugins.Multimedia.UserInterface/Editors/Multimedia/Audio/Waveform/WaveformAudioEditor.cs index 8e53d4c6..59f0248e 100644 --- a/Plugins.UserInterface/UniversalEditor.Plugins.Multimedia.UserInterface/Editors/Multimedia/Audio/Waveform/WaveformAudioEditor.cs +++ b/Plugins.UserInterface/UniversalEditor.Plugins.Multimedia.UserInterface/Editors/Multimedia/Audio/Waveform/WaveformAudioEditor.cs @@ -24,8 +24,11 @@ using MBS.Audio; using MBS.Audio.PortAudio; using MBS.Framework.UserInterface; using MBS.Framework.UserInterface.Layouts; + using UniversalEditor.ObjectModels.Multimedia.Audio.Waveform; using UniversalEditor.Plugins.Multimedia.UserInterface.Editors.Multimedia.Audio.Waveform.Controls; +using UniversalEditor.Plugins.Multimedia.UserInterface.Editors.Multimedia.Audio.Waveform.Dialogs; + using UniversalEditor.UserInterface; namespace UniversalEditor.Plugins.Multimedia.UserInterface.Editors.Multimedia.Audio.Waveform @@ -48,6 +51,18 @@ namespace UniversalEditor.Plugins.Multimedia.UserInterface.Editors.Multimedia.Au public WaveformAudioEditor() { Layout = new BoxLayout(Orientation.Vertical); + + Context.AttachCommandEventHandler("WaveformAudioEditor_Tools_MultiTrackMapping", WaveformAudioEditor_Tools_MultiTrackMapping); + } + + private void WaveformAudioEditor_Tools_MultiTrackMapping(object sender, EventArgs e) + { + MultiTrackMappingDialog dlg = new MultiTrackMappingDialog(); + dlg.Editor = this; + if (dlg.ShowDialog() == DialogResult.OK) + { + + } } protected override void OnObjectModelChanged(EventArgs e) @@ -82,7 +97,7 @@ namespace UniversalEditor.Plugins.Multimedia.UserInterface.Editors.Multimedia.Au // get the setting "Editors -> Audio -> Waveform -> Synchronize with JACK transport AudioPlayer player = new AudioPlayer(); player.Play(wave); - + return /*true*/; } diff --git a/Plugins.UserInterface/UniversalEditor.Plugins.Multimedia.UserInterface/UniversalEditor.Plugins.Multimedia.UserInterface.csproj b/Plugins.UserInterface/UniversalEditor.Plugins.Multimedia.UserInterface/UniversalEditor.Plugins.Multimedia.UserInterface.csproj index acef14da..5945205f 100644 --- a/Plugins.UserInterface/UniversalEditor.Plugins.Multimedia.UserInterface/UniversalEditor.Plugins.Multimedia.UserInterface.csproj +++ b/Plugins.UserInterface/UniversalEditor.Plugins.Multimedia.UserInterface/UniversalEditor.Plugins.Multimedia.UserInterface.csproj @@ -62,6 +62,7 @@ + @@ -88,6 +89,7 @@ +