using System; using System.Data; using System.Globalization; using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Media; using System.Windows.Media.Imaging; using Chernobyl.App.Core; using Chernobyl.Extensions; using Chernobyl.Generation; using Chernobyl.Mathematics; using LiveCharts; using LiveCharts.Wpf; namespace Chernobyl.App.Patterns { // TODO: look into using a graph to display pattern structure: // https://stackoverflow.com/questions/16479768/how-to-easily-draw-graphs-in-wpf // Looks Good: // http://graphviz4net.codeplex.com/ (https://github.com/tomap/Graphviz4Net) /// /// Represents the view of an . /// public class PatternViewModel : ViewModel { /// The to be displayed. public PatternViewModel(IPattern pattern) { Pattern = pattern; var patternData = Pattern.Data.ToArray(); DataSeries = new SeriesCollection { new LineSeries { Title = "Pattern", Values = new ChartValues(patternData) } }; var grandienStops = patternData .Select(value => (byte)value.Normalize(Range.Unit, Tuple.Create(0.0, 255.0))) .Select((value, index) => new GradientStop(Color.FromRgb(0, 0, value), index / (double)patternData.Length)); GradientStops = new GradientStopCollection(grandienStops); var width = 8; // TODO: Create tests to target for features. Each test will test for ever more advanced features. // They will fail at first until we fulfill the feature. Use tests as feature plan. var rowCreator = Func.StaticFactory(Colors.Black) .AddBeat(3, () => Colors.Red) .AddRepeater(width); var columnCreator = rowCreator.AddRepeater(3); var tablePattern = columnCreator(); Instruments = new DataTable(); for (int i = 0; i < width; i++) { Instruments.Columns.Add($"Beat {i}"); } foreach (var row in tablePattern) { Instruments.Rows.Add(row.Cast().ToArray()); } } /// /// The to be displayed. /// public IPattern Pattern { get; } /// /// The series containing the values from the pattern. /// public SeriesCollection DataSeries { get; } /// /// The colors and their location in the gradient. /// public GradientStopCollection GradientStops { get; } /// /// Beat information for each pattern. /// public DataTable Instruments { get; } } /// /// Converts a data cell value to a hex color string. /// public class ValueToBrushConverter : IValueConverter { /// public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { try { var dgc = (DataGridCell)value; var row = (DataRowView)dgc.DataContext; return row[dgc.Column.DisplayIndex].ToString(); } catch (Exception) { return DependencyProperty.UnsetValue; } } /// public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotSupportedException(); } } }