예제 #1
0
 /// <summary>
 /// Loads the specified music file.
 /// </summary>
 /// <param name="musicFileName">Path of the music file.</param>
 private void Load(string musicFileName)
 {
     List<MoodNode> nodes = new List<MoodNode>();
     XmlSerializer phraseDeserializer = new XmlSerializer(typeof(Phrase));
     XPathDocument doc = new XPathDocument(musicFileName);
     XPathNavigator navi = doc.CreateNavigator();
     foreach (XPathNavigator item in navi.Select("Phrase"))
     {
         Phrase phrase = (Phrase)phraseDeserializer.Deserialize(new StringReader(item.OuterXml));
         nodes.Add(new MoodNode(phrase.Mood, phrase));
     }
     musicGraph = new Graph<Mood>();
     foreach (XPathNavigator item in navi.Select("Edge"))
     {
         //Get from item
         string fromPath = item.SelectSingleNode("From").Value;
         MoodNode fromNode = nodes.Find((e) => { return (e.Phrase.FileName == fromPath); });
         //Get to item
         string toPath = item.SelectSingleNode("To").Value;
         MoodNode toNode = nodes.Find((e) => { return (e.Phrase.FileName == toPath); });
         musicGraph.AddDirectedEdge(fromNode, toNode, (int)fromNode.Phrase.Duration.TotalMilliseconds);
     }
 }
예제 #2
0
 public Music()
 {
     musicGraph = new Graph<Mood>();
 }