Skip to content

Commit

Permalink
refactor: Rename some variables
Browse files Browse the repository at this point in the history
  • Loading branch information
ditek committed Feb 2, 2022
1 parent 058b570 commit 248091f
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 50 deletions.
22 changes: 11 additions & 11 deletions app/src/main/java/com/midisheetmusic/MidiOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
package com.midisheetmusic;

import java.io.*;
import android.util.Log;

import org.json.*;
import android.graphics.*;

Expand Down Expand Up @@ -63,9 +63,9 @@ public class MidiOptions implements Serializable {
public int lastMeasure; /** The last measure in the song */

public boolean useColors;
public boolean useDashColors; /* Will change the RED as color for dash and flat */
public boolean colorAccidentals; /** Will set RED as color for sharps and flats */
public boolean useFullHeight; /** Will enlarge the graphics to the full screen */
public int delayStartInterval; /** delay before playing after the play button is pressed **/
public int delayStartInterval; /** Delay playing after the play button is pressed **/

public int[] noteColors;
public int midiShift;
Expand Down Expand Up @@ -174,11 +174,11 @@ public String toJson() {
json.put("midiShift", midiShift);
json.put("key", key);
json.put("combineInterval", combineInterval);
json.put("delay2start", delayStartInterval);
json.put("delayStartInterval", delayStartInterval);
json.put("shade1Color", shade1Color);
json.put("shade2Color", shade2Color);
json.put("useColors", useColors);
json.put("useDashColors", useDashColors);
json.put("colorAccidentals", colorAccidentals);
json.put("useFullHeight", useFullHeight);
json.put("noteColors", jsonColors);
json.put("showMeasures", showMeasures);
Expand Down Expand Up @@ -258,12 +258,12 @@ public static MidiOptions fromJson(String jsonString) {
if (json.has("useFullHeight")) {
options.useFullHeight = json.getBoolean("useFullHeight");
}
if (json.has("useDashColors")) {
options.useDashColors = json.getBoolean("useDashColors");
if (json.has("colorAccidentals")) {
options.colorAccidentals = json.getBoolean("colorAccidentals");
}

if (json.has("delay2start")) {
options.delayStartInterval = json.getInt("delay2start");
if (json.has("delayStartInterval")) {
options.delayStartInterval = json.getInt("delayStartInterval");
}
else
{
Expand Down Expand Up @@ -317,7 +317,7 @@ void merge(MidiOptions saved) {
shade1Color = saved.shade1Color;
shade2Color = saved.shade2Color;
useColors = saved.useColors;
useDashColors = saved.useDashColors;
colorAccidentals = saved.colorAccidentals;
useFullHeight = saved.useFullHeight;
showMeasures = saved.showMeasures;
playMeasuresInLoop = saved.playMeasuresInLoop;
Expand Down Expand Up @@ -376,7 +376,7 @@ public MidiOptions copy() {
options.shade1Color = shade1Color;
options.shade2Color = shade2Color;
options.useColors = useColors;
options.useDashColors = useDashColors;
options.colorAccidentals = colorAccidentals;
options.useFullHeight = useFullHeight;
options.showMeasures = showMeasures;
options.playMeasuresInLoop = playMeasuresInLoop;
Expand Down
46 changes: 23 additions & 23 deletions app/src/main/java/com/midisheetmusic/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ public static class SettingsFragment extends PreferenceFragmentCompat
private ListPreference key; /** Key Signature to use */
private ListPreference time; /** Time Signature to use */
private ListPreference combineInterval; /** Interval (msec) to combine notes */
private ListPreference delay2start; /** Delay before playing */
private ListPreference delayStartInterval; /** Delay before playing */

private ColorPreference[] noteColors;
private SwitchPreferenceCompat useColors;
private SwitchPreferenceCompat useDashColors; /* if Red as Sharp is used */
private SwitchPreferenceCompat useFullHeight; /** Drawing on full height option */
private SwitchPreferenceCompat colorAccidentals; /** Use RED as color for sharps and flats */
private SwitchPreferenceCompat useFullHeight; /** Drawing on full height option */

private ColorPreference shade1Color; /** Right-hand color */
private ColorPreference shade2Color; /** Left-hand color */
Expand Down Expand Up @@ -168,7 +168,7 @@ private void createView() {
createKeySignaturePrefs(root);
createTimeSignaturePrefs(root);
createCombineIntervalPrefs(root);
createDelay2StartPrefs(root);
createDelayStartIntervalPrefs(root);
createColorPrefs(root);
setPreferenceScreen(root);
}
Expand Down Expand Up @@ -392,24 +392,24 @@ private void createCombineIntervalPrefs(PreferenceScreen root) {
* SetSummary is not to be used as The default mechanism will force the value but not the summary
* Therefore using call back to calculate the summary
*/
private void createDelay2StartPrefs(PreferenceScreen root) {
private void createDelayStartIntervalPrefs(PreferenceScreen root) {
int selected = options.delayStartInterval;
delay2start = new ListPreference(context);
delay2start.setKey("DelayToStart");
delay2start.setOnPreferenceChangeListener((preference, isChecked) -> {
delayStartInterval = new ListPreference(context);
delayStartInterval.setKey("DelayToStart");
delayStartInterval.setOnPreferenceChangeListener((preference, isChecked) -> {
options.delayStartInterval = Integer.parseInt((String)isChecked);
delay2start.setValueIndex(options.delayStartInterval / 1000);
delayStartInterval.setValueIndex(options.delayStartInterval / 1000);

return true;});
delay2start.setSummaryProvider((preference) -> {
delayStartInterval.setSummaryProvider((preference) -> {
return (Integer.parseInt((String)((ListPreference)preference).getValue()) / 1000) + " second(s)" ;
});

delay2start.setTitle(R.string.delay_to_start);
delay2start.setEntries(R.array.delay_to_start_entries);
delay2start.setEntryValues(R.array.delay_to_start_values);
delay2start.setValueIndex(selected / 1000);
root.addPreference(delay2start);
delayStartInterval.setTitle(R.string.delay_start_interval);
delayStartInterval.setEntries(R.array.delay_start_interval_entries);
delayStartInterval.setEntryValues(R.array.delay_start_interval_values);
delayStartInterval.setValueIndex(selected / 1000);
root.addPreference(delayStartInterval);
}


Expand All @@ -429,11 +429,11 @@ private void createColorPrefs(PreferenceScreen root) {
shade2Color.setTitle(R.string.left_hand_color);
root.addPreference(shade2Color);

useDashColors = new SwitchPreferenceCompat(context);
useDashColors.setTitle(R.string.use_dash_colors);
useDashColors.setChecked(options.useDashColors);
colorAccidentals = new SwitchPreferenceCompat(context);
colorAccidentals.setTitle(R.string.use_accidental_colors);
colorAccidentals.setChecked(options.colorAccidentals);

useDashColors.setOnPreferenceChangeListener((preference, isChecked) -> {
colorAccidentals.setOnPreferenceChangeListener((preference, isChecked) -> {
if ((boolean)isChecked == true)
useColors.setChecked(false);

Expand All @@ -444,14 +444,14 @@ private void createColorPrefs(PreferenceScreen root) {

return true;
});
root.addPreference(useDashColors);
root.addPreference(colorAccidentals);

useColors = new SwitchPreferenceCompat(context);
useColors.setTitle(R.string.use_note_colors);
useColors.setChecked(options.useColors);
useColors.setOnPreferenceChangeListener((preference, isChecked) -> {
if ((boolean)isChecked == true)
useDashColors.setChecked(false);
colorAccidentals.setChecked(false);

for (ColorPreference noteColorPref : noteColors) {
noteColorPref.setVisible((boolean)isChecked);
Expand Down Expand Up @@ -518,11 +518,11 @@ private void updateOptions() {
break;
}
options.combineInterval = Integer.parseInt(combineInterval.getValue());
options.delayStartInterval = Integer.parseInt(delay2start.getValue());
options.delayStartInterval = Integer.parseInt(delayStartInterval.getValue());
options.shade1Color = shade1Color.getColor();
options.shade2Color = shade2Color.getColor();
options.useColors = useColors.isChecked();
options.useDashColors = useDashColors.isChecked();
options.colorAccidentals = colorAccidentals.isChecked();
options.useFullHeight = useFullHeight.isChecked();
}

Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/midisheetmusic/SheetMusic.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void init(MidiFile file, MidiOptions options) {

filename = file.getFileName();

SetColors(options.noteColors, options.useColors, options.useDashColors, options.shade1Color, options.shade2Color);
SetColors(options.noteColors, options.useColors, options.colorAccidentals, options.shade1Color, options.shade2Color);

paint = new Paint();
paint.setTextSize(12.0f);
Expand Down Expand Up @@ -902,13 +902,13 @@ else if (symbols.get(startindex).getStartTime() / measurelen ==


/** Change the note colors for the sheet music, and redraw. */
public void SetColors(int[] newcolors, boolean shouldUseColors, boolean shouldUseDashColors, int newshade1, int newshade2) {
public void SetColors(int[] newcolors, boolean shouldUseColors, boolean shouldColorAccidentals, int newshade1, int newshade2) {
useColors = shouldUseColors;
if (NoteColors == null) {
NoteColors = new int[12];
for (int i = 0; i < 12; i++) {

if (shouldUseDashColors && NoteScale.IsBlackKey(i))
if (shouldColorAccidentals && NoteScale.IsBlackKey(i))
NoteColors[i] = Color.RED;
else
NoteColors[i] = Color.BLACK;
Expand Down
16 changes: 8 additions & 8 deletions app/src/main/java/com/midisheetmusic/SheetMusicActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,25 +149,25 @@ void createViews() {
createSheetMusic(options);
});

SwitchDrawerItem useDashColors = new SwitchDrawerItem();
SwitchDrawerItem colorAccidentals = new SwitchDrawerItem();

SwitchDrawerItem useColors = new SwitchDrawerItem()
.withName(R.string.use_note_colors)
.withChecked(options.useColors)
.withOnCheckedChangeListener((iDrawerItem, compoundButton, isChecked) -> {
if (isChecked == true)
{
options.useDashColors = false;
options.colorAccidentals = false;
}
useDashColors.setChecked(options.useDashColors);
drawer.updateItem(useDashColors);
colorAccidentals.setChecked(options.colorAccidentals);
drawer.updateItem(colorAccidentals);
options.useColors = isChecked;
createSheetMusic(options);
});


useDashColors.withName(R.string.use_dash_colors)
.withChecked(options.useDashColors)
colorAccidentals.withName(R.string.use_accidental_colors)
.withChecked(options.colorAccidentals)
.withOnCheckedChangeListener((iDrawerItem, compoundButton, isChecked) -> {
if (isChecked == true)
{
Expand All @@ -176,7 +176,7 @@ void createViews() {

useColors.setChecked(options.useColors);
drawer.updateItem(useColors);
options.useDashColors = isChecked;
options.colorAccidentals = isChecked;
createSheetMusic(options);
});

Expand Down Expand Up @@ -217,7 +217,7 @@ void createViews() {
.addDrawerItems(
scrollVertically,
useColors,
useDashColors,
colorAccidentals,
loopSettings,
new DividerDrawerItem()
)
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
<item>100 milliseconds</item>
</string-array>

<string-array name="delay_to_start_entries">
<string-array name="delay_start_interval_entries">
<item>0 second</item>
<item>1 seconds</item>
<item>2 seconds</item>
Expand All @@ -112,7 +112,7 @@
<item>100</item>
</string-array>

<string-array name="delay_to_start_values">
<string-array name="delay_start_interval_values">
<item>0</item>
<item>1000</item>
<item>2000</item>
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
<string name="time_signature">Time Signature</string>
<string name="combine_interval">Combine Interval</string>
<string name="combine_interval_summary">Notes within the given interval (in milliseconds) are combined into a single chord</string>
<string name="delay_to_start">Delay before start</string>
<string name="delay_to_start_summary">Delay before staring music</string>
<string name="delay_start_interval">Delay before start</string>
<string name="delay_start_interval_summary">Delay before staring music</string>
<string name="right_hand_color">Right Hand Color</string>
<string name="left_hand_color">Left Hand Color</string>
<string name="show_measures">Show Measure Numbers</string>
Expand All @@ -51,7 +51,7 @@
<string name="settings">Settings</string>
<string name="use_full_height">Use full height</string>
<string name="use_note_colors">Use Note Colors</string>
<string name="use_dash_colors">Use Sharp Colors</string>
<string name="use_accidental_colors">Use Accidental Colors</string>
<string name="home">Home</string>

</resources>

0 comments on commit 248091f

Please sign in to comment.