Skip to content

Commit 5ef2041

Browse files
committed
Added channel allocation mode field
1 parent 4525453 commit 5ef2041

File tree

9 files changed

+112
-12
lines changed

9 files changed

+112
-12
lines changed

ADLMIDI-Player/src/main/cpp/adlmidi-jni.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,20 @@ Java_ru_wohlsoft_adlmidiplayer_PlayerService_adl_1setVolumeRangeModel(
742742
pthread_mutex_unlock(&g_lock);
743743
}
744744

745+
JNIEXPORT void JNICALL
746+
Java_ru_wohlsoft_adlmidiplayer_PlayerService_adl_1setChannelAllocMode(
747+
JNIEnv *env,
748+
jclass instance,
749+
jlong device,
750+
jint chanAlloc
751+
)
752+
{
753+
(void)env; (void)instance;
754+
pthread_mutex_lock(&g_lock);
755+
adl_setChannelAllocMode(ADL_DEV, (int)chanAlloc);
756+
pthread_mutex_unlock(&g_lock);
757+
}
758+
745759
JNIEXPORT jint JNICALL
746760
Java_ru_wohlsoft_adlmidiplayer_PlayerService_adl_1setRunAtPcmRate(
747761
JNIEnv *env,

ADLMIDI-Player/src/main/java/ru/wohlsoft/adlmidiplayer/AppSettings.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class AppSettings
1414
static private int m_ADL_bank = 58;
1515
static private int m_ADL_tremolo = -1;
1616
static private int m_ADL_vibrato = -1;
17-
static private int m_ADL_scalable = -1;
17+
static private int m_ADL_scalable = 0;
1818
static private int m_ADL_softPanEnabled = 0;
1919
// Default 1 for performance reasons
2020
static private int m_ADL_runAtPcmRate = 1;
@@ -25,6 +25,7 @@ public class AppSettings
2525
static private int m_adl_numChips = 2;
2626
static private int m_ADL_num4opChannels = -1;
2727
static private int m_ADL_volumeModel = 0;
28+
static private int m_ADL_chanAllocMode = 0;
2829

2930
static private double m_gainingLevel = 2.0;
3031

@@ -41,7 +42,7 @@ static public void loadSetup(SharedPreferences setup)
4142
m_ADL_bank = setup.getInt("adlBank", m_ADL_bank);
4243
m_ADL_tremolo = setup.getBoolean("flagTremolo", m_ADL_tremolo > 0) ? 1 : -1;
4344
m_ADL_vibrato = setup.getBoolean("flagVibrato", m_ADL_vibrato > 0) ? 1 : -1;
44-
m_ADL_scalable = setup.getBoolean("flagScalable", m_ADL_scalable > 0) ? 1 : -1;
45+
m_ADL_scalable = setup.getBoolean("flagScalable", m_ADL_scalable > 0) ? 1 : 0;
4546
m_ADL_softPanEnabled = setup.getBoolean("flagSoftPan", m_ADL_softPanEnabled > 0) ? 1 : 0;
4647
m_ADL_runAtPcmRate = setup.getBoolean("flagRunAtPcmRate", m_ADL_runAtPcmRate > 0) ? 1 : 0;
4748
m_ADL_autoArpeggio = setup.getBoolean("flagAutoArpeggio", m_ADL_autoArpeggio > 0) ? 1 : 0;
@@ -50,6 +51,7 @@ static public void loadSetup(SharedPreferences setup)
5051
m_adl_numChips = setup.getInt("numChips", m_adl_numChips);
5152
m_ADL_num4opChannels = setup.getInt("num4opChannels", m_ADL_num4opChannels);
5253
m_ADL_volumeModel = setup.getInt("volumeModel", m_ADL_volumeModel);
54+
m_ADL_chanAllocMode = setup.getInt("chanAllocMode", m_ADL_chanAllocMode);
5355

5456
m_gainingLevel = (double)setup.getFloat("gaining", (float)m_gainingLevel);
5557
}
@@ -104,6 +106,18 @@ static public int getVolumeModel()
104106
}
105107

106108

109+
static public void setChanAllocMode(int chanAllocMode)
110+
{
111+
m_ADL_chanAllocMode = chanAllocMode;
112+
m_setup.edit().putInt("chanAllocMode", m_ADL_chanAllocMode).apply();
113+
}
114+
115+
static public int getChanAlocMode()
116+
{
117+
return m_ADL_chanAllocMode;
118+
}
119+
120+
107121
static public void setDeepTremolo(boolean flag)
108122
{
109123
m_ADL_tremolo = flag ? 1 : -1;
@@ -136,7 +150,7 @@ static public int getDeepVibratoRaw()
136150

137151
static public void setScalableModulators(boolean flag)
138152
{
139-
m_ADL_scalable = flag ? 1 : -1;
153+
m_ADL_scalable = flag ? 1 : 0;
140154
m_setup.edit().putBoolean("flagScalable", flag).apply();
141155
}
142156

ADLMIDI-Player/src/main/java/ru/wohlsoft/adlmidiplayer/Player.java

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ public void onServiceDisconnected(ComponentName arg0)
126126
}
127127
};
128128

