Skip to content

Commit

Permalink
Implement analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
yukozh committed Jun 18, 2016
1 parent 8d73cc8 commit e654075
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 3 deletions.
43 changes: 43 additions & 0 deletions src/TentacleGuitar.Tabular/Analyzer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Xml;

namespace TentacleGuitar.Tabular
{
public static class Analyzer
{
public static Tabular ParseMusicXml(string xml)
{
var ret = new Tabular();
var xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xml);

// 获取每分钟节拍数
ret.BPM = Convert.ToInt32(xmlDoc.GetElementsByTagName("per-minute").Item(0).Value.ToString());

// 获取调弦信息
var tuning = xmlDoc.GetElementsByTagName("staff-tuning");
foreach (XmlNode x in tuning)
ret.Staff.Add(new Staff { TuningStep = x.FirstChild.Value.ToString(), TuningOctave = Convert.ToInt32(x.LastChild.Value.ToString()) });

// 获取全部小节
var measures = xmlDoc.GetElementsByTagName("measure");
foreach(XmlNode x in measures)
{
int beats, beatType; // 定义拍号信息
int timePerBeat; // 定义每拍占用毫秒数

// 判断小节是否变奏
if (x.ChildNodes.Cast<XmlNode>().Where(y => y.Name == "attributes").Count() > 0 && x.ChildNodes.Cast<XmlNode>().First(y => y.Name == "attributes").Cast<XmlNode>().Where(y => y.Name == "time").Count() > 0)
{
var time = x.ChildNodes.Cast<XmlNode>().First(y => y.Name == "attributes").Cast<XmlNode>().Where(y => y.Name == "time").First();
beats = Convert.ToInt32(time.FirstChild.Value.ToString());
beatType = Convert.ToInt32(time.LastChild.Value.ToString());
timePerBeat = 60 * 1000 / ret.BPM;
}
}
}
}
}
11 changes: 11 additions & 0 deletions src/TentacleGuitar.Tabular/Note.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,19 @@ namespace TentacleGuitar.Tabular
{
public class Note
{
/// <summary>
/// 品
/// </summary>
public int Fret { get; set; }

/// <summary>
/// 弦
/// </summary>
public string String { get; set; }

/// <summary>
/// 持续时长
/// </summary>
public int Duration { get; set; }
}
}
19 changes: 16 additions & 3 deletions src/TentacleGuitar.Tabular/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,24 @@
},

"frameworks": {
"net40": { },
"net451": { },
"net40": {
"frameworkAssemblies": {
"System.Xml": "4.0.0.0"
}
},
"net451": {
"frameworkAssemblies": {
"System.Xml": "4.0.0.0"
}
},
"netstandard1.5": {
"dependencies": {
"NETStandard.Library": "1.5.0-rc2-24027"
"NETStandard.Library": "1.5.0-rc2-24027",
"System.Xml.XDocument": "4.0.11-rc2-24027",
"System.Xml.ReaderWriter": "4.0.11-rc2-24027",
"System.Xml.XmlDocument": "4.0.1-rc2-24027",
"System.Xml.XmlSerializer": "4.0.11-rc2-24027",
"System.Xml.XPath": "4.0.1-rc2-24027"
},
"imports": [
"dnxcore50",
Expand Down

0 comments on commit e654075

Please sign in to comment.