Skip to content

Commit

Permalink
Merge branch 'release/3.2.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
paralleltree committed Jul 23, 2021
2 parents 6cf34c2 + edaf9b5 commit 482afd6
Show file tree
Hide file tree
Showing 17 changed files with 223 additions and 54 deletions.
1 change: 1 addition & 0 deletions Ched/Ched.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@
</Compile>
<Compile Include="UI\Windows\Converters\BitmapImageSourceConverter.cs" />
<Compile Include="UI\Windows\Converters\ShortcutKeyTextConverter.cs" />
<Compile Include="UI\Windows\Converters\VolumeConverter.cs" />
<Compile Include="UI\Windows\DiagnosticsWindow.xaml.cs">
<DependentUpon>DiagnosticsWindow.xaml</DependentUpon>
</Compile>
Expand Down
8 changes: 8 additions & 0 deletions Ched/Configuration/ApplicationSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,13 @@ public bool IsPreviewAbortAtLastNote
get { return ((bool)(this["IsPreviewAbortAtLastNote"])); }
set { this["IsPreviewAbortAtLastNote"] = value; }
}

[UserScopedSetting]
[DefaultSettingValue("False")]
public bool IsSlowDownPreviewEnabled
{
get => (bool)this["IsSlowDownPreviewEnabled"];
set => this["IsSlowDownPreviewEnabled"] = value;
}
}
}
7 changes: 7 additions & 0 deletions Ched/Configuration/SoundSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,12 @@ public Dictionary<string, SoundSource> ScoreSound
get { return (Dictionary<string, SoundSource>)this["ScoreSound"]; }
set { this["ScoreSound"] = value; }
}

[UserScopedSetting]
public SoundSource GuideSound
{
get => (SoundSource)this["GuideSound"] ?? new SoundSource("guide.mp3", 0.036);
set => this["GuideSound"] = value;
}
}
}
27 changes: 27 additions & 0 deletions Ched/Localization/MainFormStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Ched/Localization/MainFormStrings.en.resx
Original file line number Diff line number Diff line change
Expand Up @@ -333,4 +333,13 @@
<data name="ResetAll" xml:space="preserve">
<value>Reset All</value>
</data>
<data name="GuideVolume" xml:space="preserve">
<value>Guide Volume (Global)</value>
</data>
<data name="MusicVolume" xml:space="preserve">
<value>Music Volume</value>
</data>
<data name="SlowDownPreview" xml:space="preserve">
<value>Slow Down Preview</value>
</data>
</root>
9 changes: 9 additions & 0 deletions Ched/Localization/MainFormStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -333,4 +333,13 @@
<data name="ResetAll" xml:space="preserve">
<value>初期化</value>
</data>
<data name="GuideVolume" xml:space="preserve">
<value>ガイド音音量(共通)</value>
</data>
<data name="MusicVolume" xml:space="preserve">
<value>楽曲音量</value>
</data>
<data name="SlowDownPreview" xml:space="preserve">
<value>スロー再生</value>
</data>
</root>
2 changes: 1 addition & 1 deletion Ched/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
[assembly: ComVisible(false)]
[assembly: Guid("4c0c9f98-6fcf-4d2f-b821-37a66362dc75")]

[assembly: AssemblyVersion("3.1.0.0")]
[assembly: AssemblyVersion("3.2.0.0")]

[assembly: DisableDpiAwareness]
31 changes: 21 additions & 10 deletions Ched/UI/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,11 @@ protected void LoadBook(ScoreBook book)
if (!string.IsNullOrEmpty(book.Path))
{
SoundSettings.Default.ScoreSound.TryGetValue(book.Path, out SoundSource src);
if (src != null) CurrentMusicSource = src;
if (src != null)
{
if (src.Volume == 0) src.Volume = 1;
CurrentMusicSource = src;
}
}
}

