bool LoadGrandMutusDocument(XElement root, string fileName) { // rootからMutusDocumentというメソッドはないんだっけ? MutusDocument doc = new MutusDocument(); doc.LoadGrandMutusDocument(root, fileName); // 0.6.4.2以降! NowLoading = true; try { foreach (var q in doc.Questions) { IntroQuestion question = (IntroQuestion)q; var sweet_question = new SweetQuestion(question.Song); sweet_question.PlayPos = question.PlayPos; // intro_question側で未実装. //sweet_question.StopPos = question.StopPos; sweet_question.Category = question.Category; sweet_question.No = question.No; this.AddQuestion(sweet_question); } } finally { NowLoading = false; } return(true); }
// (0.3.1) //void Questions_QuestionsRemoved(object sender, ItemEventArgs<IEnumerable<SweetQuestion>> e) //{ // AddOperationHistory(new SweetQuestionsRemovedCache(this, e.Item)); //} // (0.2.0)staticを解除。boolを返すように変更。 // (0.1.7)再生開始位置もロードするように変更. // HyperMutusからのパクリ.古いメソッドだけど,とりあえずそのまま使う. // 場所も未定.とりあえずstatic化してここに置いておく. #region *ファイルからメタデータを読み込み(LoadInformation) /// <summary> /// songのFileNameプロパティで指定されたファイルからメタデータを読み込みます. /// </summary> bool LoadInformation(SweetQuestion question) { SPP.Aldente.IID3Tag tag; try { tag = SPP.Aldente.AldenteMP3TagAccessor.ReadFile(question.FileName); } catch (IOException ex) { // 通知したい。 if (Confirm(string.Format( "読み込みに失敗しました。 - {0} \n曲情報を読み込まずに曲ファイルを追加しますか?", ex.Message))) { tag = null; } else { return(false); } } catch (ApplicationException) { tag = null; } question.Title = tag == null ? string.Empty : tag.Title; question.Artist = tag == null ? string.Empty : tag.Artist; question.SabiPos = tag == null ? TimeSpan.Zero : TimeSpan.FromSeconds(Convert.ToDouble(tag.SabiPos)); question.PlayPos = tag == null ? TimeSpan.Zero : TimeSpan.FromSeconds(Convert.ToDouble(tag.StartPos)); return(true); }
// (0.1.5)Noの処理は,1つ上(SweetQuestionsCollectionクラス)で行うようにする. // (0.1.3) #region *[static]mutus2のsong要素からオブジェクトを生成する(GenerateFromMutus2) public static SweetQuestion GenerateFromMutus2(XElement songElement, string songsRoot, string category) { // <song id="6" sabipos="21.7"> // <title>誰もいない海</title> // <artist>トワエモア</artist> // <filename>intro\JOY02554.mp3</filename> // </song> var question = new SweetQuestion(); // XMLからインスタンスを生成するならばIDは常にあるのでは? // →songをインポートする時とかはそうではないかもしれない?ので一応有無をチェックする. // →でも,インポートする時はXML経由ではなくオブジェクト経由で行った方がいいのでは?(ファイル名のパスの扱いとか...) var id_attribute = songElement.Attribute(ID_ATTRIBUTE); if (id_attribute != null) { question.ID = (int)id_attribute; } question.Category = category; // mutus2のNoは,それ以降のものとかなり仕様が違うのであった! //question.No = (int?)songElement.Attribute(NO_ATTRIBUTE); question.Title = (string)songElement.Element(TITLE_ELEMENT); question.Artist = (string)songElement.Element(ARTIST_ELEMENT); var file_name = (string)songElement.Element("filename"); // 相対パスをフルパスに直す作業が必要! if (!Path.IsPathRooted(file_name)) { file_name = Path.Combine(songsRoot, file_name); if (!Path.IsPathRooted(file_name)) { throw new ArgumentException("ファイル名が相対パスで記録されています.songsRootには,絶対パスを指定して下さい.", "songsRoot"); } } question.FileName = file_name; var sabi_pos = (double?)songElement.Attribute("sabipos"); if (sabi_pos.HasValue) { question.SabiPos = TimeSpan.FromSeconds(sabi_pos.Value); } var play_pos = (double?)songElement.Attribute("playpos"); if (play_pos.HasValue) { question.PlayPos = TimeSpan.FromSeconds(play_pos.Value); } var stop_pos = (double?)songElement.Attribute("stoppos"); if (stop_pos.HasValue) { question.StopPos = TimeSpan.FromSeconds(stop_pos.Value); } return(question); }
// (0.2.2.1)カテゴリを設定できるように改良。 // (0.2.0)曲を追加しない場合にnullを返すように変更。 #region *曲を追加(AddQuestions) /// <summary> /// このメソッドが直接呼び出されることは想定していません. /// 呼び出し元でAddSongsActionに設定されるActionの中で呼び出して下さい(ややこしい...). /// </summary> /// <param name="fileName"></param> /// <returns></returns> public SweetQuestion AddQuestion(string fileName, string category = null) { SweetQuestion question = new SweetQuestion { FileName = fileName, Category = string.IsNullOrEmpty(category) ? string.Empty : category }; if (LoadInformation(question)) { return(this.AddQuestion(question)); } else { return(null); } }
/// <summary> /// questionがnullの場合は、何もせずにnullを返します。 /// </summary> /// <param name="question"></param> /// <returns></returns> private SweetQuestion AddQuestion(SweetQuestion question) { if (question == null) { return(null); } try { _questions.Add(question); // この後の処理でSongDuplicateExceptionが発生する。 _addedSongFiles.Add(question.FileName); //SongAdded(this, new ItemEventArgs<Song> { Item = song }); return(question); } catch (SongDuplicateException) { // この時点ではsongが_songsに追加された状態になっているので、ここで削除する。 _questions.Remove(question); return(null); } }
// (0.6.0)SeekPositionに対応、 // (0.4.3)memo要素に対応。 // (0.3.3) #region *[static]XML要素からオブジェクトを生成(Generate) public static SweetQuestion Generate(XElement questionElement, string songsRoot = null) { var question = new SweetQuestion(); // XMLからインスタンスを生成するならばIDは常にあるのでは? // →songをインポートする時とかはそうではないかもしれない?ので一応有無をチェックする. // →でも,インポートする時はXML経由ではなくオブジェクト経由で行った方がいいのでは?(ファイル名のパスの扱いとか...) var id_attribute = questionElement.Attribute(ID_ATTRIBUTE); if (id_attribute != null) { question.ID = (int)id_attribute; } question.Category = (string)questionElement.Attribute(CATEGORY_ATTRIBUTE); question.No = (int?)questionElement.Attribute(NO_ATTRIBUTE); question.Title = (string)questionElement.Element(TITLE_ELEMENT); question.Artist = (string)questionElement.Element(ARTIST_ELEMENT); var file_name = (string)questionElement.Element(FILE_NAME_ELEMENT); // 相対パスをフルパスに直す作業が必要! if (!Path.IsPathRooted(file_name)) { file_name = Path.Combine(songsRoot, file_name); if (!Path.IsPathRooted(file_name)) { throw new ArgumentException("ファイル名が相対パスで記録されています.songsRootには,絶対パスを指定して下さい.", "songsRoot"); } } question.FileName = file_name; var sabi_pos = (double?)questionElement.Attribute(SABI_POS_ATTRIBUTE); if (sabi_pos.HasValue) { question.SabiPos = TimeSpan.FromSeconds(sabi_pos.Value); } var play_pos = (double?)questionElement.Attribute(PLAY_POS_ATTRIBUTE); if (play_pos.HasValue) { question.PlayPos = TimeSpan.FromSeconds(play_pos.Value); } var stop_pos = (double?)questionElement.Attribute(STOP_POS_ATTRIBUTE); if (stop_pos.HasValue) { question.StopPos = TimeSpan.FromSeconds(stop_pos.Value); } var memo = (string)questionElement.Element(MEMO_ELEMENT); if (!string.IsNullOrEmpty(memo)) { question.Memo = memo; } foreach (var seek_element in questionElement.Elements(SeekPosition.ELEMENT_NAME)) { question.SeekPositionList.Add(SeekPosition.Generate(seek_element)); ; } return(question); }
public QuestionMemoChangedCache(SweetQuestion question, string from, string to) : base(from, to) { this._question = question; }
public QuestionNoChangedCache(SweetQuestion question, int?from, int?to) : base(from, to) { this._question = question; }
public QuestionPositionChangedCache(SweetQuestion question, TimeSpan from, TimeSpan to) : base(from, to) { this._question = question; }
public QuestionStopPosChangedCache(SweetQuestion question, TimeSpan from, TimeSpan to) : base(question, from, to) { }