129+
@SuppressLint("SetTextI18n")
129130
private void initUiSetup(boolean fromConnect)
130131
{
131132
boolean isPlaying = false;
@@ -142,7 +143,7 @@ private void initUiSetup(boolean fromConnect)
142143
Log.d(LOG_TAG, "\"bound\" set to true");
143144
isPlaying = m_service.isPlaying();
144145

145-
if (isPlaying)
146+
if(isPlaying)
146147
{
147148
Log.d(LOG_TAG, "Player works, make a toast");
148149
seekerStart();
@@ -330,6 +331,31 @@ public void onNothingSelected(AdapterView<?> parent) {
330331
}
331332
});
332333

334+
/*
335+
* Channel allocation mode combo-box
336+
*/
337+
Spinner sChanMode = (Spinner) findViewById(R.id.channelAllocationMode);
338+
final String[] chanAllocModeItems = {"[Auto]", "Releasing delay", "Released with same instrument", "Any released" };
339+
340+
ArrayAdapter<String> adapterCA = new ArrayAdapter<>(
341+
this, android.R.layout.simple_spinner_item, chanAllocModeItems);
342+
adapterCA.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
343+
sChanMode.setAdapter(adapterCA);
344+
sChanMode.setSelection(AppSettings.getChanAlocMode());
345+
346+
sChanMode.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
347+
public void onItemSelected(AdapterView<?> parent,
348+
View itemSelected, int selectedItemPosition, long selectedId)
349+
{
350+
AppSettings.setChanAllocMode(selectedItemPosition - 1);
351+
if(m_bound)
352+
m_service.setChanAllocMode(selectedItemPosition - 1);
353+
}
354+
355+
public void onNothingSelected(AdapterView<?> parent) {
356+
}
357+
});
358+
333359

334360
/*
335361
* Deep Tremolo checkbox
@@ -766,7 +792,7 @@ protected void onStop() {
766792
public boolean onKeyUp(int keyCode, KeyEvent event) {
767793
if (keyCode == KeyEvent.KEYCODE_MENU) {
768794

769-
/* **
795+
/***
770796
* TODO: Rpleace this crap with properly made settings box
771797
* (this one can't receive changed value for "input" EditText field)
772798
*/
@@ -913,6 +939,7 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
913939
}
914940
}
915941

