<commit_before>/***
    Copyright 2017 by <NAME>
    Licensed under the Apache License version 2.0
*/

package edisyn;

import java.util.*;
import java.io.*;
import edisyn.gui.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;

/***

Procedure:

Menu -> Start Hill-Climb [or Menu -> Reset Hill-Climb if already started]
	Creates Hill-Climb Panel and Resets it to current patch
Menu -> Stop Hill-Climb
	Deletes Hill-Climb Panel

Each sound has:
1. Done (or Keep?) -> Deletes Hill-Climb Panel and sets current patch to this sound [probably requires double-check dialog panel]
2. Try -> Sends sound to current patch
3. Best / Second Best / Third Best

The Panel also has:
1. Iterate
2. Rate
3. Backup

***/


public class HillClimb extends SynthPanel
	{
	public static final int NUM_MODELS = 16;

	ArrayList oldA = new ArrayList();
	ArrayList oldB = new ArrayList();
	ArrayList oldC = new ArrayList();
	Model[] currentModels = new Model[NUM_MODELS];
	Model[] bestModels = new Model[3];
	JRadioButton[][] ratings = new JRadioButton[16][3];
	PushButton[] plays = new PushButton[16];
	public static final int INITIAL_MUTATION_RATE = 20;
	public static final int INITIAL_RECOMBINATION_RATE = 75;
	JSlider mutationRate = new JSlider(JSlider.HORIZONTAL, 0, 100, INITIAL_MUTATION_RATE);
	JSlider recombinationRate = new JSlider(JSlider.HORIZONTAL, 0, 100, INITIAL_RECOMBINATION_RATE);
	Category iterations;
	
	Synth synth;
	int currentPlay = 0;
	
	public HillClimb(Synth synth)
		{
		this.synth = synth;
	
		VBox top = new VBox();
		add(top, BorderLayout.CENTER);

		// add globals

		Category panel = new Category(null, "Iteration 1", Style.COLOR_A);
		iterations = panel;
		
		PushButton backup = new PushButton("Backup")
            {
            public void perform()
            	{
				pop();
            	resetCurrentPlay();
                }
            };
            
		PushButton climb = new PushButton("Climb")
            {
            public void perform()
            	{
            	climb(true);
            	resetCurrentPlay();
                }
            };
        climb.getButton().setPreferredSize(backup.getButton().getPreferredSize());
		
		PushButton reset = new PushButton("Reset")
            {
            public void perform()
            	{
				initialize((Model)(synth.getModel().clone()), true);
            	resetCurrentPlay();
                }
            };
        reset.getButton().setPreferredSize(backup.getButton().getPreferredSize());
		
		PushButton retry = new PushButton("Retry")
            {
            public void perform()
            	{
				again();
            	resetCurrentPlay();
                }
            };
        retry.getButton().setPreferredSize(backup.getButton().getPreferredSize());
		
		VBox vbox = new VBox();
		
		JLabel recombinationRateLabel = new JLabel("Recombination Rate", SwingConstants.RIGHT);
        recombinationRateLabel.setFont(Style.SMALL_FONT);
		recombinationRateLabel.setForeground(Style.TEXT_COLOR);
		recombinationRateLabel.setOpaque(false);
		JLabel recombinationRateVal = new JLabel("" + INITIAL_RECOMBINATION_RATE + "%");
        recombinationRateVal.setFont(Style.SMALL_FONT);
		recombinationRateVal.setForeground(Style.TEXT_COLOR);
		recombinationRateVal.setOpaque(false);
		recombinationRate.setOpaque(false);
		recombinationRate.addChangeListener(new ChangeListener()
			{
			public void stateChanged(ChangeEvent e) { recombinationRateVal.setText("" + recombinationRate.getValue() + "%"); }
			});
		HBox ratebox = new HBox();
		ratebox.add(climb);
		ratebox.add(retry);
		ratebox.add(Strut.makeHorizontalStrut(30));
		ratebox.add(recombinationRateLabel);
		ratebox.add(recombinationRate);
		ratebox.add(recombinationRateVal);
		vbox.add(ratebox);


		JLabel mutationRateLabel = new JLabel("Mutation Rate", SwingConstants.RIGHT);
		mutationRateLabel.setPreferredSize(recombinationRateLabel.getPreferredSize());
        mutationRateLabel.setFont(Style.SMALL_FONT);
		mutationRateLabel.setForeground(Style.TEXT_COLOR);
		mutationRateLabel.setOpaque(false);
		JLabel mutationRateVal = new JLabel("" + INITIAL_MUTATION_RATE + "%");
        mutationRateVal.setFont(Style.SMALL_FONT);
		mutationRateVal.setForeground(Style.TEXT_COLOR);
		mutationRateVal.setOpaque(false);
		mutationRate.setOpaque(false);
		mutationRate.addChangeListener(new ChangeListener()
			{
			public void stateChanged(ChangeEvent e) { mutationRateVal.setText("" + mutationRate.getValue() + "%"); }
			});
		ratebox = new HBox();
		ratebox.add(backup);
		ratebox.add(reset);
		ratebox.add(Strut.makeHorizontalStrut(30));
		ratebox.add(mutationRateLabel);
		ratebox.add(mutationRate);
		ratebox.add(mutationRateVal);
		vbox.add(ratebox);
				
        panel.add(vbox, BorderLayout.WEST);
        top.add(panel);
        
        
        // Add Candidates

		panel =  new Category(null, "Candidates", Style.COLOR_B);

		HBox hbox = new HBox();
		
		ButtonGroup one = new ButtonGroup();
		ButtonGroup two = new ButtonGroup();
		ButtonGroup three = new ButtonGroup();
		
		VBox vr = new VBox();
		for(int i = 0; i < 16; i++)
			{
			final int _i = i;

			vbox = new VBox();
			plays[i] = new PushButton("Play")
				{
				public void perform()
					{
					if (synth.isSendingTestNotes())
						{
						currentPlay = _i - 1;
						}
					else
						{
						// change the model, send all parameters, maybe play a note,
						// and then restore the model.
						Model backup = synth.model;
						synth.model = currentModels[_i];
						synth.sendAllParameters();
						synth.doSendTestNote();
						synth.model = backup;
						}

					}
				};
			vbox.add(plays[i]);

			Box b = new Box(BoxLayout.X_AXIS);
			b.setBackground(Style.BACKGROUND_COLOR);
			b.add(Box.createGlue());
			b.add(ratings[i][0] = new JRadioButton("1"));<commit_msg>println<commit_after>/***
    Copyright 2017 by <NAME>
    Licensed under the Apache License version 2.0
*/

package edisyn;

import java.util.*;
import java.io.*;
import edisyn.gui.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;

/***

Procedure:

Menu -> Start Hill-Climb [or Menu -> Reset Hill-Climb if already started]
	Creates Hill-Climb Panel and Resets it to current patch
Menu -> Stop Hill-Climb
	Deletes Hill-Climb Panel

Each sound has:
1. Done (or Keep?) -> Deletes Hill-Climb Panel and sets current patch to this sound [probably requires double-check dialog panel]
2. Try -> Sends sound to current patch
3. Best / Second Best / Third Best

The Panel also has:
1. Iterate
2. Rate
3. Backup

***/


public class HillClimb extends SynthPanel
	{
	public static final int NUM_MODELS = 16;

	ArrayList oldA = new ArrayList();
	ArrayList oldB = new ArrayList();
	ArrayList oldC = new ArrayList();
	Model[] currentModels = new Model[NUM_MODELS];
	Model[] bestModels = new Model[3];
	JRadioButton[][] ratings = new JRadioButton[16][3];
	PushButton[] plays = new PushButton[16];
	public static final int INITIAL_MUTATION_RATE = 20;
	public static final int INITIAL_RECOMBINATION_RATE = 75;
	JSlider mutationRate = new JSlider(JSlider.HORIZONTAL, 0, 100, INITIAL_MUTATION_RATE);
	JSlider recombinationRate = new JSlider(JSlider.HORIZONTAL, 0, 100, INITIAL_RECOMBINATION_RATE);
	Category iterations;
	
	Synth synth;
	int currentPlay = 0;
	
	public HillClimb(Synth synth)
		{
		this.synth = synth;
	
		VBox top = new VBox();
		add(top, BorderLayout.CENTER);

		// add globals

		Category panel = new Category(null, "Iteration 1", Style.COLOR_A);
		iterations = panel;
		
		PushButton backup = new PushButton("Backup")
            {
            public void perform()
            	{
				pop();
            	resetCurrentPlay();
                }
            };
            
		PushButton climb = new PushButton("Climb")
            {
            public void perform()
            	{
            	climb(true);
            	resetCurrentPlay();
                }
            };
        climb.getButton().setPreferredSize(backup.getButton().getPreferredSize());
		
		PushButton reset = new PushButton("Reset")
            {
            public void perform()
            	{
				initialize((Model)(synth.getModel().clone()), true);
            	resetCurrentPlay();
                }
            };
        reset.getButton().setPreferredSize(backup.getButton().getPreferredSize());
		
		PushButton retry = new PushButton("Retry")
            {
            public void perform()
            	{
				again();
            	resetCurrentPlay();
                }
            };
        retry.getButton().setPreferredSize(backup.getButton().getPreferredSize());
		
		VBox vbox = new VBox();
		
		JLabel recombinationRateLabel = new JLabel("Recombination Rate", SwingConstants.RIGHT);
        recombinationRateLabel.setFont(Style.SMALL_FONT);
		recombinationRateLabel.setForeground(Style.TEXT_COLOR);
		recombinationRateLabel.setOpaque(false);
		JLabel recombinationRateVal = new JLabel("" + INITIAL_RECOMBINATION_RATE + "%");
        recombinationRateVal.setFont(Style.SMALL_FONT);
		recombinationRateVal.setForeground(Style.TEXT_COLOR);
		recombinationRateVal.setOpaque(false);
		recombinationRate.setOpaque(false);
		recombinationRate.addChangeListener(new ChangeListener()
			{
			public void stateChanged(ChangeEvent e) { recombinationRateVal.setText("" + recombinationRate.getValue() + "%"); }
			});
		HBox ratebox = new HBox();
		ratebox.add(climb);
		ratebox.add(retry);
		ratebox.add(Strut.makeHorizontalStrut(30));
		ratebox.add(recombinationRateLabel);
		ratebox.add(recombinationRate);
		ratebox.add(recombinationRateVal);
		vbox.add(ratebox);


		JLabel mutationRateLabel = new JLabel("Mutation Rate", SwingConstants.RIGHT);
		mutationRateLabel.setPreferredSize(recombinationRateLabel.getPreferredSize());
        mutationRateLabel.setFont(Style.SMALL_FONT);
		mutationRateLabel.setForeground(Style.TEXT_COLOR);
		mutationRateLabel.setOpaque(false);
		JLabel mutationRateVal = new JLabel("" + INITIAL_MUTATION_RATE + "%");
        mutationRateVal.setFont(Style.SMALL_FONT);
		mutationRateVal.setForeground(Style.TEXT_COLOR);
		mutationRateVal.setOpaque(false);
		mutationRate.setOpaque(false);
		mutationRate.addChangeListener(new ChangeListener()
			{
			public void stateChanged(ChangeEvent e) { mutationRateVal.setText("" + mutationRate.getValue() + "%"); }
			});
		ratebox = new HBox();
		ratebox.add(backup);
		ratebox.add(reset);
		ratebox.add(Strut.makeHorizontalStrut(30));
		ratebox.add(mutationRateLabel);
		ratebox.add(mutationRate);
		ratebox.add(mutationRateVal);
		vbox.add(ratebox);
				
        panel.add(vbox, BorderLayout.WEST);
        top.add(panel);
        
        
        // Add Candidates

		panel =  new Category(null, "Candidates", Style.COLOR_B);

		HBox hbox = new HBox();
		
		ButtonGroup one = new ButtonGroup();
		ButtonGroup two = new ButtonGroup();
		ButtonGroup three = new ButtonGroup();
		
		VBox vr = new VBox();
		for(int i = 0; i < 16; i++)
			{
			final int _i = i;

			vbox = new VBox();
			plays[i] = new PushButton("Play")
				{
				public void perform()
					{
					if (synth.isSendingTestNotes())
						{
						currentPlay = _i - 1;
						}
					else
						{
						// change the model, send all parameters, maybe play a note,
						// and then restore the model.
						Model backup = synth.model;
						synth.model = currentModels[_i];
						synth.sendAllParameters();
						synth.doSendTestNote(false);
						synth.model = backup;
						}

					}
				};
			vbox.add(plays[i]);

			Box b = new Box(BoxLayout.X_AXIS);
			b.setBackground(Style.BACKGROUND_COLOR);
			b.add(Box.createGlue());
			b.add(ratings[i][0] = new JRadioButton("1"));
{'fraction_non_alphanumeric': 0.11745625266752027, 'fraction_numerical': 0.007511737089201878, 'mean_word_length': 3.103677758318739, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '5177713', 'n_tokens_mistral': 4221, 'n_tokens_neox': 3652, 'n_words': 803}