exsurgat 0.2.2 copy "exsurgat: ^0.2.2" to clipboard
exsurgat: ^0.2.2 copied to clipboard

Flutter package for rendering Gregorian chant scores from GABC notation. Provides display widgets, SVG and PNG export, layout and style customization.

example/lib/main.dart

import 'dart:convert';

import 'package:exsurgat/exsurgat.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'GABC code editor',
      theme: ThemeData(colorScheme: .fromSeed(seedColor: Colors.deepPurple)),
      home: const EditorPage(title: 'GABC code editor'),
      debugShowCheckedModeBanner: false,
    );
  }
}

class EditorPage extends StatefulWidget {
  const EditorPage({super.key, required this.title});
  final String title;

  @override
  State<EditorPage> createState() => _EditorPageState();
}

class _EditorPageState extends State<EditorPage> {
  final _gabcCtrl = TextEditingController(text: '(c3) ');

  bool dropCap = true;
  bool fancy = false;

  final fancyTheme = ChantTheme(
    textColor: Colors.brown,
    rubricColor: ChantColors.rubric,
    neumeColor: Colors.indigo,
    staffLineColor: ChantColors.nigric,
    dividerLineColor: Colors.blueGrey,
    baseTextStyle: BaseTextStyle(
      font: GoogleFonts.imFellDwPica().fontFamily!,
      size: Scalar(16),
    ),
    supertitle: TextStyleDefinition(size: FontSize.relative(7 / 6)),
    title: TextStyleDefinition(size: FontSize.relative(3 / 2)),
    subtitle: const TextStyleDefinition(),
    leftRight: TextStyleDefinition(size: FontSize.relative(0.9)),
    annotation: TextStyleDefinition(size: FontSize.relative(2 / 3)),
    dropCap: TextStyleDefinition(
      font: GoogleFonts.uncialAntiqua().fontFamily,
      size: FontSize.relative(4),
      color: Colors.deepOrange,
    ),
    aboveLine: const TextStyleDefinition(),
    choralSign: TextStyleDefinition(size: FontSize.staffInterval(1.5)),
    lyric: TextStyleDefinition(size: FontSize.relative(0.9)),
    translation: TextStyleDefinition(size: FontSize.relative(0.75)),
  );
  final normalTheme = ChantTheme(
    baseTextStyle: BaseTextStyle(
      font: GoogleFonts.crimsonPro().fontFamily!,
      size: Scalar(16),
    ),
  );
  @override
  Widget build(BuildContext context) {
    final chantTheme = fancy ? fancyTheme : normalTheme;
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
        actions: [
          IconButton(
            onPressed: saveSvg,
            icon: Icon(Icons.save),
            tooltip: 'Save as SVG',
          ),
        ],
      ),
      body: Column(
        children: [
          TextField(
            style: TextStyle(fontFamily: 'Consolas'),
            autofocus: true,
            minLines: 1,
            maxLines: 10,
            controller: _gabcCtrl,
          ),
          Row(
            children: [
              Switch.adaptive(
                value: dropCap,
                onChanged: (v) => setState(() => dropCap = v),
              ),
              Text('Drop Cap'),
              VerticalDivider(),
              Switch.adaptive(
                value: fancy,
                onChanged: (v) => setState(() => fancy = v),
              ),
              Text('Fancy Theme'),
            ],
          ),
          Expanded(
            child: Container(
              margin: const EdgeInsets.all(8.0),
              color: Colors.amber.withAlpha(40),
              child: ListenableBuilder(
                listenable: _gabcCtrl,
                builder: (_, _) => ChantScoreView(
                  gabc: _gabcCtrl.text,
                  useDropCap: dropCap,
                  theme: chantTheme,
                ),
              ),
            ),
          ),
        ],
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: loadSampleScore,
        tooltip: 'Load Sample Score',
        child: const Icon(Icons.abc_sharp),
      ),
    );
  }

  Future<void> saveSvg() async {
    final renderingContext = ChantContext(
      textMeasuringStrategy: .svg,
      stylingMode: .attributes,
      theme: fancy ? fancyTheme : ChantTheme.kDefaultTheme,
    );
    final score =
        ChantScore(
            ctxt: renderingContext,
            words: Gabc.fromSource(renderingContext, _gabcCtrl.text),
            header: GabcHeader.fromSource(_gabcCtrl.text),
            useDropCap: true,
          )
          ..performLayout(renderingContext)
          ..layoutChantLines(renderingContext, 800);
    final xml = score.createSvgNode(renderingContext).toXmlString();
    await FilePicker.saveFile(
      allowedExtensions: ['.svg'],
      dialogTitle: 'Save chant to SVG',
      fileName: 'chant.svg',
      bytes: Utf8Codec().encode(xml),
    );
  }

  Future<void> loadSampleScore() async {
    _gabcCtrl.text = '''
annotation: Ant
mode: 7 a
title: Exsurgat Deus
text-right: <b>Ps 68 (67)</b>
%%
(c3)Ex(e)súr(g)gat(h) De(ihji)us,(i) *(,) et(i) dis(j)si(i)pén(hg)tur(ef) in(g)i(h)mí(f)ci(f) e(e)ius.(e) (::)
E(i) u(i) o(j) u(i) a(h) e.(gf) (::)
''';
  }
}
1
likes
160
points
433
downloads

Documentation

API reference

Publisher

verified publisherorb.net.pl

Weekly Downloads

Flutter package for rendering Gregorian chant scores from GABC notation. Provides display widgets, SVG and PNG export, layout and style customization.

Repository (GitHub)
View/report issues

Topics

#gabc #gregorian-chant #music #engraving #rendering

Funding

Consider supporting this project:

buymeacoffee.com
pay.e.cash

License

MIT (license)

Dependencies

flutter, xml

More

Packages that depend on exsurgat