<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import wave, struct, random, math
import os

class MelopyGenericError(Exception): pass
class MelopyValueError(ValueError): pass

def frequency_from_key(key):
	return 440 * 2 ** ((key - 49) / 12.0)

def frequency_from_note(note):
	return frequency_from_key(key_from_note(note))

def key_from_note(note):
	indices = { 'C':0, 'D':2, 'E':4, 'F':5, 'G':7, 'A':9, 'B':11 }

	octave = 4

	if note[-1] in '012345678':
		octave = int(note[-1])

	tone = indices[note[0].upper()]
	key = 12 * octave + tone

	if len(note) > 1 and note[1] == '#':
		key += 1
	elif len(note) > 1 and note[1] == 'b':
		key -= 1

	return key - 8;

def note_from_key(key):
	notes = ['a','a#','b','c','c#','d','d#','e','f','f#','g','g#']
	octave = (key+8) / 12
	note = notes[(key-1) % 12]

	return note.upper() + str(octave)
	
def iterate(start, pattern):
	start_key = key_from_note(start)
	ret = [start_key]
	for step in pattern:
		ret.append(ret[-1] + step)
		
	ret = map(note_from_key, ret)
	return ret
	
def generate_major_scale(start):
	major_steps = [2,2,1,2,2,2]
	return iterate(start, major_steps)
	
def generate_minor_scale(start):
	minor_steps = [2,1,2,2,1,2]
	return iterate(start, minor_steps)
	
def generate_chromatic_scale(start):
	chromatic_steps = [1,1,1,1,1,1,1,1,1,1,1]
	return iterate(start, chromatic_steps)
	
def generate_major_pentatonic_scale(start):
	major_pentatonic_steps = [2,2,3,2]
	return iterate(start, major_pentatonic_steps)
	
def generate_minor_pentatonic_scale(start):
	minor_pentatonic_steps = [3,2,2,3]
	return iterate(start, minor_pentatonic_steps)

def generate_major_triad(start):
	major_triad = [4, 3]
	return iterate(start, major_triad)
	
def generate_minor_triad(start):
	minor_triad = [3, 4]
	return iterate(start, minor_triad)

class Melopy:
	def __init__(self, title='sound', volume=50, tempo=120, octave=4):
		if not title:
			raise MelopyValueError('Title must be non-null.')
			
		self.title = title.lower()
		self.rate = 44100<commit_msg>Added doc strings to all the functions in melopy.py<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import wave, struct, random, math
import os

class MelopyGenericError(Exception): pass
class MelopyValueError(ValueError): pass

def frequency_from_key(key):
	"""Returns the frequency of the note (key) keys from A0"""
	return 440 * 2 ** ((key - 49) / 12.0)

def frequency_from_note(note):
	"""Returns the frequency of a note represented by a string"""
	return frequency_from_key(key_from_note(note))

def key_from_note(note):
	"""Returns the key number (keys from A0) from a note represented by a string"""
	indices = { 'C':0, 'D':2, 'E':4, 'F':5, 'G':7, 'A':9, 'B':11 }

	octave = 4

	if note[-1] in '012345678':
		octave = int(note[-1])

	tone = indices[note[0].upper()]
	key = 12 * octave + tone

	if len(note) > 1 and note[1] == '#':
		key += 1
	elif len(note) > 1 and note[1] == 'b':
		key -= 1

	return key - 8;

def note_from_key(key):
	"""Returns a string representing a note which is (key) keys from A0"""
	notes = ['a','a#','b','c','c#','d','d#','e','f','f#','g','g#']
	octave = (key+8) / 12
	note = notes[(key-1) % 12]

	return note.upper() + str(octave)
	
def iterate(start, pattern):
	"""Iterates over a pattern starting at a given note"""
	start_key = key_from_note(start)
	ret = [start_key]
	for step in pattern:
		ret.append(ret[-1] + step)
		
	ret = map(note_from_key, ret)
	return ret
	
def generate_major_scale(start):
	"""Generates a major scale using the pattern [2,2,1,2,2,2] (Returns: List)"""
	major_steps = [2,2,1,2,2,2]
	return iterate(start, major_steps)
	
def generate_minor_scale(start):
	"""Generates a minor scale using the pattern [2,1,2,2,1,2] (Returns: List)"""
	minor_steps = [2,1,2,2,1,2]
	return iterate(start, minor_steps)
	
def generate_chromatic_scale(start):
	"""Generates a chromatic scale using the pattern [1,1,1,1,1,1,1,1,1,1,1] (Returns: List)"""
	chromatic_steps = [1,1,1,1,1,1,1,1,1,1,1]
	return iterate(start, chromatic_steps)
	
def generate_major_pentatonic_scale(start):
	"""Generates a major pentatonic scale using the pattern [2,2,3,2] (Returns: List)"""
	major_pentatonic_steps = [2,2,3,2]
	return iterate(start, major_pentatonic_steps)
	
def generate_minor_pentatonic_scale(start):
	"""Generates a minor pentatonic scale using the pattern [3,2,2,3] (Returns: List)"""
	minor_pentatonic_steps = [3,2,2,3]
	return iterate(start, minor_pentatonic_steps)

def generate_major_triad(start):
	"""Generates a major triad using the pattern [4,3] (Returns: List)"""
	major_triad = [4, 3]
	return iterate(start, major_triad)
	
def generate_minor_triad(start):
	"""Generates a minor triad using the pattern [3,4] (Returns: List)"""
	minor_triad = [3, 4]
	return iterate(start, minor_triad)

class Melopy:
	def __init__(self, title='sound', volume=50, tempo=120, octave=4):
		if not title:
			raise MelopyValueError('Title must be non-null.')
			
		self.title = title.lower()
		self.rate = 44100
{'fraction_non_alphanumeric': 0.16361071932299012, 'fraction_numerical': 0.045133991537376586, 'mean_word_length': 5.181818181818182, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '572366', 'n_tokens_mistral': 2070, 'n_tokens_neox': 1909, 'n_words': 480}