<commit_before>package thriveTones;

/**
 * "ThriveTones" Song Generator
 * Copyright © 2014 <NAME>
 * <EMAIL>
 *
 * Song.java
 * This class represents a song part, containing metadata, key, mode, and a chord progression
 */

import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Scanner;

import org.jfugue.Pattern;
import org.jfugue.Player;

public class Song {
	private String name;
	private String artist;
	private String part;
	private String key;
	private String rel_major;
	private int mode;
	private LinkedList<Chord> progression;
	private double beats;
	private ChordDictionary dictionary;

	/**
	 * Constructor method
	 * @param nm: song name
	 * @param at: song artist
	 * @param pt: song part (chorus, verse, etc)
	 * @param ky: song key
	 * @param md: song mode (major, minor, dorian, etc)
	 * @param sif: chords in SIF format
	 * @param bim: beats in measure
	 * @param dict: Chord dictionary
	 * @throws IllegalArgumentException: throws if an invalid parameter is supplied
	 */
	public Song(String nm, String at, String pt, String ky, int md, String sif,
			double bim, ChordDictionary dict) throws Exception{

		if(nm.isEmpty() || nm.equals(""))
			throw new IllegalArgumentException("Invalid name value: " + nm);
		if(at.isEmpty() || at.equals(""))
			throw new IllegalArgumentException("Invalid artist value: " + at);
		if(pt.isEmpty() || pt.equals(""))
			throw new IllegalArgumentException("Invalid part value: " + pt);
		if(md < 0 || md > 7)
			throw new IllegalArgumentException("Invalid mode value: " + md);
		if(sif.isEmpty() || sif.equals(""))
			throw new IllegalArgumentException("Invalid SIF value: " + sif);
		if(bim < 0.25 || bim > 20)
			throw new IllegalArgumentException("Invalid BiM value: " + bim);
		
		name = nm;
		artist = at;
		part = pt;
		if(ky.isEmpty()) key = "C";
		else key = ky;
		mode = md;
		beats = bim;
		dictionary = dict;
		
		progression = new LinkedList<Chord>();
		
		String[] sif_chords = sif.split(",");
		LinkedList<Chord> sequence = new LinkedList<Chord>();
		for(String sif_chord : sif_chords){
			if(sif_chord.isEmpty()) continue;

			Chord current = new Chord(mode, sif_chord);
			progression.add(current);

			//add to dictionary
			if(sequence.size() > 3)
				sequence.remove();
			sequence.add(current);
			dictionary.put(sequence, current);
		}

		calculateRelativeMajor();
	}
	
	public Song(String pt, String ky, int md, double bim, LinkedList<Chord> pg){
		name = "AI Creation";
		artist = "Music Bot";
		part = pt;
		key = ky;
		mode = md;
		beats = bim;
		progression = pg;
		dictionary = null;

		calculateRelativeMajor();
	}

	/**
	 * Adjusts the song's key
	 * @param ky: new key
	 * @param md: new mode
	 */
	public void changeKey(String ky, int md) throws Exception{<commit_msg>Fixed dictionary build bug in Song.java<commit_after>package thriveTones;

/**
 * "ThriveTones" Song Generator
 * Copyright © 2014 <NAME>
 * <EMAIL>
 *
 * Song.java
 * This class represents a song part, containing metadata, key, mode, and a chord progression
 */

import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Scanner;

import org.jfugue.Pattern;
import org.jfugue.Player;

public class Song {
	private String name;
	private String artist;
	private String part;
	private String key;
	private String rel_major;
	private int mode;
	private LinkedList<Chord> progression;
	private double beats;
	private ChordDictionary dictionary;
	private static final int MAX_HISTORY_LENGTH = 3;

	/**
	 * Constructor method
	 * @param nm: song name
	 * @param at: song artist
	 * @param pt: song part (chorus, verse, etc)
	 * @param ky: song key
	 * @param md: song mode (major, minor, dorian, etc)
	 * @param sif: chords in SIF format
	 * @param bim: beats in measure
	 * @param dict: Chord dictionary
	 * @throws IllegalArgumentException: throws if an invalid parameter is supplied
	 */
	public Song(String nm, String at, String pt, String ky, int md, String sif,
			double bim, ChordDictionary dict) throws Exception{

		if(nm.isEmpty() || nm.equals(""))
			throw new IllegalArgumentException("Invalid name value: " + nm);
		if(at.isEmpty() || at.equals(""))
			throw new IllegalArgumentException("Invalid artist value: " + at);
		if(pt.isEmpty() || pt.equals(""))
			throw new IllegalArgumentException("Invalid part value: " + pt);
		if(md < 0 || md > 7)
			throw new IllegalArgumentException("Invalid mode value: " + md);
		if(sif.isEmpty() || sif.equals(""))
			throw new IllegalArgumentException("Invalid SIF value: " + sif);
		if(bim < 0.25 || bim > 20)
			throw new IllegalArgumentException("Invalid BiM value: " + bim);
		
		name = nm;
		artist = at;
		part = pt;
		if(ky.isEmpty()) key = "C";
		else key = ky;
		mode = md;
		beats = bim;
		dictionary = dict;
		
		progression = new LinkedList<Chord>();
		
		String[] sif_chords = sif.split(",");
		LinkedList<Chord> sequence = new LinkedList<Chord>();
		for(String sif_chord : sif_chords){
			if(sif_chord.isEmpty()) continue;

			Chord current = new Chord(mode, sif_chord);
			progression.add(current);

			//add to dictionary
			if(sequence.size() > MAX_HISTORY_LENGTH)
				sequence.remove();
			dictionary.put(sequence, current);
			sequence.add(current);
		}

		calculateRelativeMajor();
	}
	
	public Song(String pt, String ky, int md, double bim, LinkedList<Chord> pg){
		name = "AI Creation";
		artist = "Music Bot";
		part = pt;
		key = ky;
		mode = md;
		beats = bim;
		progression = pg;
		dictionary = null;

		calculateRelativeMajor();
	}

	/**
	 * Adjusts the song's key
	 * @param ky: new key
	 * @param md: new mode
	 */
	public void changeKey(String ky, int md) throws Exception{
{'fraction_non_alphanumeric': 0.12488928255093003, 'fraction_numerical': 0.004251550044286979, 'mean_word_length': 3.846351931330472, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, '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': '6406264', 'n_tokens_mistral': 2042, 'n_tokens_neox': 1767, 'n_words': 586}