<commit_before>package nak.nakloidGUI.gui;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ControlListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Scale;
import org.eclipse.swt.widgets.Shell;

import nak.nakloidGUI.NakloidGUI;
import nak.nakloidGUI.actions.displays.DisplayHorizontalZoomInAction;
import nak.nakloidGUI.actions.displays.DisplayHorizontalZoomOutAction;
import nak.nakloidGUI.actions.displays.DisplayLogAction;
import nak.nakloidGUI.actions.displays.DisplayNotesAction;
import nak.nakloidGUI.actions.displays.DisplayNotesWindowAction;
import nak.nakloidGUI.actions.displays.DisplayPitchesAction;
import nak.nakloidGUI.actions.displays.DisplayVerticalZoomInAction;
import nak.nakloidGUI.actions.displays.DisplayVerticalZoomOutAction;
import nak.nakloidGUI.actions.displays.DisplayZoomInAction;
import nak.nakloidGUI.actions.displays.DisplayZoomOutAction;
import nak.nakloidGUI.actions.editors.AddNoteAction;
import nak.nakloidGUI.actions.editors.EditLyricsAction;
import nak.nakloidGUI.actions.executors.BuildAction;
import nak.nakloidGUI.actions.executors.BuildAndPlayAction;
import nak.nakloidGUI.actions.executors.ExportWavAction;
import nak.nakloidGUI.actions.executors.InitializePitchesAction;
import nak.nakloidGUI.actions.executors.PlayAction;
import nak.nakloidGUI.actions.files.ExitAction;
import nak.nakloidGUI.actions.files.ExportVocalAction;
import nak.nakloidGUI.actions.files.ImportScoreAction;
import nak.nakloidGUI.actions.files.ImportVocalAction;
import nak.nakloidGUI.actions.files.OpenAction;
import nak.nakloidGUI.actions.files.SaveAction;
import nak.nakloidGUI.actions.files.SaveAsAction;
import nak.nakloidGUI.actions.files.SpeechSynthesisAction;
import nak.nakloidGUI.actions.options.AboutNakloidAction;
import nak.nakloidGUI.actions.options.NakloidOptionAction;
import nak.nakloidGUI.actions.options.VocalOptionAction;
import nak.nakloidGUI.coredata.CoreData;
import nak.nakloidGUI.coredata.CoreData.CoreDataSubscriber;
import nak.nakloidGUI.gui.mainWindowViews.KeyboardView;
import nak.nakloidGUI.gui.mainWindowViews.MainView;
import nak.nakloidGUI.gui.mainWindowViews.MainView.MainViewListener;
import nak.nakloidGUI.gui.mainWindowViews.OverView;
import nak.nakloidGUI.gui.mainWindowViews.OverView.OverViewListener;
import nak.nakloidGUI.gui.mainWindowViews.VocalInfoView;
import nak.nakloidGUI.models.Waveform;
import nak.nakloidGUI.models.Waveform.WaveformStatus;

public class MainWindow extends ApplicationWindow implements CoreDataSubscriber, MainViewListener, OverViewListener {
	private CoreData coreData;
	private MainWindowDisplayMode displayMode;
	private OverView overView;
	private VocalInfoView vocalInfoView;
	private KeyboardView keyboardView;
	private MainView mainView;
	private LoggerWindow loggerWindow;
	private NotesWindow notesWindow;
	private boolean displayLog = NakloidGUI.preferenceStore.getBoolean("gui.mainWindow.displayLogWindow");
	private boolean displayNotesWindow = NakloidGUI.preferenceStore.getBoolean("gui.mainWindow.displayNotesWindow");
	private double msByPixel = NakloidGUI.preferenceStore.getDouble("gui.mainWindow.baseMsByPixel");
	private double noteHeight = NakloidGUI.preferenceStore.getDouble("gui.mainWindow.baseNoteHeight");
	final public Action saveAction, saveAsAction, openAction, importNarAction, importVocalAction, exportVocalAction, speechSynthesisAction,exitAction,
			addNoteAction, editLyricsAction, displayNotesAction, displayPitchesAction, displayLogAction, displayNotesWindowAction,
			displayZoomInAction, displayZoomOutAction, displayHorizontalZoomInAction, displayHorizontalZoomOutAction, displayVerticalZoomInAction, displayVerticalZoomOutAction,
			playAction, buildAction, buildAndPlayAction, exportWavAction, initializePitchesAction,
			nakloidOptionAction, vocalOptionAction, aboutNakloidAction;

