Skip to main content

A small package designed to create simple melodies

Project description

PyLody

PyLody is a small package designed to create simple melodies.

Usage

To create a melody you can use two methods: you can use notescript notation or add melody elements manually.

The notescript notation

The notescript notation is a little-function programming language that allows you to write a melody using the melody elements: the letter notation of notes, pauses and repeating blocks.


The letter notation of notes and pauses must contains the duration at end of the declaration: [Note or pause] [Duration (in milliseconds)] The letter notation of notes must match this regex: \w\d#? [duration] (the duration regex is \d+). The pause declaration is - [duration].


The repeating block is a part of melody that can repeat any number of times. This is the structure of this block:

[Number of times to repeat] {
	...elements to repeat...
}

To create an infinite repeating loop just write an asterisk (*) as the number of times to repeat.


The notescript notation supports commentaries: /The text in the slashes will be ignored/.

Creating a melody

First of all, create a MelodyBuilder object. The constructor of this class takes one optional argument —— a notescript. To play the melody call the play method.

from pylody import MelodyBuilder

mb = MelodyBuilder(notescript)
mb.play()

You can create a melody without the notescript. Just add elements manually:

from pylody.elements import Pause, Note, Block

# The note declaration
mb.add(Note(note="A",
			octave=4,
			duration=250)) # A4 250

# The pause declaration
mb.add(Pause(duration=250)) # - 250

# The block declaration
block = Block(repeattimes=1)
...
block.add(element)
...
mb.add(block)

Or you can play elements separately:

note.play()
pause.play()
block.play()

Example

from pylody import MelodyBuilder

mb = MelodyBuilder(r"""
	\ Example \
	* {
		2 {
			A4 250
			B4 250
		}
		3 {
			A4# 250
		}
		- 500
	}
""")
mb.play()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PyLody-1.0.0.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

PyLody-1.0.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file PyLody-1.0.0.tar.gz.

File metadata

  • Download URL: PyLody-1.0.0.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.6

File hashes

Hashes for PyLody-1.0.0.tar.gz
Algorithm Hash digest
SHA256 a070ccf20ede9e7189b4fc0d71b869763ec92a88b199cbed3695f0da79c451ea
MD5 13a45c520c0f8ba362698b2b52732922
BLAKE2b-256 0e8521bcb2bd6646004ddd42154c3a08550e5e7364dd0dc2b3b087b808e8d998

See more details on using hashes here.

File details

Details for the file PyLody-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: PyLody-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.6

File hashes

Hashes for PyLody-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0c4896b6e4a54bb6c49d54caa4dfdd449057b2f8c3fecc477432dc7e90a2f139
MD5 bf6d3fd8c95a0fe22b080aee7569b200
BLAKE2b-256 c281d6e8383070f32038f8b097c8edce52a6e55b506634c0e55c325be065c84b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page