Skip to content

Commit

Permalink
Merge branch 'release/3.0.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
paralleltree committed Feb 18, 2021
2 parents cc411ad + baddd43 commit 6154686
Show file tree
Hide file tree
Showing 54 changed files with 1,076 additions and 396 deletions.
7 changes: 3 additions & 4 deletions Ched.Core/Ched.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Ched.Core</RootNamespace>
<AssemblyName>Ched.Core</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
Expand Down Expand Up @@ -66,7 +66,7 @@
<Compile Include="BarIndexCalculator.cs" />
<Compile Include="Constants.cs" />
<Compile Include="EventCollection.cs" />
<Compile Include="Events\BPMChangeEvent.cs" />
<Compile Include="Events\BpmChangeEvent.cs" />
<Compile Include="Events\EventBase.cs" />
<Compile Include="Events\HighSpeedChangeEvent.cs" />
<Compile Include="Events\InvalidTimeSignatureException.cs" />
Expand All @@ -79,14 +79,13 @@
<Compile Include="Notes\Flick.cs" />
<Compile Include="Notes\Hold.cs" />
<Compile Include="Notes\LongNoteBase.cs" />
<Compile Include="Notes\NoteBase.cs" />
<Compile Include="Notes\ShortNoteBase.cs" />
<Compile Include="Notes\Slide.cs" />
<Compile Include="Notes\Tap.cs" />
<Compile Include="Notes\TappableBase.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Score.cs" />
<Compile Include="ScoreBook.cs" />
<Compile Include="TimeCalculator.cs" />
<Compile Include="UI\SelectionRange.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions Ched.Core/EventCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ namespace Ched.Core
public class EventCollection
{
[Newtonsoft.Json.JsonProperty]
private List<BPMChangeEvent> bpmChangeEvents = new List<BPMChangeEvent>();
private List<BpmChangeEvent> bpmChangeEvents = new List<BpmChangeEvent>();
[Newtonsoft.Json.JsonProperty]
private List<TimeSignatureChangeEvent> timeSignatureChangeEvents = new List<TimeSignatureChangeEvent>();
[Newtonsoft.Json.JsonProperty]
private List<HighSpeedChangeEvent> highSpeedChangeEvents = new List<HighSpeedChangeEvent>();

public List<BPMChangeEvent> BPMChangeEvents
public List<BpmChangeEvent> BpmChangeEvents
{
get { return bpmChangeEvents; }
set { bpmChangeEvents = value; }
Expand All @@ -40,13 +40,13 @@ public List<HighSpeedChangeEvent> HighSpeedChangeEvents
}

public IEnumerable<EventBase> AllEvents =>
BPMChangeEvents.Cast<EventBase>()
BpmChangeEvents.Cast<EventBase>()
.Concat(TimeSignatureChangeEvents)
.Concat(HighSpeedChangeEvents);

public void UpdateTicksPerBeat(double factor)
{
var events = BPMChangeEvents.Cast<EventBase>()
var events = BpmChangeEvents.Cast<EventBase>()
.Concat(TimeSignatureChangeEvents)
.Concat(HighSpeedChangeEvents);
foreach (var e in events)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ namespace Ched.Core.Events
/// BPMの変更イベントを表すクラスです。
/// </summary>
[Newtonsoft.Json.JsonObject(Newtonsoft.Json.MemberSerialization.OptIn)]
[DebuggerDisplay("Tick = {Tick}, Value = {BPM}")]
public class BPMChangeEvent : EventBase
[DebuggerDisplay("Tick = {Tick}, Value = {Bpm}")]
public class BpmChangeEvent : EventBase
{
[Newtonsoft.Json.JsonProperty]
private decimal bpm;
private double bpm;

public decimal BPM
public double Bpm
{
get { return bpm; }
set { bpm = value; }
Expand Down
2 changes: 1 addition & 1 deletion Ched.Core/Notes/Air.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Ched.Core.Notes
{
[Newtonsoft.Json.JsonObject(Newtonsoft.Json.MemberSerialization.OptIn)]
public class Air : ShortNoteBase, IAirable
public class Air
{
[Newtonsoft.Json.JsonProperty]
private IAirable parentNote;
Expand Down
8 changes: 4 additions & 4 deletions Ched.Core/Notes/AirAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Ched.Core.Notes
{
[Newtonsoft.Json.JsonObject(Newtonsoft.Json.MemberSerialization.OptIn)]
public class AirAction : LongNoteBase
public class AirAction : ILongNote
{
[Newtonsoft.Json.JsonProperty]
private IAirable parentNote;
Expand All @@ -16,7 +16,7 @@ public class AirAction : LongNoteBase

public List<ActionNote> ActionNotes { get { return actionNotes; } }
public IAirable ParentNote { get { return parentNote; } }
public override int StartTick { get { return ParentNote.Tick; } }
public int StartTick => ParentNote.Tick;

/// <summary>
/// 親<see cref="IAirable"/>オブジェクトを持たない<see cref="AirAction"/>の新しいインスタンスを初期化します。
Expand All @@ -35,14 +35,14 @@ public AirAction(IAirable parent)
parentNote = parent;
}

public override int GetDuration()
public int GetDuration()
{
return ActionNotes.Max(p => p.Offset);
}


[Newtonsoft.Json.JsonObject(Newtonsoft.Json.MemberSerialization.OptIn)]
public class ActionNote : ShortNoteBase
public class ActionNote
{
[Newtonsoft.Json.JsonProperty]
private int offset;
Expand Down
14 changes: 4 additions & 10 deletions Ched.Core/Notes/LongNoteBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,20 @@
namespace Ched.Core.Notes
{
public interface ILongNote
{
int StartTick { get; }
int GetDuration();
}

public abstract class LongNoteBase : NoteBase, ILongNote
{
/// <summary>
/// ノートの開始位置を表すTickを設定します。
/// </summary>
public abstract int StartTick { get; }
int StartTick { get; }

/// <summary>
/// ノートの長さを表すTickを取得します。
/// </summary>
public abstract int GetDuration();
int GetDuration();
}

[Newtonsoft.Json.JsonObject(Newtonsoft.Json.MemberSerialization.OptIn)]
public abstract class MovableLongNoteBase : NoteBase, ILongNote
public abstract class MovableLongNoteBase : ILongNote
{
[Newtonsoft.Json.JsonProperty]
private int startTick;
Expand All @@ -51,7 +45,7 @@ public int StartTick
public abstract int GetDuration();
}

public abstract class LongNoteTapBase : TapBase, IAirable
public abstract class LongNoteTapBase : IAirable
{
public abstract bool IsTap { get; }
public abstract int LaneIndex { get; }
Expand Down
12 changes: 0 additions & 12 deletions Ched.Core/Notes/NoteBase.cs

This file was deleted.

12 changes: 0 additions & 12 deletions Ched.Core/Notes/ShortNoteBase.cs

This file was deleted.

6 changes: 1 addition & 5 deletions Ched.Core/Notes/TappableBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@

namespace Ched.Core.Notes
{
public abstract class TapBase : ShortNoteBase
{
}

[Newtonsoft.Json.JsonObject(Newtonsoft.Json.MemberSerialization.OptIn)]
public abstract class TappableBase : TapBase, IAirable
public abstract class TappableBase : IAirable
{
[Newtonsoft.Json.JsonProperty]
private int tick;
Expand Down
2 changes: 1 addition & 1 deletion Ched.Core/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
[assembly: ComVisible(false)]
[assembly: Guid("5a5ff947-79dc-4352-94d5-eec14065f93a")]

[assembly: AssemblyVersion("2.7.0.0")]
[assembly: AssemblyVersion("3.0.0.0")]
16 changes: 12 additions & 4 deletions Ched.Core/ScoreBook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class ScoreBook
[Newtonsoft.Json.JsonProperty]
private Score score = new Score();
[Newtonsoft.Json.JsonProperty]
private Dictionary<string, object> exporterArgs = new Dictionary<string, object>();
private Dictionary<string, string> exportArgs = new Dictionary<string, string>();

public string Path { get; set; }

Expand Down Expand Up @@ -90,10 +90,10 @@ public Score Score
/// <summary>
/// エクスポート用の設定を格納します。
/// </summary>
public Dictionary<string, object> ExporterArgs
public Dictionary<string, string> ExportArgs
{
get { return exporterArgs; }
set { exporterArgs = value; }
get { return exportArgs; }
set { exportArgs = value; }
}

public void Save(string path)
Expand All @@ -116,6 +116,8 @@ public void Save()
}
}

public ScoreBook Clone() => JsonConvert.DeserializeObject<ScoreBook>(JsonConvert.SerializeObject(this, SerializerSettings));

/// <summary>
/// 指定のファイルから<see cref="ScoreBook"/>のインスタンスを生成します。
/// 古いバージョンのファイルは現在のバージョン用に変換されます。
Expand Down Expand Up @@ -149,6 +151,12 @@ public static ScoreBook LoadFile(string path)
type = System.Text.RegularExpressions.Regex.Replace(type, "Ched$", "Ched.Core").Replace("Components", "Core");
obj["$type"] = type;
}

var susExportArgs = doc["exporterArgs"]["sus"];
var exportArgs = new JObject();
if (susExportArgs != null) exportArgs.Add("Ched.Plugins.SusExportPlugin", susExportArgs.ToString());
doc.Remove("exporterArgs");
doc.Add("exportArgs", exportArgs);
}

doc["version"] = JObject.FromObject(CurrentVersion);
Expand Down
62 changes: 62 additions & 0 deletions Ched.Core/TimeCalculator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Ched.Core.Events;

namespace Ched.Core
{
/// <summary>
/// BPM変更イベントからTick値に対応する時刻を求めるクラスです。
/// </summary>
public class TimeCalculator
{
protected int TicksPerBeat { get; }
// 時間順ソート済み
protected List<(int Tick, double Bpm, double Time)> BpmDefinitions { get; } = new List<(int Tick, double Bpm, double Time)>();

public TimeCalculator(int ticksPerBeat, IEnumerable<BpmChangeEvent> bpms)
{
TicksPerBeat = ticksPerBeat;
double time = 0;
var ordered = bpms.OrderBy(p => p.Tick).ToList();
if (ordered[0].Tick != 0) throw new ArgumentException("Initial BpmChangeEvent was not found.", "bpms");
BpmDefinitions.Add((0, ordered[0].Bpm, 0));
for (int i = 1; i < ordered.Count; i++)
{
time += GetDuration(ordered[i - 1].Bpm, ordered[i].Tick - ordered[i - 1].Tick);
BpmDefinitions.Add((ordered[i].Tick, ordered[i].Bpm, time));
}
}

public double GetTimeFromTick(int tick)
{
for (int i = BpmDefinitions.Count - 1; 0 <= i; i--)
{
if (tick < BpmDefinitions[i].Tick) continue;
return BpmDefinitions[i].Time + GetDuration(BpmDefinitions[i].Bpm, tick - BpmDefinitions[i].Tick);
}
// 負の時間は初期BPMで遡る
return GetDuration(BpmDefinitions[0].Bpm, tick);
}

public int GetTickFromTime(double time)
{
for (int i = BpmDefinitions.Count - 1; 0 <= i; i--)
{
if (time < BpmDefinitions[i].Time) continue;
return BpmDefinitions[i].Tick + GetDurationInTick(BpmDefinitions[i].Bpm, time - BpmDefinitions[i].Time);
}
// 負の時間は初期BPMで遡る
return GetDurationInTick(BpmDefinitions[0].Bpm, time);
}

// => durationTick * (60 / bpm) / TicksPerBeat;
protected double GetDuration(double bpm, int durationTick) => durationTick * 60 / bpm / TicksPerBeat;

// => TicksPerBeat * duration * (bpm / 60)
protected int GetDurationInTick(double bpm, double duration) => (int)(TicksPerBeat * duration * bpm / 60);
}
}
2 changes: 1 addition & 1 deletion Ched.Drawing/Ched.Drawing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Ched.Drawing</RootNamespace>
<AssemblyName>Ched.Drawing</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion Ched.Drawing/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
[assembly: ComVisible(false)]
[assembly: Guid("a41ea7d5-9776-421b-a338-dd662287069b")]

[assembly: AssemblyVersion("2.7.0.0")]
[assembly: AssemblyVersion("3.0.0.0")]
5 changes: 4 additions & 1 deletion Ched.Plugins/Ched.Plugins.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Ched.Plugins</RootNamespace>
<AssemblyName>Ched.Plugins</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
Expand Down Expand Up @@ -54,10 +54,13 @@
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup>
<Compile Include="Diagnostics.cs" />
<Compile Include="IScoreBookExportPlugin.cs" />
<Compile Include="IScoreBookImportPlugin.cs" />
<Compile Include="IPlugin.cs" />
<Compile Include="IScorePlugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UserCancelledException.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Ched.Core\Ched.Core.csproj">
Expand Down
33 changes: 33 additions & 0 deletions Ched.Plugins/Diagnostics.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ched.Plugins
{
public interface IDiagnosable
{
void ReportDiagnostic(Diagnostic diagnostic);
}

public class Diagnostic
{
public DiagnosticSeverity Severity { get; }
public string Message { get; }

public Diagnostic(DiagnosticSeverity severity, string message)
{
Severity = severity;
Message = message;
}
}

public enum DiagnosticSeverity
{
Hidden = 0,
Information = 1,
Warning = 2,
Error = 3
}
}
Loading

0 comments on commit 6154686

Please sign in to comment.