	static public enum MusicalScales {
		C(0),C_MAJOR(1),D(2),D_MAJOR(3),E(4),F(5),F_MAJOR(6),G(7),G_MAJOR(8),A(9),A_MAJOR(10),B(11);
		private static final String[] MusicalScaleStrings = {"C","C#","D","D#","E","F","F#","G","G#","A","A#","B"};
		private static final MusicalScales[] MusicalScaleInstances = {C,C_MAJOR,D,D_MAJOR,E,F,F_MAJOR,G,G_MAJOR,A,A_MAJOR,B};
		private final int id;
		private MusicalScales(int id) {
			this.id = id;
		}
		public String getString() {
			return MusicalScaleStrings[id];
		}
		public boolean isMajor() {
			return MusicalScaleStrings[id].endsWith("#");
		}
		public boolean equals(int numMidiNote) {
			return id == numMidiNote%12;
		}
		public static String getStringFromNumMidiNote(int numMidiNote, boolean withOctave) {
			return MusicalScaleStrings[numMidiNote%12]+((withOctave)?Integer.toString(numMidiNote/12-1):"");
		}
		public static MusicalScales getMusicalScalesFromNumMidiNote(int numMidiNote) {
			return MusicalScaleInstances[numMidiNote%12];
		}
	}

	public enum MainWindowDisplayMode {NOTES, PITCHES}

