protected override string InternalToString(Tune t)
        {
            var sb = new StringBuilder();

            foreach (var tuneElement in t.TuneElementList)
            {
                sb.Append(DurationConverter.ToString(tuneElement.Duration));

                var note = tuneElement as Note;
                if (note != null)
                {
                    sb.Append(PitchConverter.ToString(note.Pitch));
                    sb.Append((ScaleConverter.GetValue(note.Scale) - OffsetScale).ToString(CultureInfo.InvariantCulture));
                }
                else if (tuneElement is Pause)
                {
                    sb.Append(Pause);
                }

                if (tuneElement.Dotted)
                {
                    sb.Append(Dot);
                }

                sb.Append(TuneElementDelimiter);
            }

            return(sb.ToString());
        }
예제 #2
0
        protected override string InternalToString(Tune t)
        {
            var sb = new StringBuilder();

            sb.Append(t.Name);
            sb.Append(TuneCommandDelimiter);

            var defaultDuration = t.TuneElementList.GroupBy(g => g.Duration)
                                  .OrderByDescending(o => o.Count())
                                  .First().Key;

            var defaultScale = t.TuneElementList.OfType <Note>()
                               .GroupBy(g => g.Scale)
                               .OrderByDescending(o => o.Count())
                               .First().Key;

            sb.AppendFormat("d={0},o={1},b={2}",
                            DurationConverter.ToString(defaultDuration),
                            ScaleConverter.ToString(defaultScale),
                            t.Tempo.HasValue ? t.Tempo.Value.ToString(CultureInfo.InvariantCulture) : DefaultBpm.ToString());

            sb.Append(TuneCommandDelimiter);

            foreach (var tuneElement in t.TuneElementList)
            {
                if (tuneElement.Duration != defaultDuration)
                {
                    sb.Append(DurationConverter.ToString(tuneElement.Duration));
                }

                var note = tuneElement as Note;
                if (note != null)
                {
                    sb.Append(PitchConverter.ToString(note.Pitch));
                    if (note.Scale != defaultScale)
                    {
                        sb.Append(ScaleConverter.ToString(note.Scale));
                    }
                }
                else if (tuneElement is Pause)
                {
                    sb.Append(Pause);
                }

                if (tuneElement.Dotted)
                {
                    sb.Append(Dot);
                }

                sb.Append(TuneElementDelimiter);
            }

            return(sb.ToString());
        }