예제 #1
0
		private static void DrawPanelMusicControl()
		{


			var inputDevices = DeviceManager.Devices;

			if (ImGui.BeginCombo("Input Device".Localize(), DeviceManager.CurrentInputDevice.ToDeviceString()))
			{
				if (ImGui.Selectable("None##device", DeviceManager.CurrentInputDevice is null))
				{
					DeviceManager.DisposeDevice();
				}
				for (int i = 0; i < inputDevices.Length; i++)
				{
					var device = inputDevices[i];
					if (ImGui.Selectable($"{device.Name}##{i}", device.Id == DeviceManager.CurrentInputDevice?.Id))
					{
						DeviceManager.SetDevice(device);
					}
				}
				ImGui.EndCombo();
			}
			if (ImGui.IsItemHovered() && ImGui.IsMouseClicked(ImGuiMouseButton.Right))
			{
				DeviceManager.DisposeDevice();
			}
			ToolTip("Choose external midi input device. right click to reset.".Localize());




			UIcurrentInstrument = Plugin.CurrentInstrument;
			if (ImGui.Combo("Instrument".Localize(), ref UIcurrentInstrument, InstrumentStrings, InstrumentStrings.Length, 20))
			{
				Task.Run(() => SwitchInstrument.SwitchTo((uint)UIcurrentInstrument, true));
			}
			ToolTip("Select current instrument. \nRight click to quit performance mode.".Localize());

			if (ImGui.IsItemHovered() && ImGui.IsMouseClicked(ImGuiMouseButton.Right))
			{
				Task.Run(() => SwitchInstrument.SwitchTo(0));
				PlayerControl.Pause();
			}



			if (currentPlayback != null)
			{
				var currentTime = currentPlayback.GetCurrentTime<MetricTimeSpan>();
				var duration = currentPlayback.GetDuration<MetricTimeSpan>();
				float progress;
				try
				{
					progress = (float)currentTime.Divide(duration);
				}
				catch (Exception e)
				{
					progress = 0;
				}

				if (ImGui.SliderFloat("Progress".Localize(), ref progress, 0, 1,
					$"{currentTime.Minutes}:{currentTime.Seconds:00}",
					ImGuiSliderFlags.AlwaysClamp | ImGuiSliderFlags.NoRoundToFormat))
				{
					currentPlayback.MoveToTime(duration.Multiply(progress));
				}

				if (ImGui.IsItemHovered() && ImGui.IsMouseClicked(ImGuiMouseButton.Right))
				{
					currentPlayback.MoveToTime(duration.Multiply(0));
				}
			}
			else
			{
				float zeroprogress = 0;
				ImGui.SliderFloat("Progress".Localize(), ref zeroprogress, 0, 1, "0:00", ImGuiSliderFlags.NoInput);
			}
			ToolTip("Set the playing progress. \nRight click to restart current playback.".Localize());

			#region bpm

			Tempo bpm = null;
			try
			{
				// ReSharper disable once PossibleNullReferenceException
				var current = currentPlayback.GetCurrentTime(TimeSpanType.Midi);
				bpm = currentPlayback.TempoMap.GetTempoAtTime(current);
			}
			catch
			{
				//
			}

			var label = $"{config.playSpeed:F2}";

			if (bpm != null) label += $" ({bpm.BeatsPerMinute * config.playSpeed:F1} bpm)";

			#endregion

			if (ImGui.DragFloat("Speed".Localize(), ref config.playSpeed, 0.003f, 0.1f, 10f, label, ImGuiSliderFlags.Logarithmic))
			{
				SetSpeed();
			}
			ToolTip("Set the speed of events playing. 1 means normal speed.\nFor example, to play events twice slower this property should be set to 0.5.\nRight Click to reset back to 1.".Localize());

			if (ImGui.IsItemHovered() && ImGui.IsMouseClicked(ImGuiMouseButton.Right))
			{
				config.playSpeed = 1;
				SetSpeed();
			}

			void SetSpeed()
			{
				try
				{
					config.playSpeed = Math.Max(0.1f, config.playSpeed);
					var currenttime = currentPlayback.GetCurrentTime(TimeSpanType.Midi);
					currentPlayback.Speed = config.playSpeed;
					currentPlayback.MoveToTime(currenttime);
				}
				catch (Exception e)
				{
				}
			}

			ImGui.InputInt("Transpose".Localize(), ref config.NoteNumberOffset, 12);
			if (ImGui.IsItemHovered() && ImGui.IsMouseClicked(ImGuiMouseButton.Right)) config.NoteNumberOffset = 0;
			ToolTip("Transpose, measured by semitone. \nRight click to reset.".Localize());


			if (ImGui.Button("Octave+".Localize())) config.NoteNumberOffset += 12;
			ToolTip("Add 1 octave(+12 semitones) to all notes.".Localize());

			ImGui.SameLine();
			if (ImGui.Button("Octave-".Localize())) config.NoteNumberOffset -= 12;
			ToolTip("Subtract 1 octave(-12 semitones) to all notes.".Localize());

			ImGui.SameLine();
			if (ImGui.Button("Reset##note".Localize())) config.NoteNumberOffset = 0;

			ImGui.SameLine();
			ImGui.Checkbox("Auto Adapt".Localize(), ref config.AdaptNotesOOR);
			HelpMarker("Adapt high/low pitch notes which are out of range\r\ninto 3 octaves we can play".Localize());



			//ImGui.SliderFloat("secbetweensongs", ref config.timeBetweenSongs, 0, 10,
			//	$"{config.timeBetweenSongs:F2} [{500000 * config.timeBetweenSongs:F0}]", ImGuiSliderFlags.AlwaysClamp);
		}
