/
Pendulf
/
NotRedSound
Обзор
Документация
Войти
/
Pendulf
/
NotRedSound
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
lib/presentation/common/widgets/pattern_painter.dart
74 строки
2 KB
Dominatorr
NotRedSound version 1.0.0
14 май 2026, 02:14
14 май 2026, 02:14
301f13d
Код
Авторство
О чём код?
import 'package:flutter/material.dart'; import '../../../domain/entities/track_model.dart'; class PatternPainter extends CustomPainter { final List<MidiNote> notes; final Color color; final double barWidth; final double previewHeight; final int minNote; final int maxNote; final int ticksPerBar; PatternPainter({ required this.notes, required this.color, required this.barWidth, required this.previewHeight, required this.minNote, required this.maxNote, required this.ticksPerBar, }); @override void paint(Canvas canvas, Size size) { if (notes.isEmpty) return; final paint = Paint() ..color = color.withValues(alpha: 0.75) ..style = PaintingStyle.fill; for (final note in notes) { final normalizedY = _normalizeNotePosition(note.pitch); final relativePosition = note.startTick / ticksPerBar; final noteX = relativePosition * barWidth; final noteWidth = ((note.durationTicks / ticksPerBar) * barWidth).clamp(2.0, barWidth); final noteHeight = (previewHeight / (maxNote - minNote + 1) * 0.8).clamp(2.0, 10.0); canvas.drawRRect( RRect.fromRectAndRadius( Rect.fromLTWH( noteX, normalizedY - noteHeight / 2, noteWidth, noteHeight, ), const Radius.circular(2), ), paint, ); } } double _normalizeNotePosition(int pitch) { final range = maxNote - minNote; if (range <= 0) return previewHeight / 2; final position = (maxNote - pitch) / range; return position * previewHeight; } @override bool shouldRepaint(covariant PatternPainter oldDelegate) { return oldDelegate.notes != notes || oldDelegate.color != color || oldDelegate.minNote != minNote || oldDelegate.maxNote != maxNote || oldDelegate.ticksPerBar != ticksPerBar || oldDelegate.barWidth != barWidth; } }