/// <summary> /// Load MML from a string of code starting with 'MML@' and ending in ';' /// with tracks separated by ',' /// </summary> /// <param name="code">MML collection string to load from.</param> /// <param name="maxTracks">Maximum number of tracks allowed, 0 for infinite.</param> /// <param name="strict">Accepts files that don't start with 'MML@' and end with a semi-colon if false, throws MalformedMMLException if true</param> public void Load(string code, int maxTracks, bool strict) { if (code.Length > settings.MaxSize) { throw new SongSizeException("Song exceeded maximum length of " + settings.MaxSize); } string trimmedCode = code.Trim(new char[] { ' ', '\t', '\n', '\r' }); if (strict) { if (!trimmedCode.StartsWith("MML@", StringComparison.InvariantCultureIgnoreCase)) { throw new MalformedMMLException("Mabinogi-format MML code should start with 'MML@'"); } if (!trimmedCode.EndsWith(";", StringComparison.InvariantCultureIgnoreCase)) { throw new MalformedMMLException("Mabinogi-format MML code should end with ';'"); } trimmedCode = trimmedCode.Replace("MML@", ""); trimmedCode = trimmedCode.Remove(trimmedCode.Length - 1); } else { if (trimmedCode.StartsWith("MML@", StringComparison.InvariantCultureIgnoreCase)) { trimmedCode = trimmedCode.Replace("MML@", ""); } if (trimmedCode.EndsWith(";", StringComparison.InvariantCultureIgnoreCase)) { trimmedCode = trimmedCode.Remove(trimmedCode.Length - 1); } } var tokens = code.Split(','); if (tokens.Length > maxTracks && maxTracks > 0) { throw new MalformedMMLException("Maximum number of tracks exceeded. Count: " + tokens.Length + ", max: " + maxTracks); } tracks = new List <MMLPlayerTrack>(); for (int i = 0; i < tokens.Length; ++i) { var track = new MMLPlayerTrack(this); track.Settings = settings; track.Load(tokens[i]); track.Mode = mmlMode; tracks.Add(track); } CalculateDuration(); }
public void Load(string code, int maxTracks) { string trimmedCode = code.Trim().TrimEnd(new char[] { '\n', '\r' }).TrimStart(new char[] { '\n', '\r' }); if (trimmedCode.StartsWith("MML@", StringComparison.InvariantCultureIgnoreCase)) { trimmedCode = trimmedCode.Replace("MML@", ""); } if (trimmedCode.EndsWith(";", StringComparison.InvariantCultureIgnoreCase)) { trimmedCode = trimmedCode.Remove(trimmedCode.Length - 1); } string[] tokens = code.Split(',', StringSplitOptions.None); if (tokens.Length > maxTracks && maxTracks > 0) { throw new MalformedMMLException("Maximum number of tracks exceeded. Count: " + tokens.Length.ToString() + ", max: " + maxTracks.ToString()); } this.Tracks = new List <MMLPlayerTrack>(); for (int i = 0; i < tokens.Length; i++) { MMLPlayerTrack track = new MMLPlayerTrack(this) { Settings = this.Settings }; track.Load(tokens[i]); track.Mode = this.mmlMode; this.Tracks.Add(track); } this.CalculateDuration(); }
/// <summary> /// Load MML from a string of code starting with 'MML@' and ending in ';' /// with tracks separated by ',' /// </summary> /// <param name="code">MML collection string to load from.</param> /// <param name="maxTracks">Maximum number of tracks allowed, 0 for infinite.</param> public void Load(string code, int maxTracks) { //if (code.Length > settings.MaxSize) { // throw new SongSizeException("Song exceeded maximum length of " + settings.MaxSize); //} string trimmedCode = code.Trim().TrimEnd('\n', '\r').TrimStart('\n', '\r'); if (trimmedCode.StartsWith("MML@", StringComparison.InvariantCultureIgnoreCase)) { trimmedCode = trimmedCode.Replace("MML@", ""); } if (trimmedCode.EndsWith(";", StringComparison.InvariantCultureIgnoreCase)) { trimmedCode = trimmedCode.Remove(trimmedCode.Length - 1); } var tokens = code.Split(','); if (tokens.Length > maxTracks && maxTracks > 0) { throw new MalformedMMLException("Maximum number of tracks exceeded. Count: " + tokens.Length + ", max: " + maxTracks); } Tracks = new List <MMLPlayerTrack>(); for (int i = 0; i < tokens.Length; ++i) { var track = new MMLPlayerTrack(this) { Settings = Settings }; track.Load(tokens[i]); track.Mode = mmlMode; Tracks.Add(track); } CalculateDuration(); }
/// <summary> /// Load MML from a string of code starting with 'MML@' and ending in ';' /// with tracks separated by ',' /// </summary> /// <param name="code">MML collection string to load from.</param> /// <param name="maxTracks">Maximum number of tracks allowed, 0 for infinite.</param> public void Load(string code, int maxTracks) { if (code.Length > settings.MaxSize) { throw new SongSizeException("Song exceeded maximum length of " + settings.MaxSize); } string trimmedCode = code.Trim().TrimEnd('\n', '\r').TrimStart('\n', '\r'); if (trimmedCode.StartsWith("MML@", StringComparison.InvariantCultureIgnoreCase)) trimmedCode = trimmedCode.Replace("MML@", ""); if (trimmedCode.EndsWith(";", StringComparison.InvariantCultureIgnoreCase)) trimmedCode = trimmedCode.Remove(trimmedCode.Length - 1); var tokens = code.Split(','); if (tokens.Length > maxTracks && maxTracks > 0) throw new MalformedMMLException("Maximum number of tracks exceeded. Count: " + tokens.Length + ", max: " + maxTracks); tracks = new List<MMLPlayerTrack>(); for (int i = 0; i < tokens.Length; ++i){ var track = new MMLPlayerTrack(this); track.Settings = settings; track.Load(tokens[i]); track.Mode = mmlMode; tracks.Add(track); } CalculateDuration(); }