Expand Down Expand Up @@ -482,7 +486,7 @@ void lambda(object p, EventArgs q)
try
{
CommitChanges();
var context = new SoundPreviewContext(ScoreBook.Score, CurrentMusicSource);
var context = new SoundPreviewContext(ScoreBook.Score, CurrentMusicSource, SoundSettings.Default.GuideSound);
if (!PreviewManager.Start(context, startTick)) return;
PreviewManager.Finished += lambda;
NoteView.Editable = CanEdit;
Expand Down Expand Up @@ -851,6 +855,20 @@ void updateScore(Score newScore)

var insertMenuItems = new ToolStripItem[] { insertBpmItem, insertHighSpeedItem, insertTimeSignatureItem };

var playItem = shortcutItemBuilder.BuildItem(Commands.PlayPreview, MainFormStrings.Play);

var stopItem = new ToolStripMenuItem(MainFormStrings.Stop, null, (s, e) => PreviewManager.Stop());

var slowDownPreviewItem = new ToolStripMenuItem(MainFormStrings.SlowDownPreview, null, (s, e) =>
{
var item = s as ToolStripMenuItem;
item.Checked = !item.Checked;
ApplicationSettings.Default.IsSlowDownPreviewEnabled = item.Checked;
})
{
Checked = ApplicationSettings.Default.IsSlowDownPreviewEnabled
};

var isAbortAtLastNoteItem = new ToolStripMenuItem(MainFormStrings.AbortAtLastNote, null, (s, e) =>
{
var item = s as ToolStripMenuItem;
Expand All @@ -864,17 +882,10 @@ void updateScore(Score newScore)
PreviewManager.Started += (s, e) => isAbortAtLastNoteItem.Enabled = false;
PreviewManager.Finished += (s, e) => isAbortAtLastNoteItem.Enabled = true;

var playItem = shortcutItemBuilder.BuildItem(Commands.PlayPreview, MainFormStrings.Play);

var stopItem = new ToolStripMenuItem(MainFormStrings.Stop, null, (s, e) =>
{
PreviewManager.Stop();
});

var playMenuItems = new ToolStripItem[]
{
playItem, stopItem, new ToolStripSeparator(),
isAbortAtLastNoteItem
slowDownPreviewItem, isAbortAtLastNoteItem
};

var helpMenuItems = new ToolStripItem[]
Expand Down
28 changes: 13 additions & 15 deletions Ched/UI/NoteView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ IObservable<MouseEventArgs> addAirActionHandler()
{
foreach (var note in Notes.AirActions.Reverse())
{
var size = new SizeF(UnitLaneWidth / 2, GetYPositionFromTick(note.ActionNotes.Max(q => q.Offset)));
var size = new SizeF(UnitLaneWidth / 2, GetYPositionFromTick(note.ActionNotes.Max(q => q.Offset)) - GetYPositionFromTick(0));
var rect = new RectangleF(
(UnitLaneWidth + BorderThickness) * (note.ParentNote.LaneIndex + note.ParentNote.Width / 2f) - size.Width / 2,
GetYPositionFromTick(note.ParentNote.Tick),
Expand Down Expand Up @@ -1096,17 +1096,13 @@ IObservable<MouseEventArgs> addAirActionHandler()
}
newNote.Width = LastWidth;
newNote.Tick = Math.Max(GetQuantizedTick(GetTickFromYPosition(scorePos.Y)), 0);
int newNoteLaneIndex = (int)(scorePos.X / (UnitLaneWidth + BorderThickness)) - newNote.Width / 2;
newNoteLaneIndex = Math.Min(Constants.LanesCount - newNote.Width, Math.Max(0, newNoteLaneIndex));
newNote.LaneIndex = newNoteLaneIndex;
newNote.LaneIndex = GetNewNoteLaneIndex(scorePos.X, newNote.Width);
Invalidate();
return moveTappableNoteHandler(newNote)
.Finally(() => OperationManager.Push(op));
}
else
{
int newNoteLaneIndex;

switch (NewNoteType)
{
case NoteType.Hold:
Expand All @@ -1116,8 +1112,7 @@ IObservable<MouseEventArgs> addAirActionHandler()
Width = LastWidth,
Duration = (int)QuantizeTick
};
newNoteLaneIndex = (int)(scorePos.X / (UnitLaneWidth + BorderThickness)) - hold.Width / 2;
hold.LaneIndex = Math.Min(Constants.LanesCount - hold.Width, Math.Max(0, newNoteLaneIndex));
hold.LaneIndex = GetNewNoteLaneIndex(scorePos.X, hold.Width);
Notes.Add(hold);
Invalidate();
return holdDurationHandler(hold)
Expand Down Expand Up @@ -1168,8 +1163,7 @@ IObservable<MouseEventArgs> addAirActionHandler()
StartTick = Math.Max(GetQuantizedTick(GetTickFromYPosition(scorePos.Y)), 0),
StartWidth = LastWidth
};
newNoteLaneIndex = (int)(scorePos.X / (UnitLaneWidth + BorderThickness)) - slide.StartWidth / 2;
slide.StartLaneIndex = Math.Min(Constants.LanesCount - slide.StartWidth, Math.Max(0, newNoteLaneIndex));
slide.StartLaneIndex = GetNewNoteLaneIndex(scorePos.X, slide.StartWidth);
var step = new Slide.StepTap(slide) { TickOffset = (int)QuantizeTick };
slide.StepNotes.Add(step);
Notes.Add(slide);
Expand Down Expand Up @@ -1623,7 +1617,7 @@ protected override void OnPaint(PaintEventArgs pe)
(UnitLaneWidth + BorderThickness) * hold.LaneIndex + BorderThickness,
GetYPositionFromTick(hold.StartTick),
(UnitLaneWidth + BorderThickness) * hold.Width - BorderThickness,
GetYPositionFromTick(hold.Duration)
GetYPositionFromTick(hold.Duration) - GetYPositionFromTick(0)
));
}

Expand Down Expand Up @@ -1827,8 +1821,6 @@ private Matrix GetDrawingMatrix(Matrix baseMatrix, bool flipY)
}
// ずれたコントロール高さ分を補正
matrix.Translate(0, ClientSize.Height - 1, MatrixOrder.Append);
// さらにずらして下端とHeadTickを合わせる
matrix.Translate(0, HeadTick * UnitBeatHeight / UnitBeatTick, MatrixOrder.Append);
// 水平方向に対して中央に寄せる
matrix.Translate((ClientSize.Width - LaneWidth) / 2, 0);

