Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "music21j",
"version": "0.17.13",
"version": "0.17.14",
"description": "A toolkit for computer-aided musicology, Javascript version",
"main": "releases/music21.debug.js",
"typings": "releases/src/main.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* does not load the other modules.
*
* Copyright (c) 2013-24, Michael Scott Asato Cuthbert
* Copyright (c) 2013-24, Michael Scott Asato Cuthbert, BSD License
* Based on music21 (=music21p), Copyright (c) 2006-24, Michael Scott Asato Cuthbert
*
* module for Music21Objects
Expand Down
5 changes: 3 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import * as interval from './interval';
import * as key from './key';
import * as keyboard from './keyboard';
import * as layout from './layout';
import * as metadata from './metadata';
import * as meter from './meter';
import * as miditools from './miditools';
import * as musicxml from './musicxml';
Expand All @@ -85,6 +86,7 @@ import * as webmidi from './webmidi';

import { debug } from './debug';

export const VERSION = '0.17.14';

export {
MIDI,
Expand Down Expand Up @@ -120,6 +122,7 @@ export {
key,
keyboard,
layout,
metadata,
meter,
miditools,
musicxml,
Expand All @@ -142,6 +145,4 @@ export {
webmidi,
};

export const VERSION = '0.17.12';

parseLoader.runConfiguration();
28 changes: 28 additions & 0 deletions src/metadata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* music21j -- Javascript reimplementation of Core music21p features.
* music21/metadata -- Very basic metadata object
*
* Copyright (c) 2013-25, Michael Scott Asato Cuthbert, BSD License
* Based on music21 (=music21p), Copyright (c) 2006-25, Michael Scott Asato Cuthbert
*/

import { Music21Object } from './base';

export class Metadata extends Music21Object {
title: string|undefined = undefined;
composer: string|undefined = undefined;

constructor(vars: any = {}) {
super(vars);
if ('title' in vars) {
this.title = vars.title;
}
if ('composer' in vars) {
this.composer = vars.composer;
}
}

static get className() { return 'music21.metadata.Metadata'; }
}

export default Metadata;
19 changes: 19 additions & 0 deletions src/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import * as common from './common';
import * as derivation from './derivation';
import { Duration } from './duration';
import * as instrument from './instrument';
import * as metadata from './metadata';
import * as meter from './meter';
import * as note from './note';
import * as pitch from './pitch';
Expand Down Expand Up @@ -557,6 +558,24 @@ export class Stream<ElementType extends base.Music21Object = base.Music21Object>
}
}

get metadata(): metadata.Metadata {
let out_metadata = this._firstElementContext('metadata') as metadata.Metadata;
if (out_metadata === undefined) {
out_metadata = new metadata.Metadata();
this.insert(0.0, out_metadata);
}
return out_metadata;
}

set metadata(newMetadata: metadata.Metadata) {
const oldMetadata = this._firstElementContext('metadata') as metadata.Metadata;
if (oldMetadata !== undefined) {
this.replace(oldMetadata, newMetadata);
} else {
this.insert(0.0, newMetadata);
}
}

get clef(): clef.Clef {
return this.getSpecialContext('clef', false) as clef.Clef;
}
Expand Down
2 changes: 2 additions & 0 deletions tests/loadAll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import figuredBass from './moduleTests/figuredBass';
import interval from './moduleTests/interval';
import iterator from './moduleTests/stream/iterator';
import key from './moduleTests/key';
import metadata from './moduleTests/metadata';
import meter from './moduleTests/meter';
import note from './moduleTests/note';
import pitch from './moduleTests/pitch';
Expand Down Expand Up @@ -43,6 +44,7 @@ const allTests = {
interval,
iterator,
key,
metadata,
meter,
note,
pitch,
Expand Down
28 changes: 28 additions & 0 deletions tests/moduleTests/metadata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import * as QUnit from 'qunit';
import * as music21 from '../../src/main';

const { test } = QUnit;


export default function tests() {
test('music21.metadata.Metadata', assert => {
const m = new music21.metadata.Metadata({title: 'Aloha Oe', composer: 'Liliuokalani'});
assert.equal(m.title, 'Aloha Oe');
assert.equal(m.composer, 'Liliuokalani');
});

test('music21.metadata.Metadata in Streams', assert => {
const s = new music21.stream.Score();
s.insert(0.0, new music21.note.Note('C4'));
s.metadata.title = 'Aloha Oe';
assert.equal(s.metadata.title, 'Aloha Oe');
const old_md = s.metadata;

const md2 = new music21.metadata.Metadata({title: 'Pink Pony Club'});
s.metadata = md2;
assert.equal(s.metadata.title, 'Pink Pony Club');
assert.equal(old_md.title, 'Aloha Oe');
assert.ok(Array.from(s).includes(md2));
assert.notOk(Array.from(s).includes(old_md));
});
}