942+
916943
public void OnOpenBankFileClick(View view)
917944
{
918945
// Here, thisActivity is the current activity
@@ -932,15 +959,19 @@ public void openBankDialog()
932959
.setOpenDialogListener(new OpenFileDialog.OpenDialogListener()
933960
{
934961
@Override
935-
public void OnSelectedFile(Context ctx, String fileName, String lastPath) {
962+
public void OnSelectedFile(Context ctx, String fileName, String lastPath)
963+
{
936964
m_lastBankPath = fileName;
937965
AppSettings.setBankPath(m_lastBankPath);
938966

939967
TextView cbl = (TextView) findViewById(R.id.bankFileName);
940-
if(!m_lastBankPath.isEmpty()) {
968+
if(!m_lastBankPath.isEmpty())
969+
{
941970
File f = new File(m_lastBankPath);
942971
cbl.setText(f.getName());
943-
} else {
972+
}
973+
else
974+
{
944975
cbl.setText(R.string.noCustomBankLabel);
945976
}
946977
if(m_bound)
@@ -967,13 +998,13 @@ public void openMusicFileDialog()
967998
.setCurrentDirectory(m_lastPath)
968999
.setOpenDialogListener(new OpenFileDialog.OpenDialogListener()
9691000
{
970-
@Override
971-
public void OnSelectedDirectory(Context ctx, String lastPath) {}
972-
9731001
@Override
9741002
public void OnSelectedFile(Context ctx, String fileName, String lastPath) {
9751003
processMusicFile(fileName, lastPath);
9761004
}
1005+
1006+
@Override
1007+
public void OnSelectedDirectory(Context ctx, String lastPath) {}
9771008
});
9781009
fileDialog.show();
9791010
}
@@ -1133,3 +1164,4 @@ void onGainUpdate(double gainLevel, boolean silent)
11331164
gainFactor.setText(String.format(Locale.getDefault(), "%.1f", gainLevel));
11341165
}
11351166
}
1167+

ADLMIDI-Player/src/main/java/ru/wohlsoft/adlmidiplayer/PlayerService.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ public void applySetup()
455455
adl_setScaleModulators(MIDIDevice, AppSettings.getScalableModulationRaw());
456456
adl_setSoftPanEnabled(MIDIDevice, AppSettings.getFullPanningStereoRaw());
457457
adl_setVolumeRangeModel(MIDIDevice, AppSettings.getVolumeModel());
458+
adl_setChannelAllocMode(MIDIDevice, AppSettings.getChanAlocMode());
458459
adl_setLoopEnabled(MIDIDevice, 1);
459460
}
460461

@@ -495,6 +496,14 @@ public void setVolumeModel(int volumeModel)
495496
adl_setVolumeRangeModel(MIDIDevice, volumeModel);
496497
}
497498

499+
public void setChanAllocMode(int chanAllocMode)
500+
{
501+
if(MIDIDevice == 0) {
502+
return;
503+
}
504+
adl_setChannelAllocMode(MIDIDevice, chanAllocMode);
505+
}
506+
498507
public void setDeepTremolo(boolean flag)
499508
{
500509
if(MIDIDevice == 0) {
@@ -785,6 +794,8 @@ public void playerStop() {
785794
// extern void adl_setVolumeRangeModel(struct ADL_MIDIPlayer *device, int volumeModel);
786795
public static native void adl_setVolumeRangeModel(long device, int volumeModel);
787796

797+
public static native void adl_setChannelAllocMode(long device, int chanalloc);
798+
788799
public static native int adl_setRunAtPcmRate(long device, int enabled);
789800

790801
public static native int adl_setAutoArpeggio(long device, int enabled);

ADLMIDI-Player/src/main/res/layout/activity_player.xml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,38 @@
195195
android:minHeight="30dp" />
196196

197197
<TextView
198-
android:id="@+id/musicBankLabel"
198+
android:id="@+id/channelAllocationModeLabel"
199199
android:layout_width="wrap_content"
200200
android:layout_height="wrap_content"
201201
android:layout_below="@+id/volumeRangesModel"
202202
android:layout_alignParentStart="true"
203203
android:layout_alignParentLeft="true"
204204
android:layout_alignParentEnd="true"
205205
android:layout_alignParentRight="true"
206+
android:text="@string/chanAllocationMode"
207+
tools:text="@string/chanAllocationMode" />
208+
209+
<Spinner
210+
android:id="@+id/channelAllocationMode"
211+
android:layout_width="match_parent"
212+
android:layout_height="wrap_content"
213+
android:layout_below="@+id/channelAllocationModeLabel"
214+
android:layout_alignParentStart="true"
215+
android:layout_alignParentLeft="true"
216+
android:layout_alignParentEnd="true"
217+
android:layout_alignParentRight="true"
218+
android:layout_marginBottom="15dp"
219+
android:minHeight="30dp" />
220+
221+
<TextView
222+
android:id="@+id/musicBankLabel"
223+
android:layout_width="wrap_content"
224+
android:layout_height="wrap_content"
225+
android:layout_below="@+id/channelAllocationMode"
226+
android:layout_alignParentStart="true"
227+
android:layout_alignParentLeft="true"
228+
android:layout_alignParentEnd="true"
229+
android:layout_alignParentRight="true"
206230
android:text="@string/bankNo"
207231
tools:text="@string/bankNo" />
208232

ADLMIDI-Player/src/main/res/values-en/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@
2828
<string name="emulatorType">OPL3 Emulator</string>
2929
<string name="noCustomBankLabel"><![CDATA[<No custom bank>]]></string>
3030
<string name="autoArpeggio">Auto Arpeggio</string>
31+
<string name="chanAllocationMode">Channel allocation mode</string>
3132
</resources>

ADLMIDI-Player/src/main/res/values-fr/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@
2727
<string name="run_at_pcm_rate">Calculer au taux PCM (charge processeur moindre)</string>
2828
<string name="emulatorType">Émulateur OPL3</string>
2929
<string name="noCustomBankLabel"><![CDATA[<No custom bank>]]></string>
30+
<string name="autoArpeggio">Arpège automatique</string>
31+
<string name="chanAllocationMode">Mode d\'allocation des canaux</string>
3032
</resources>

ADLMIDI-Player/src/main/res/values-ru/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@
2828
<string name="emulatorType">Эмулятор OPL3</string>
2929
<string name="noCustomBankLabel"><![CDATA[<Нет внешнего банка>]]></string>
3030
<string name="autoArpeggio">Авто-арпеджио</string>
31+
<string name="chanAllocationMode">Режим выборки каналов</string>
3132
</resources>

ADLMIDI-Player/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@
3131
<string name="emulatorType">OPL3 Emulator</string>
3232
<string name="noCustomBankLabel"><![CDATA[<No custom bank>]]></string>
3333
<string name="autoArpeggio">Auto Arpeggio</string>
34+
<string name="chanAllocationMode">Channel allocation mode</string>
3435
</resources>

0 commit comments

Comments
 (0)