예제 #2
0
        public unsafe void Draw()
        {
            if (!IsVisible)
            {
                return;
            }

            //var Buttoncolor = *ImGui.GetStyleColorVec4(ImGuiCol.Button);
            //var ButtonHoveredcolor = *ImGui.GetStyleColorVec4(ImGuiCol.ButtonHovered);
            //var ButtonActivecolor = *ImGui.GetStyleColorVec4(ImGuiCol.ButtonActive);


            ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, new Vector2(5, 5));
            ImGui.SetNextWindowPos(new Vector2(100, 100), ImGuiCond.FirstUseEver);
            ImGui.SetNextWindowSize(new Vector2(400, 400), ImGuiCond.FirstUseEver);
            //ImGui.SetNextWindowSizeConstraints(new Vector2(356, 10), config.miniPlayer ? new Vector2(356, 100) : new Vector2(10000, 10000));
            var flag = config.miniPlayer ? ImGuiWindowFlags.NoDecoration : ImGuiWindowFlags.None;

            if (config.miniPlayer)
            {
                ImGui.SetNextWindowSizeConstraints(Vector2.Zero, new Vector2(357, 800));
            }
            if (ImGui.Begin("MidiBard", ref IsVisible,
                            ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.AlwaysAutoResize | flag))
            {
                if (!config.miniPlayer)
                {
                    ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, new Vector2(4, 4));
                    ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, new Vector2(15, 4));
                    {
                        if (!_isImportRunning)
                        {
                            DrawImportButton();
                            ToolTip("Import midi file.".Localize());
                        }
                        else
                        {
                            DrawImportProgress();
                        }

                        if (_hasError)
                        {
                            DrawFailedImportMessage();
                        }

                        //ImGui.SameLine();
                        //if (ImGui.Button("Remove Selected"))
                        //{
                        //	PlaylistManager.Remove(PlaylistManager.currentPlaying);
                        //}

                        ImGui.SameLine();
                        if (ImGui.Button("Clear Playlist".Localize()))
                        {
                            PlaylistManager.Clear();
                        }

                        if (localizer.Language == UILang.CN)
                        {
                            ImGui.SameLine();
                            ImGui.PushFont(UiBuilder.IconFont);
                            if (ImGui.Button(FontAwesomeIcon.QuestionCircle.ToIconString()))
                            {
                                //config.showHelpWindow ^= true;
                            }

                            ImGui.PopFont();

                            if (ImGui.IsItemHovered())
                            {
                                var currentwindowpos = ImGui.GetWindowPos();
                                var width            = ImGui.GetWindowWidth();
                                ImGui.SetNextWindowPos(currentwindowpos + new Vector2(0,
                                                                                      ImGui.GetTextLineHeightWithSpacing() + ImGui.GetFrameHeightWithSpacing() +
                                                                                      ImGui.GetStyle().WindowPadding.Y));
                                ImGui.SetNextWindowSizeConstraints(new Vector2(width, 0), new Vector2(10000, 10000));
                                ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, new Vector2(4, 4));
                                if (ImGui.Begin("HelpWindow",
                                                ImGuiWindowFlags.NoDecoration | ImGuiWindowFlags.Tooltip |
                                                ImGuiWindowFlags.AlwaysAutoResize))
                                {
                                    ImGui.BulletText(
                                        "如何开始使用MIDIBARD演奏?" +
                                        "\n MIDIBARD窗口默认在角色进入演奏模式后自动弹出。" +
                                        "\n 点击窗口左上角的“+”按钮来将乐曲文件导入到播放列表,仅支持.mid格式的乐曲。" +
                                        "\n 导入时按Ctrl或Shift可以选择多个文件一同导入。" +
                                        "\n 双击播放列表中要演奏的乐曲后点击播放按钮开始演奏。\n");
                                    ImGui.BulletText(
                                        "为什么点击播放之后没有正常演奏?" +
                                        "\n MIDIBARD仅使用37键演奏模式。" +
                                        "\n 请在游戏“乐器演奏操作设置”的“键盘操作”类别下启用“全音阶一同显示、设置按键”的选项。\n");
                                    ImGui.BulletText(
                                        "如何使用MIDIBARD进行多人合奏?" +
                                        "\n MIDIBARD使用游戏中的合奏助手来完成合奏,请在合奏时打开游戏的节拍器窗口。" +
                                        "\n 合奏前在播放列表中双击要合奏的乐曲,播放器下方会出现可供演奏的所有音轨,请为每位合奏成员分别选择其需要演奏的音轨。" +
                                        "\n 选择音轨后队长点击节拍器窗口的“合奏准备确认”按钮," +
                                        "\n 并确保合奏准备确认窗口中已勾选“使用合奏助手”选项后点击开始即可开始合奏。" +
                                        "\n 注:节拍器前两小节为准备时间,从第1小节开始会正式开始合奏。" +
                                        "\n   考虑到不同使用环境乐曲加载速度可能不一致,为了避免切换乐曲导致的不同步,在乐曲结束时合奏会自动停止。\n");
                                    ImGui.BulletText(
                                        "后台演奏时有轻微卡顿不流畅怎么办?" +
                                        "\n 在游戏内“系统设置→显示设置→帧数限制”中取消勾选 “程序在游戏窗口处于非激活状态时限制帧数” 的选项并应用设置。\n");
                                    ImGui.Spacing();

                                    ImGui.End();
                                }

                                ImGui.PopStyleVar();
                            }
                        }

                        if (EnsembleModeRunning)
                        {
                            ImGui.SameLine();
                            if (MetronomeBeatsElapsed < 0)
                            {
                                ImGui.PushStyleColor(ImGuiCol.Button, 0xFF00A0D0);
                                ImGui.Button("Ensemble Mode Preparing".Localize());
                            }
                            else
                            {
                                ImGui.PushStyleColor(ImGuiCol.Button, 0xFF0000D0);
                                ImGui.Button("Ensemble Mode Running".Localize());
                            }

                            ImGui.PopStyleColor();
                        }
                    }

                    ImGui.PopStyleVar(2);



                    if (PlaylistManager.Filelist.Count == 0)
                    {
                        if (ImGui.Button("Import midi files to start performing!".Localize(), new Vector2(-1, 25)))
                        {
                            RunImportTask();
                        }
                    }
                    else
                    {
                        ImGui.PushStyleColor(ImGuiCol.Button, 0);
                        ImGui.PushStyleColor(ImGuiCol.ButtonHovered, 0);
                        ImGui.PushStyleColor(ImGuiCol.ButtonActive, 0);
                        ImGui.PushStyleColor(ImGuiCol.Header, 0x3C60FF8E);
                        ImGui.PushStyleColor(ImGuiCol.HeaderHovered, 0x80808080);
                        if (ImGui.BeginTable("##PlaylistTable", 3,
                                             ImGuiTableFlags.RowBg | ImGuiTableFlags.PadOuterX |
                                             ImGuiTableFlags.ScrollY | ImGuiTableFlags.NoSavedSettings | ImGuiTableFlags.BordersInnerV | ImGuiTableFlags.ContextMenuInBody,
                                             new Vector2(-1,
                                                         ImGui.GetTextLineHeightWithSpacing() * Math.Min(config.playlistSizeY,
                                                                                                         PlaylistManager.Filelist.Count)
                                                         )))
                        {
                            ImGui.TableSetupColumn("\ue035", ImGuiTableColumnFlags.WidthFixed);
                            ImGui.TableSetupColumn("##delete", ImGuiTableColumnFlags.WidthFixed);
                            ImGui.TableSetupColumn("filename", ImGuiTableColumnFlags.WidthStretch);
                            for (var i = 0; i < PlaylistManager.Filelist.Count; i++)
                            {
                                ImGui.TableNextRow();
                                ImGui.TableSetColumnIndex(0);
                                if (ImGui.Selectable($"{i + 1:000}##plistitem", PlaylistManager.CurrentPlaying == i,
                                                     ImGuiSelectableFlags.SpanAllColumns | ImGuiSelectableFlags.AllowDoubleClick |
                                                     ImGuiSelectableFlags.AllowItemOverlap))
                                {
                                    if (ImGui.IsMouseDoubleClicked(ImGuiMouseButton.Left))
                                    {
                                        PlaylistManager.CurrentPlaying = i;

                                        try
                                        {
                                            var wasplaying = IsPlaying;
                                            currentPlayback?.Dispose();
                                            currentPlayback = null;

                                            currentPlayback = PlaylistManager.Filelist[PlaylistManager.CurrentPlaying].GetFilePlayback();
                                            if (wasplaying)
                                            {
                                                currentPlayback?.Start();
                                            }
                                            Task.Run(SwitchInstrument.WaitSwitchInstrument);
                                        }
                                        catch (Exception e)
                                        {
                                            //
                                        }
                                    }
                                    else
                                    {
                                        PlaylistManager.CurrentSelected = i;
                                    }
                                }

                                ImGui.TableNextColumn();
                                ImGui.PushFont(UiBuilder.IconFont);
                                ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, Vector2.Zero);
                                if (ImGui.Button($"{((FontAwesomeIcon)0xF2ED).ToIconString()}##{i}", new Vector2(ImGui.GetTextLineHeight(), ImGui.GetTextLineHeight())))
                                {
                                    PlaylistManager.Remove(i);
                                }
                                ImGui.PopStyleVar();
                                ImGui.PopFont();
                                ImGui.TableNextColumn();
                                try
                                {
                                    ImGui.Text(PlaylistManager.Filelist[i].Item2);
                                }
                                catch (Exception e)
                                {
                                    ImGui.Text("deleted");
                                }
                            }

                            ImGui.EndTable();
                        }

                        ImGui.PopStyleColor(5);
                    }

                    #region old playlist

                    //ImGui.BeginListBox("##PlayList1", new Vector2(-1, ImGui.GetTextLineHeightWithSpacing() * maxItems));
                    //{
                    //	var i = 0;
                    //	foreach (var tuple in PlaylistManager.Filelist)
                    //	{
                    //		if (PlaylistManager.currentPlaying == i)
                    //		{
                    //			ImGui.PushStyleColor(ImGuiCol.Text, config.ThemeColor);
                    //		}

                    //		if (ImGui.Selectable($"{tuple.Item2}##{i}", PlaylistManager.currentSelected[i], ImGuiSelectableFlags.AllowDoubleClick))
                    //		{

                    //		}
                    //		if (PlaylistManager.currentPlaying == i)
                    //		{
                    //			ImGui.PopStyleColor();
                    //		}
                    //		i++;
                    //	}
                    //}
                    //ImGui.EndListBox();
                    //ImGui.Text(sb.ToString());

                    //if (ImGui.ListBox("##PlayList", ref PlaylistManager.currentPlaying, items, itemsCount, maxItems))
                    //{
                    //	var wasplaying = IsPlaying;
                    //	currentPlayback?.Dispose();

                    //	try
                    //	{
                    //		currentPlayback = PlaylistManager.Filelist[PlaylistManager.currentPlaying].Item1.GetPlayback();
                    //		if (wasplaying) currentPlayback?.Start();
                    //	}
                    //	catch (Exception e)
                    //	{

                    //	}
                    //}

                    #endregion

                    ImGui.Spacing();
                }

                DrawCurrentPlaying();

                ImGui.Spacing();

                DrawProgressBar();

                ImGui.Spacing();

                ImGui.PushFont(UiBuilder.IconFont);
                ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, new Vector2(4, 4));
                ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, new Vector2(15, 4));
                {
                    DrawButtonPlayPause();
                    DrawButtonStop();
                    DrawButtonFastForward();
                    DrawButtonPlayMode();
                    DrawButtonShowSettingsPanel();
                    DrawButtonShowInstrumentSwitch();
                    DrawButtonMiniPlayer();
                }
                ImGui.PopFont();
                ImGui.PopStyleVar(2);

                if (config.showMusicControlPanel)
                {
                    DrawTrackTrunkSelectionWindow();
                    ImGui.Separator();
                    DrawPanelMusicControl();
                    //}
                    //if (config.showSettingsPanel)
                    //{
                    ImGui.Separator();
                    DrawPanelGeneralSettings();
                }
                if (Debug)
                {
                    DrawDebugWindow();
                }

                var size = ImGui.GetWindowSize();
                var pos  = ImGui.GetWindowPos();
                var vp   = ImGui.GetWindowViewport();



                //ImGui.SetNextWindowViewport(vp.ID);
                ImGui.SetNextWindowPos(pos + new Vector2(size.X + 1, 0));
                //ImGui.SetNextWindowSizeConstraints(Vector2.Zero, size);
                if (config.showInstrumentSwitchWindow && ImGui.Begin("Instrument".Localize(), ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoFocusOnAppearing | ImGuiWindowFlags.NoBringToFrontOnFocus | ImGuiWindowFlags.NoMove | ImGuiWindowFlags.AlwaysAutoResize))
                {
                    ImGui.SetNextItemWidth(120);
                    UIcurrentInstrument = Plugin.CurrentInstrument;
                    if (ImGui.ListBox("##instrumentSwitch", ref UIcurrentInstrument,
                                      InstrumentSheet.Select(i => i.Instrument.ToString()).ToArray(), (int)InstrumentSheet.RowCount,
                                      (int)InstrumentSheet.RowCount))
                    {
                        Task.Run(() => SwitchInstrument.SwitchTo((uint)UIcurrentInstrument));
                    }

                    //if (ImGui.Button("Quit"))
                    //{
                    //	Task.Run(() => SwitchInstrument.SwitchTo(0));
                    //}
                    ImGui.End();
                }

                ImGui.End();
            }

            ImGui.PopStyleVar();
        }