	public MainWindow() {
		super(null);

		Shell shellSplash = new Shell(SWT.ON_TOP);
		shellSplash.setLayout(new FillLayout());
		Image imgLoad = loadImage("icon256.png");
		Splash splash = new Splash(shellSplash, imgLoad);
		splash.setText("読み込み中...");
		shellSplash.open();

		StringBuilder sb = new StringBuilder();
		CoreData.Builder cdb = new CoreData.Builder();
		splash.setText("歌手情報を読み込み中...");
		try {
			cdb.loadOtoIni();
		} catch (IOException e) {
			sb.append("歌手情報が読み込めませんでした。\n");
		}
		if (!NakloidGUI.preferenceStore.getString("workspace.path_nar").isEmpty()) {
			splash.setText("最後に開いたnarファイルを読み込み中...");
			try {
				cdb.loadNar(Paths.get(NakloidGUI.preferenceStore.getString("workspace.path_nar")));
			} catch (IOException e) {
				sb.append("narファイルが読み込めませんでした。\n");
			}
			splash.setText("楽譜情報を読み込み中...");
			try {
				cdb.loadScore();
			} catch (IOException e) {
				sb.append("楽譜情報が読み込めませんでした。\n");
			}
			splash.setText("ピッチ情報を読み込み中...");
			try {
				cdb.loadPitches();
			} catch (IOException e) {
				sb.append("ピッチ情報が読み込めませんでした。\n");
			}
		}

		splash.setText("準備中...");
		coreData = cdb.build();<commit_msg>startup bugfix<commit_after>package nak.nakloidGUI.gui;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ControlListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Scale;
import org.eclipse.swt.widgets.Shell;

import nak.nakloidGUI.NakloidGUI;
import nak.nakloidGUI.actions.displays.DisplayHorizontalZoomInAction;
import nak.nakloidGUI.actions.displays.DisplayHorizontalZoomOutAction;
import nak.nakloidGUI.actions.displays.DisplayLogAction;
import nak.nakloidGUI.actions.displays.DisplayNotesAction;
import nak.nakloidGUI.actions.displays.DisplayNotesWindowAction;
import nak.nakloidGUI.actions.displays.DisplayPitchesAction;
import nak.nakloidGUI.actions.displays.DisplayVerticalZoomInAction;
import nak.nakloidGUI.actions.displays.DisplayVerticalZoomOutAction;
import nak.nakloidGUI.actions.displays.DisplayZoomInAction;
import nak.nakloidGUI.actions.displays.DisplayZoomOutAction;
import nak.nakloidGUI.actions.editors.AddNoteAction;
import nak.nakloidGUI.actions.editors.EditLyricsAction;
import nak.nakloidGUI.actions.executors.BuildAction;
import nak.nakloidGUI.actions.executors.BuildAndPlayAction;
import nak.nakloidGUI.actions.executors.ExportWavAction;
import nak.nakloidGUI.actions.executors.InitializePitchesAction;
import nak.nakloidGUI.actions.executors.PlayAction;
import nak.nakloidGUI.actions.files.ExitAction;
import nak.nakloidGUI.actions.files.ExportVocalAction;
import nak.nakloidGUI.actions.files.ImportScoreAction;
import nak.nakloidGUI.actions.files.ImportVocalAction;
import nak.nakloidGUI.actions.files.OpenAction;
import nak.nakloidGUI.actions.files.SaveAction;
import nak.nakloidGUI.actions.files.SaveAsAction;
import nak.nakloidGUI.actions.files.SpeechSynthesisAction;
import nak.nakloidGUI.actions.options.AboutNakloidAction;
import nak.nakloidGUI.actions.options.NakloidOptionAction;
import nak.nakloidGUI.actions.options.VocalOptionAction;
import nak.nakloidGUI.coredata.CoreData;
import nak.nakloidGUI.coredata.CoreData.CoreDataSubscriber;
import nak.nakloidGUI.gui.mainWindowViews.KeyboardView;
import nak.nakloidGUI.gui.mainWindowViews.MainView;
import nak.nakloidGUI.gui.mainWindowViews.MainView.MainViewListener;
import nak.nakloidGUI.gui.mainWindowViews.OverView;
import nak.nakloidGUI.gui.mainWindowViews.OverView.OverViewListener;
import nak.nakloidGUI.gui.mainWindowViews.VocalInfoView;
import nak.nakloidGUI.models.Waveform;
import nak.nakloidGUI.models.Waveform.WaveformStatus;

public class MainWindow extends ApplicationWindow implements CoreDataSubscriber, MainViewListener, OverViewListener {
	private CoreData coreData;
	private MainWindowDisplayMode displayMode;
	private OverView overView;
	private VocalInfoView vocalInfoView;
	private KeyboardView keyboardView;
	private MainView mainView;
	private LoggerWindow loggerWindow;
	private NotesWindow notesWindow;
	private boolean displayLog = NakloidGUI.preferenceStore.getBoolean("gui.mainWindow.displayLogWindow");
	private boolean displayNotesWindow = NakloidGUI.preferenceStore.getBoolean("gui.mainWindow.displayNotesWindow");
	private double msByPixel = NakloidGUI.preferenceStore.getDouble("gui.mainWindow.baseMsByPixel");
	private double noteHeight = NakloidGUI.preferenceStore.getDouble("gui.mainWindow.baseNoteHeight");
	final public Action saveAction, saveAsAction, openAction, importNarAction, importVocalAction, exportVocalAction, speechSynthesisAction,exitAction,
			addNoteAction, editLyricsAction, displayNotesAction, displayPitchesAction, displayLogAction, displayNotesWindowAction,
			displayZoomInAction, displayZoomOutAction, displayHorizontalZoomInAction, displayHorizontalZoomOutAction, displayVerticalZoomInAction, displayVerticalZoomOutAction,
			playAction, buildAction, buildAndPlayAction, exportWavAction, initializePitchesAction,
			nakloidOptionAction, vocalOptionAction, aboutNakloidAction;

	static public enum MusicalScales {
		C(0),C_MAJOR(1),D(2),D_MAJOR(3),E(4),F(5),F_MAJOR(6),G(7),G_MAJOR(8),A(9),A_MAJOR(10),B(11);
		private static final String[] MusicalScaleStrings = {"C","C#","D","D#","E","F","F#","G","G#","A","A#","B"};
		private static final MusicalScales[] MusicalScaleInstances = {C,C_MAJOR,D,D_MAJOR,E,F,F_MAJOR,G,G_MAJOR,A,A_MAJOR,B};
		private final int id;
		private MusicalScales(int id) {
			this.id = id;
		}
		public String getString() {
			return MusicalScaleStrings[id];
		}
		public boolean isMajor() {
			return MusicalScaleStrings[id].endsWith("#");
		}
		public boolean equals(int numMidiNote) {
			return id == numMidiNote%12;
		}
		public static String getStringFromNumMidiNote(int numMidiNote, boolean withOctave) {
			return MusicalScaleStrings[numMidiNote%12]+((withOctave)?Integer.toString(numMidiNote/12-1):"");
		}
		public static MusicalScales getMusicalScalesFromNumMidiNote(int numMidiNote) {
			return MusicalScaleInstances[numMidiNote%12];
		}
	}

	public enum MainWindowDisplayMode {NOTES, PITCHES}

	public MainWindow() {
		super(null);

		Shell shellSplash = new Shell(SWT.ON_TOP);
		shellSplash.setLayout(new FillLayout());
		Image imgLoad = loadImage("icon256.png");
		Splash splash = new Splash(shellSplash, imgLoad);
		splash.setText("読み込み中...");
		shellSplash.open();

		StringBuilder sb = new StringBuilder();
		CoreData.Builder cdb = new CoreData.Builder();
		splash.setText("歌手情報を読み込み中...");
		try {
			cdb.loadOtoIni();
		} catch (IOException e) {
			sb.append("歌手情報が読み込めませんでした。\n");
		}
		if (!NakloidGUI.preferenceStore.getString("workspace.path_nar").isEmpty()) {
			splash.setText("最後に開いたnarファイルを読み込み中...");
			try {
				cdb.loadNar(Paths.get(NakloidGUI.preferenceStore.getString("workspace.path_nar")));
			} catch (IOException e) {
				sb.append("narファイルが読み込めませんでした。\n");
				NakloidGUI.preferenceStore.setValue("workspace.path_nar", "");
			}
			splash.setText("楽譜情報を読み込み中...");
			try {
				cdb.loadScore();
			} catch (IOException e) {
				sb.append("楽譜情報が読み込めませんでした。\n");
			}
			splash.setText("ピッチ情報を読み込み中...");
			try {
				cdb.loadPitches();
			} catch (IOException e) {
				sb.append("ピッチ情報が読み込めませんでした。\n");
			}
		}

		splash.setText("準備中...");
		coreData = cdb.build();
{'fraction_non_alphanumeric': 0.11226215644820296, 'fraction_numerical': 0.003664552501761804, 'mean_word_length': 6.674959437533802, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4606671', 'n_tokens_mistral': 5161, 'n_tokens_neox': 4887, 'n_words': 687}