music_xml 1.2.2 copy "music_xml: ^1.2.2" to clipboard
music_xml: ^1.2.2 copied to clipboard

A Dart package project to parse MusicXML. Inspired from Google's magenta.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:music_xml/music_xml.dart';
import 'package:xml/xml.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  const MyHomePage([Key? key]) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // This method is rerun every time setState is called, for instance as done
    // by the _incrementCounter method above.
    //
    // The Flutter framework has been optimized to make rerunning build methods
    // fast, so that you can just rebuild anything that needs updating rather
    // than having to individually change instances of widgets.
    return Scaffold(
      appBar: AppBar(
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: const Text('Flutter Demo Home Page'),
      ),
      body: FutureBuilder<MusicXmlDocument>(
        future: rootBundle
            .loadString('assets/musicXML.xml')
            .then((value) => MusicXmlDocument.parse(value)),
        builder: (context, snapshot) {
          if (snapshot.hasData) {
            final document = snapshot.data!;
            final score = document.score;
            final scorePartwise = score.getElement('score-partwise');
            final movementTitle = scorePartwise?.getElement('movement-title');
            return Padding(
              padding: const EdgeInsets.all(16.0),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text('movement-title: ${movementTitle?.innerText}'),
                  const SizedBox(height: 16),
                  Text('totalTimeSecs: ${document.totalTimeSecs}'),
                ],
              ),
            );
          }
          return const Center(child: CircularProgressIndicator());
        },
      ),
    );
  }
}
13
likes
140
pub points
64%
popularity

Publisher

verified publisherdemen.org

A Dart package project to parse MusicXML. Inspired from Google's magenta.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

xml

More

Packages that depend on music_xml