private static TimeProcessingInstruction CorrectObjectOnStartQuantizing(TObject obj, long time, TempoMap tempoMap, TSettings settings) { if (settings.FixOppositeEnd) { var endTime = obj.Time + obj.Length; if (time > endTime) { var result = ProcessQuantizingBeyondFixedEnd(ref time, ref endTime, settings.QuantizingBeyondFixedEndPolicy, "Start time is going to be beyond the end one."); if (result != null) { return(result); } } obj.Length = endTime - time; } else { var length = obj.LengthAs(settings.LengthType, tempoMap); obj.Length = LengthConverter.ConvertFrom(length, time, tempoMap); } return(new TimeProcessingInstruction(time)); }
private static double ConvertLength(string value) { LengthConverter lengthConverter = new LengthConverter(); double result = (double)lengthConverter.ConvertFrom(value); return(result); }
public override PatternActionResult Invoke(long time, PatternContext context) { if (State != PatternActionState.Enabled) { return(PatternActionResult.DoNothing); } context.SaveTime(time); return(new PatternActionResult(time + LengthConverter.ConvertFrom(Step, time, context.TempoMap))); }
/// <summary> /// Splits objects into the specified number of parts of the equal length. /// </summary> /// <remarks> /// Nulls will not be splitted and will be returned as nulls. If an object has zero length, /// it will be splitted into the specified number of parts of zero length. /// </remarks> /// <param name="objects">Objects to split.</param> /// <param name="partsNumber">The number of parts to split objects into.</param> /// <param name="lengthType">Type of a part's length.</param> /// <param name="tempoMap">Tempo map used to calculate times to split by.</param> /// <returns>Objects that are result of splitting <paramref name="objects"/> going in the same /// order as elements of <paramref name="objects"/>.</returns> /// <exception cref="ArgumentNullException"><paramref name="objects"/> is null. -or- /// <paramref name="tempoMap"/> is null.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="partsNumber"/> is zero or negative.</exception> /// <exception cref="InvalidEnumArgumentException"><paramref name="lengthType"/> specified an invalid value.</exception> public IEnumerable <TObject> SplitByPartsNumber(IEnumerable <TObject> objects, int partsNumber, TimeSpanType lengthType, TempoMap tempoMap) { ThrowIfArgument.IsNull(nameof(objects), objects); ThrowIfArgument.IsNonpositive(nameof(partsNumber), partsNumber, "Parts number is zero or negative."); ThrowIfArgument.IsInvalidEnumValue(nameof(lengthType), lengthType); ThrowIfArgument.IsNull(nameof(tempoMap), tempoMap); foreach (var obj in objects) { if (obj == null) { yield return(default(TObject)); continue; } if (partsNumber == 1) { yield return(CloneObject(obj)); continue; } if (obj.Length == 0) { foreach (var i in Enumerable.Range(0, partsNumber)) { yield return(CloneObject(obj)); } continue; } var time = obj.Time; var tail = CloneObject(obj); for (int partsRemaining = partsNumber; partsRemaining > 1 && tail != null; partsRemaining--) { var length = tail.LengthAs(lengthType, tempoMap); var partLength = length.Divide(partsRemaining); time += LengthConverter.ConvertFrom(partLength, time, tempoMap); var parts = SplitObject(tail, time); yield return(parts.LeftPart); tail = parts.RightPart; } if (tail != null) { yield return(tail); } } }
public Note GetNote(TempoMap tempoMap) { return(new Note(NoteNumber) { Channel = Channel, Velocity = Velocity, OffVelocity = OffVelocity, Time = TimeConverter.ConvertFrom(Time, tempoMap), Length = LengthConverter.ConvertFrom(Length, Time, tempoMap) }); }
private static void Quantize(MidiFile midiFile, MusicalLength step) { var tempoMap = midiFile.GetTempoMap(); var stepTicks = LengthConverter.ConvertFrom(step, 0, tempoMap); midiFile.ProcessNotes(n => { var time = n.Time; n.Time = (long)Math.Round(time / (double)stepTicks) * stepTicks; }); }
public PatternActionResult Invoke(long time, PatternContext context) { context.SaveTime(time); var chordLength = LengthConverter.ConvertFrom(ChordDescriptor.Length, time, context.TempoMap); return(new PatternActionResult(time + chordLength, ChordDescriptor.Notes.Select(d => new Note(d.NoteNumber, chordLength, time) { Channel = context.Channel, Velocity = ChordDescriptor.Velocity }))); }
private static TimeProcessingInstruction CorrectObjectOnEndQuantizing(TObject obj, long time, TempoMap tempoMap, TSettings settings) { if (settings.FixOppositeEnd) { var startTime = obj.Time; if (time < startTime) { var result = ProcessQuantizingBeyondFixedEnd(ref time, ref startTime, settings.QuantizingBeyondFixedEndPolicy, "End time is going to be beyond the start one."); if (result != null) { return(result); } } LengthSetter.SetObjectLength(obj, time - startTime); } else { var length = obj.LengthAs(settings.LengthType, tempoMap); var newStartTime = settings.LengthType == TimeSpanType.Midi ? time - obj.Length : TimeConverter.ConvertFrom(((MidiTimeSpan)time).Subtract(length, TimeSpanMode.TimeLength), tempoMap); if (newStartTime < 0) { switch (settings.QuantizingBeyondZeroPolicy) { case QuantizingBeyondZeroPolicy.Skip: return(TimeProcessingInstruction.Skip); case QuantizingBeyondZeroPolicy.Abort: throw new InvalidOperationException("Object is going to be moved beyond zero."); case QuantizingBeyondZeroPolicy.FixAtZero: LengthSetter.SetObjectLength(obj, time); break; } } else { LengthSetter.SetObjectLength(obj, LengthConverter.ConvertFrom(length, newStartTime, tempoMap)); } } return(new TimeProcessingInstruction(time)); }
public PatternActionResult Invoke(long time, PatternContext context) { context.SaveTime(time); var noteLength = LengthConverter.ConvertFrom(NoteDescriptor.Length, time, context.TempoMap); var note = new Note(NoteDescriptor.Note.NoteNumber, noteLength, time) { Channel = context.Channel, Velocity = NoteDescriptor.Velocity }; return(new PatternActionResult(time + noteLength, new[] { note })); }
private static IEnumerable <MidiEvent> GetEventsForPlayback(IEnumerable <EventToSend> eventsToSend, TempoMap tempoMap) { var eventsForPlayback = new List <MidiEvent>(); var currentTime = TimeSpan.Zero; foreach (var eventToSend in eventsToSend) { var midiEvent = eventToSend.Event.Clone(); midiEvent.DeltaTime = LengthConverter.ConvertFrom((MetricTimeSpan)eventToSend.Delay, (MetricTimeSpan)currentTime, tempoMap); currentTime += eventToSend.Delay; eventsForPlayback.Add(midiEvent); } return(eventsForPlayback); }
public static MidiFile TestNotes(Pattern pattern, ICollection <NoteInfo> expectedNotesInfos, params Tuple <long, Tempo>[] tempoChanges) { TempoMap tempoMap; using (var tempoMapManager = new TempoMapManager()) { foreach (var tempoChange in tempoChanges) { tempoMapManager.SetTempo(tempoChange.Item1, tempoChange.Item2); } tempoMap = tempoMapManager.TempoMap; } var midiFile = pattern.ToFile(tempoMap, Channel); var expectedNotes = expectedNotesInfos.Select(i => { var expectedTime = TimeConverter.ConvertFrom(i.Time ?? new MetricTimeSpan(), tempoMap); var expectedLength = LengthConverter.ConvertFrom(i.Length, expectedTime, tempoMap); return(new DryWetMidi.Interaction.Note(i.NoteNumber, expectedLength, expectedTime) { Velocity = i.Velocity, Channel = Channel }); }) .OrderBy(n => n.Time) .ToArray(); var actualNotes = midiFile.GetNotes().ToArray(); Assert.AreEqual(expectedNotes.Length, actualNotes.Length, "Notes count is invalid."); var j = 0; foreach (var expectedActual in expectedNotes.Zip(actualNotes, (e, a) => new { Expected = e, Actual = a })) { var expectedNote = expectedActual.Expected; var actualNote = expectedActual.Actual; Assert.IsTrue(NoteEquality.AreEqual(expectedNote, actualNote), $"Note {j} is invalid. Expected: {expectedNote}; actual: {actualNote}."); j++; } return(midiFile); }
private void SplitByGrid_MultipleSteps(IEnumerable <TObject> inputObjects, ITimeSpan gridStart, IEnumerable <ITimeSpan> gridSteps, Dictionary <TObject, IEnumerable <TimeAndLength> > expectedParts, TempoMap tempoMap) { var expectedObjects = expectedParts .SelectMany(p => p.Value.Select(tl => CloneAndChangeTimeAndLength( p.Key, TimeConverter.ConvertFrom(tl.Time, tempoMap), LengthConverter.ConvertFrom(tl.Length, tl.Time, tempoMap)))) .ToArray(); var actualObjects = Splitter.SplitByGrid(inputObjects, new SteppedGrid(gridStart, gridSteps), tempoMap).ToArray(); ObjectMethods.AssertCollectionsAreEqual(expectedObjects, actualObjects); }
/// <summary> /// Splits objects by the specified step so every object will be splitted at points /// equally distanced from each other starting from the object's start time. /// </summary> /// <remarks> /// Nulls, objects with zero length and objects with length smaller than <paramref name="step"/> /// will not be splitted and will be returned as clones of the input objects. /// </remarks> /// <param name="objects">Objects to split.</param> /// <param name="step">Step to split objects by.</param> /// <param name="tempoMap">Tempo map used to calculate times to split by.</param> /// <returns>Objects that are result of splitting <paramref name="objects"/> going in the same /// order as elements of <paramref name="objects"/>.</returns> /// <exception cref="ArgumentNullException"><paramref name="objects"/> is null. -or- /// <paramref name="step"/> is null. -or- <paramref name="tempoMap"/> is null.</exception> public IEnumerable <TObject> SplitByStep(IEnumerable <TObject> objects, ITimeSpan step, TempoMap tempoMap) { ThrowIfArgument.IsNull(nameof(objects), objects); ThrowIfArgument.IsNull(nameof(step), step); ThrowIfArgument.IsNull(nameof(tempoMap), tempoMap); foreach (var obj in objects) { if (obj == null) { yield return(default(TObject)); continue; } if (obj.Length == 0) { yield return(CloneObject(obj)); continue; } var startTime = obj.Time; var endTime = startTime + obj.Length; var time = startTime; var tail = CloneObject(obj); while (time < endTime && tail != null) { var convertedStep = LengthConverter.ConvertFrom(step, time, tempoMap); if (convertedStep == 0) { throw new InvalidOperationException("Step is too small."); } time += convertedStep; var parts = SplitObject(tail, time); yield return(parts.LeftPart); tail = parts.RightPart; } } }
public static void TestConversion <TTimeSpan>(TTimeSpan timeSpan, ITimeSpan referenceTimeSpan, ITimeSpan time, TempoMap tempoMap) where TTimeSpan : ITimeSpan { time = time ?? new MidiTimeSpan(); var ticks = LengthConverter.ConvertFrom(timeSpan, time, tempoMap); AreEqual(timeSpan, LengthConverter.ConvertTo <TTimeSpan>(ticks, time, tempoMap), "Cyclic conversion failed."); AreEqual(timeSpan, LengthConverter.ConvertTo <TTimeSpan>(referenceTimeSpan, time, tempoMap), "ConvertTo failed."); Assert.AreEqual(LengthConverter.ConvertFrom(referenceTimeSpan, time, tempoMap), ticks, "ConvertFrom failed."); }
private MidiFile To(MusicItem data) { var midiFile = new MidiFile(); var tempoMap = midiFile.GetTempoMap(); var trackChunk = new TrackChunk(); using (var notesManager = trackChunk.ManageNotes()) { var length = LengthConverter.ConvertFrom( 2 * MusicalTimeSpan.Eighth.Triplet(), 0, tempoMap); var note = new Melanchall.DryWetMidi.Interaction.Note(NoteName.A, 4, length); notesManager.Notes.Add(note); } midiFile.Chunks.Add(trackChunk); return(midiFile); }
/// <summary> /// Gets points in time of the current grid. /// </summary> /// <param name="tempoMap">Tempo map used to get grid's times.</param> /// <returns>Collection of points in time of the current grid.</returns> /// <exception cref="ArgumentNullException"><paramref name="tempoMap"/> is null.</exception> public IEnumerable <long> GetTimes(TempoMap tempoMap) { ThrowIfArgument.IsNull(nameof(tempoMap), tempoMap); if (!Steps.Any()) { yield break; } var time = TimeConverter.ConvertFrom(Start, tempoMap); yield return(time); while (true) { foreach (var step in Steps) { time += LengthConverter.ConvertFrom(step, time, tempoMap); yield return(time); } } }
public override PatternActionResult Invoke(long time, PatternContext context) { if (State == PatternActionState.Excluded) { return(PatternActionResult.DoNothing); } context.SaveTime(time); var chordLength = LengthConverter.ConvertFrom(ChordDescriptor.Length, time, context.TempoMap); if (State == PatternActionState.Disabled) { return(new PatternActionResult(time + chordLength)); } return(new PatternActionResult(time + chordLength, ChordDescriptor.Notes.Select(d => new Note(d.NoteNumber, chordLength, time) { Channel = context.Channel, Velocity = ChordDescriptor.Velocity }))); }
public static MidiFile TestNotes(Pattern pattern, ICollection <NoteInfo> expectedNotesInfos, params Tuple <long, Tempo>[] tempoChanges) { TempoMap tempoMap; using (var tempoMapManager = new TempoMapManager()) { foreach (var tempoChange in tempoChanges) { tempoMapManager.SetTempo(tempoChange.Item1, tempoChange.Item2); } tempoMap = tempoMapManager.TempoMap; } var midiFile = pattern.ToFile(tempoMap, Channel); var expectedNotes = expectedNotesInfos.Select(i => { var expectedTime = TimeConverter.ConvertFrom(i.Time ?? new MetricTimeSpan(), tempoMap); var expectedLength = LengthConverter.ConvertFrom(i.Length, expectedTime, tempoMap); return(new DryWetMidi.Interaction.Note(i.NoteNumber, expectedLength, expectedTime) { Velocity = i.Velocity, Channel = Channel }); }) .OrderBy(n => n.Time) .ToArray(); var actualNotes = midiFile.GetNotes().ToArray(); MidiAsserts.AreEqual(expectedNotes, actualNotes, "Notes are invalid."); return(midiFile); }
public void ConvertCsvToMidiFile_NoteLength_Metric(NoteNumberFormat noteNumberFormat, string[] csvLines) { var midiFile = ConvertCsvToMidiFile(MidiFileCsvLayout.DryWetMidi, TimeSpanType.Midi, csvLines, NoteFormat.Note, noteNumberFormat, TimeSpanType.Metric); var tempoMap = TempoMap.Default; var expectedObjects = new ITimedObject[] { new Note((SevenBitNumber)50, LengthConverter.ConvertFrom(new MetricTimeSpan(0, 0, 10), 0, tempoMap), 0) { Channel = (FourBitNumber)10, Velocity = (SevenBitNumber)120, OffVelocity = (SevenBitNumber)70 }, new TimedEvent(new TextEvent("Te\"s\"\"t"), 0), new Note((SevenBitNumber)70, LengthConverter.ConvertFrom(new MetricTimeSpan(0, 0, 0, 500), 100, tempoMap), 100) { Channel = (FourBitNumber)7, Velocity = (SevenBitNumber)110, OffVelocity = (SevenBitNumber)80 } }; Assert.AreEqual(1, midiFile.GetTrackChunks().Count(), "Track chunks count is invalid."); MidiAsserts.AreEqual( expectedObjects, midiFile.GetObjects(ObjectType.TimedEvent | ObjectType.Note), false, 0, "Invalid objects."); }
public override PatternActionResult Invoke(long time, PatternContext context) { if (State == PatternActionState.Excluded) { return(PatternActionResult.DoNothing); } context.SaveTime(time); var noteLength = LengthConverter.ConvertFrom(NoteDescriptor.Length, time, context.TempoMap); if (State == PatternActionState.Disabled) { return(new PatternActionResult(time + noteLength)); } var note = new Note(NoteDescriptor.Note.NoteNumber, noteLength, time) { Channel = context.Channel, Velocity = NoteDescriptor.Velocity }; return(new PatternActionResult(time + noteLength, new[] { note })); }
private void CheckPlaybackStop( ICollection <EventToSend> eventsToSend, ICollection <EventToSend> eventsWillBeSent, TimeSpan stopAfter, TimeSpan stopPeriod, PlaybackAction setupPlayback, PlaybackAction afterStart, PlaybackAction afterStop, PlaybackAction afterResume, IEnumerable <Tuple <TimeSpan, PlaybackAction> > runningAfterResume = null, ICollection <TimeSpan> explicitExpectedTimes = null, double speed = 1.0) { var playbackContext = new PlaybackContext(); var receivedEvents = playbackContext.ReceivedEvents; var sentEvents = playbackContext.SentEvents; var stopwatch = playbackContext.Stopwatch; var tempoMap = playbackContext.TempoMap; var eventsForPlayback = new List <MidiEvent>(); var expectedTimes = playbackContext.ExpectedTimes; var currentTime = TimeSpan.Zero; foreach (var eventToSend in eventsToSend) { var midiEvent = eventToSend.Event.Clone(); midiEvent.DeltaTime = LengthConverter.ConvertFrom((MetricTimeSpan)eventToSend.Delay, (MetricTimeSpan)currentTime, tempoMap); currentTime += eventToSend.Delay; eventsForPlayback.Add(midiEvent); } if (explicitExpectedTimes != null) { expectedTimes.AddRange(explicitExpectedTimes); } else { currentTime = TimeSpan.Zero; foreach (var eventWillBeSent in eventsWillBeSent) { currentTime += eventWillBeSent.Delay; var scaledCurrentTime = ScaleTimeSpan(currentTime, 1.0 / speed); expectedTimes.Add(currentTime > stopAfter ? scaledCurrentTime + stopPeriod : scaledCurrentTime); } } using (var outputDevice = OutputDevice.GetByName(MidiDevicesNames.DeviceA)) { SendReceiveUtilities.WarmUpDevice(outputDevice); outputDevice.EventSent += (_, e) => sentEvents.Add(new SentEvent(e.Event, stopwatch.Elapsed)); using (var playback = new Playback(eventsForPlayback, tempoMap, outputDevice)) { playback.Speed = speed; setupPlayback(playbackContext, playback); using (var inputDevice = InputDevice.GetByName(MidiDevicesNames.DeviceA)) { inputDevice.EventReceived += (_, e) => { lock (playbackContext.ReceivedEventsLockObject) { receivedEvents.Add(new ReceivedEvent(e.Event, stopwatch.Elapsed)); } }; inputDevice.StartEventsListening(); stopwatch.Start(); playback.Start(); afterStart(playbackContext, playback); SpinWait.SpinUntil(() => stopwatch.Elapsed >= stopAfter); playback.Stop(); afterStop(playbackContext, playback); Thread.Sleep(stopPeriod); playback.Start(); afterResume(playbackContext, playback); if (runningAfterResume != null) { foreach (var check in runningAfterResume) { Thread.Sleep(check.Item1); check.Item2(playbackContext, playback); } } var timeout = expectedTimes.Last() + SendReceiveUtilities.MaximumEventSendReceiveDelay; var areEventsReceived = SpinWait.SpinUntil(() => receivedEvents.Count == expectedTimes.Count, timeout); Assert.IsTrue(areEventsReceived, $"Events are not received for timeout {timeout}."); stopwatch.Stop(); var playbackStopped = SpinWait.SpinUntil(() => !playback.IsRunning, SendReceiveUtilities.MaximumEventSendReceiveDelay); Assert.IsTrue(playbackStopped, "Playback is running after completed."); } } } CompareSentReceivedEvents(sentEvents, receivedEvents, expectedTimes); }
private void CheckPlayback( ICollection <EventToSend> eventsToSend, double speed, PlaybackAction beforePlaybackStarted, PlaybackAction startPlayback, PlaybackAction afterPlaybackStarted, PlaybackAction waiting, PlaybackAction finalChecks, CreateTickGeneratorCallback createTickGeneratorCallback = null) { var playbackContext = new PlaybackContext(); var receivedEvents = playbackContext.ReceivedEvents; var sentEvents = playbackContext.SentEvents; var stopwatch = playbackContext.Stopwatch; var tempoMap = playbackContext.TempoMap; var eventsForPlayback = new List <MidiEvent>(); var expectedTimes = playbackContext.ExpectedTimes; var currentTime = TimeSpan.Zero; foreach (var eventToSend in eventsToSend.Where(e => !(e.Event is MetaEvent))) { var midiEvent = eventToSend.Event.Clone(); midiEvent.DeltaTime = LengthConverter.ConvertFrom((MetricTimeSpan)eventToSend.Delay, (MetricTimeSpan)currentTime, tempoMap); currentTime += eventToSend.Delay; eventsForPlayback.Add(midiEvent); expectedTimes.Add(TimeSpan.FromTicks(MathUtilities.RoundToLong(currentTime.Ticks / speed))); } using (var outputDevice = OutputDevice.GetByName(SendReceiveUtilities.DeviceToTestOnName)) { SendReceiveUtilities.WarmUpDevice(outputDevice); outputDevice.EventSent += (_, e) => sentEvents.Add(new SentEvent(e.Event, stopwatch.Elapsed)); var clockSettings = createTickGeneratorCallback != null ? new MidiClockSettings { CreateTickGeneratorCallback = createTickGeneratorCallback } : null; using (var playback = new Playback(eventsForPlayback, tempoMap, outputDevice, clockSettings)) { playback.Speed = speed; beforePlaybackStarted(playbackContext, playback); using (var inputDevice = InputDevice.GetByName(SendReceiveUtilities.DeviceToTestOnName)) { inputDevice.EventReceived += (_, e) => { lock (playbackContext.ReceivedEventsLockObject) { receivedEvents.Add(new ReceivedEvent(e.Event, stopwatch.Elapsed)); } }; inputDevice.StartEventsListening(); stopwatch.Start(); startPlayback(playbackContext, playback); afterPlaybackStarted(playbackContext, playback); waiting(playbackContext, playback); stopwatch.Stop(); finalChecks(playbackContext, playback); } } } CompareSentReceivedEvents(sentEvents.Take(expectedTimes.Count).ToList(), receivedEvents.Take(expectedTimes.Count).ToList(), expectedTimes); }
private void createUI() { DataTemplate dt = new DataTemplate(); // FrameworkElementFactory expander = new FrameworkElementFactory(typeof(Expander)); FrameworkElementFactory stackPanel = new FrameworkElementFactory(typeof(StackPanel)); stackPanel.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal); FrameworkElementFactory label = new FrameworkElementFactory(typeof(Label)); label.SetValue(Label.ContentProperty, string.Format("{0} [{1}]", this.data.TagName, this.data.Childrens.Count)); if (this.data.Childrens.Count > 0) { FrameworkElementFactory button = new FrameworkElementFactory(typeof(Button)); button.SetValue(Button.ContentProperty, "+"); button.SetValue(Button.BackgroundProperty, Brushes.Transparent); button.SetValue(Button.BorderBrushProperty, Brushes.White); button.SetValue(Button.IsTabStopProperty, false); LengthConverter lc = new LengthConverter(); string qualifiedDouble = "24px"; var converted = lc.ConvertFrom(qualifiedDouble); button.SetValue(Button.WidthProperty, converted); button.SetValue(Button.HeightProperty, converted); button.SetValue(Button.BorderThicknessProperty, new Thickness(0)); button.AddHandler(Button.ClickEvent, new RoutedEventHandler(ExpanderClick)); button.AddHandler(Button.LoadedEvent, new RoutedEventHandler(LoaderBtn)); //Create a style Style st = new Style(); Trigger tg = new Trigger() { Property = Button.IsMouseOverProperty, Value = true // <Trigger Property="IsMouseOver" Value="true"> // <!--<Setter Property="Fill" TargetName="checkBoxFill" Value="{StaticResource OptionMark.MouseOver.Background}"/>--> // <Setter Property="Fill" TargetName="optionMark" Value="{StaticResource OptionMark.MouseOver.Glyph}"/> // <Setter Property="Fill" TargetName="indeterminateMark" Value="{StaticResource OptionMark.MouseOver.Glyph}"/> // </Trigger> //Binding = new Binding("CustomerId"), //Value = 1 }; tg.Setters.Add(new Setter() { Property = Button.BackgroundProperty, Value = Brushes.Red }); st.Triggers.Add(tg); //end style button.SetValue(Button.StyleProperty, st); // expander.SetValue(Expander.HeaderProperty, this.data.TagName); stackPanel.AppendChild(button); } stackPanel.AppendChild(label); this.HeaderTemplate = dt; dt.VisualTree = stackPanel; }
public static double ToPoints(string value) { double r = (double)LengthConverter.ConvertFrom("1pt"); return(ToPixels(value) * r); }
public TObject Create(ITimeSpan time, ITimeSpan length, TempoMap tempoMap) { var convertedTime = TimeConverter.ConvertFrom(time, tempoMap); return(Create(convertedTime, LengthConverter.ConvertFrom(length, convertedTime, tempoMap))); }
public void SetLength(TObject obj, ITimeSpan length, ITimeSpan time, TempoMap tempoMap) { var convertedTime = TimeConverter.ConvertFrom(time, tempoMap); SetLength(obj, LengthConverter.ConvertFrom(length, convertedTime, tempoMap)); }
/// <summary> /// Converts a size, like what can be specified in xaml, to the pixel size. /// </summary> /// <param name="srcLength">Desired length, with units. Format should be like "8pt" (no space), supported units are 'px', 'in', 'cm', and 'pt', no units assumes 'px'.</param> /// <returns></returns> public static double GetWpfLength(string srcLength) { // Could also use FontSizeConverter, which converts return((double)LengthConverter.ConvertFrom(null, CultureInfo.InvariantCulture, srcLength)); }
public static IEnumerable <Note> ConvertToNotes(Stream stream, TempoMap tempoMap, NoteCsvConversionSettings settings) { using (var csvReader = new CsvReader(stream, settings.CsvDelimiter)) { CsvRecord record = null; while ((record = csvReader.ReadRecord()) != null) { var values = record.Values; if (values.Length < 6) { CsvError.ThrowBadFormat(record.LineNumber, "Missing required parameters."); } ITimeSpan time; if (!TimeSpanUtilities.TryParse(values[0], settings.TimeType, out time)) { CsvError.ThrowBadFormat(record.LineNumber, "Invalid time."); } FourBitNumber channel; if (!FourBitNumber.TryParse(values[1], out channel)) { CsvError.ThrowBadFormat(record.LineNumber, "Invalid channel."); } SevenBitNumber noteNumber; if (!TryParseNoteNumber(values[2], settings.NoteNumberFormat, out noteNumber)) { CsvError.ThrowBadFormat(record.LineNumber, "Invalid note number or letter."); } ITimeSpan length; if (!TimeSpanUtilities.TryParse(values[3], settings.NoteLengthType, out length)) { CsvError.ThrowBadFormat(record.LineNumber, "Invalid length."); } SevenBitNumber velocity; if (!SevenBitNumber.TryParse(values[4], out velocity)) { CsvError.ThrowBadFormat(record.LineNumber, "Invalid velocity."); } SevenBitNumber offVelocity; if (!SevenBitNumber.TryParse(values[5], out offVelocity)) { CsvError.ThrowBadFormat(record.LineNumber, "Invalid off velocity."); } var convertedTime = TimeConverter.ConvertFrom(time, tempoMap); var convertedLength = LengthConverter.ConvertFrom(length, convertedTime, tempoMap); yield return(new Note(noteNumber, convertedLength, convertedTime) { Channel = channel, Velocity = velocity, OffVelocity = offVelocity }); } } }
public override PatternActionResult Invoke(long time, PatternContext context) { context.SaveTime(time); return(new PatternActionResult(time + LengthConverter.ConvertFrom(Step, time, context.TempoMap))); }
public void ConvertFromInvalidSource() { new Action(() => _converter.ConvertFrom(null)).ShouldThrow <NotSupportedException>().WithMessage("*null*"); new Action(() => _converter.ConvertFrom(new object())).ShouldThrow <NotSupportedException>().WithMessage($"*{typeof(object)}*"); }