Expand All @@ -1837,12 +1829,12 @@ private Matrix GetDrawingMatrix(Matrix baseMatrix, bool flipY)

private float GetYPositionFromTick(int tick)
{
return tick * UnitBeatHeight / UnitBeatTick;
return (tick - HeadTick) * UnitBeatHeight / UnitBeatTick;
}

protected int GetTickFromYPosition(float y)
{
return (int)(y * UnitBeatTick / UnitBeatHeight);
return (int)(y * UnitBeatTick / UnitBeatHeight) + HeadTick;
}

protected int GetQuantizedTick(int tick)
Expand Down Expand Up @@ -1889,6 +1881,12 @@ private RectangleF GetClickableRectFromNotePosition(int tick, int laneIndex, int
return GetRectFromNotePosition(tick, laneIndex, width).Expand(1, 3);
}

private int GetNewNoteLaneIndex(float xpos, int width)
{
int newNoteLaneIndex = (int)Math.Round(xpos / (UnitLaneWidth + BorderThickness) - width / 2);
return Math.Min(Constants.LanesCount - width, Math.Max(0, newNoteLaneIndex));
}

private Rectangle GetSelectionRect()
{
int minTick = SelectedRange.Duration < 0 ? SelectedRange.StartTick + SelectedRange.Duration : SelectedRange.StartTick;
Expand Down
2 changes: 1 addition & 1 deletion Ched/UI/Shortcuts/ShortcutCommandSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class NullShortcutCommandSource : IShortcutCommandSource
public IEnumerable<string> Commands => Enumerable.Empty<string>();

// Do nothing
public bool ExecuteCommand(string command) => true;
public bool ExecuteCommand(string command) => false;

public bool ResolveCommandName(string command, out string name)
{
Expand Down
31 changes: 24 additions & 7 deletions Ched/UI/SoundManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading.Tasks;

using Un4seen.Bass;
using Un4seen.Bass.AddOn.Fx;

namespace Ched.UI
{
Expand Down Expand Up @@ -52,20 +53,22 @@ public void Register(string path)

protected int GetHandle(string filepath)
{
int handle = Bass.BASS_StreamCreateFile(filepath, 0, 0, BASSFlag.BASS_DEFAULT);
if (handle == 0) throw new ArgumentException("cannot create a stream.");
return handle;
int rawHandle = Bass.BASS_StreamCreateFile(filepath, 0, 0, BASSFlag.BASS_STREAM_DECODE);
if (rawHandle == 0) throw new ArgumentException("cannot create a stream.");
int tempoHandle = BassFx.BASS_FX_TempoCreate(rawHandle, BASSFlag.BASS_FX_FREESOURCE);
if (tempoHandle == 0) throw new ArgumentException("cannot create a stream.");
return tempoHandle;
}

public void Play(string path)
{
Play(path, 0);
Play(path, 0, 1.0, 1.0);
}

public void Play(string path, double offset)
public void Play(string path, double offset, double volume = 1.0, double speed = 1.0)
{
CheckSupported();
Task.Run(() => PlayInternal(path, offset))
Task.Run(() => PlayInternal(path, offset, volume, speed))
.ContinueWith(p =>
{
if (p.Exception != null)
Expand All @@ -76,7 +79,7 @@ public void Play(string path, double offset)
});
}

private void PlayInternal(string path, double offset)
private void PlayInternal(string path, double offset, double volume, double speed)
{
Queue<int> freelist;
lock (handles)
Expand Down Expand Up @@ -107,6 +110,8 @@ private void PlayInternal(string path, double offset)

lock (playing) playing.Add(handle);
Bass.BASS_ChannelSetPosition(handle, offset);
Bass.BASS_ChannelSetAttribute(handle, BASSAttribute.BASS_ATTRIB_VOL, (float)volume);
Bass.BASS_ChannelSetAttribute(handle, BASSAttribute.BASS_ATTRIB_TEMPO, (float)((speed - 1.0) * 100));
Bass.BASS_ChannelPlay(handle, false);
}

Expand Down Expand Up @@ -152,6 +157,18 @@ public class SoundSource

public string FilePath { get; set; }

private double volume = 1.0;
public double Volume
{
get => volume;
set
{
if (volume < 0 || volume > 1.0)
throw new ArgumentOutOfRangeException("value");
volume = value;
}
}

public SoundSource()
{
}
Expand Down
Loading

0 comments on commit 482afd6

Please sign in to comment.