1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2011 Grigor Iliev <grigor@grigoriliev.com> |
5 |
* |
6 |
* This file is part of JSampler. |
7 |
* |
8 |
* JSampler is free software; you can redistribute it and/or modify |
9 |
* it under the terms of the GNU General Public License version 2 |
10 |
* as published by the Free Software Foundation. |
11 |
* |
12 |
* JSampler is distributed in the hope that it will be useful, |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License |
18 |
* along with JSampler; if not, write to the Free Software |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
20 |
* MA 02111-1307 USA |
21 |
*/ |
22 |
|
23 |
package org.jsampler.android.view; |
24 |
|
25 |
import static org.jsampler.android.view.AndroidI18n.i18n; |
26 |
|
27 |
import org.jsampler.CC; |
28 |
import org.jsampler.MidiInstrumentMap; |
29 |
import org.jsampler.event.ListEvent; |
30 |
import org.jsampler.event.ListListener; |
31 |
|
32 |
public class MidiMapSpinnerAdapter extends AbstractSpinnerAdapter<Object> |
33 |
implements ListListener<MidiInstrumentMap> { |
34 |
|
35 |
public static final String noMap = new String(i18n.getLabel("MidiMapSpinnerAdapter.noMap")); |
36 |
public static final String defaultMap = new String(i18n.getLabel("MidiMapSpinnerAdapter.defaultMap")); |
37 |
|
38 |
public MidiMapSpinnerAdapter() { |
39 |
CC.getSamplerModel().addMidiInstrumentMapListListener(this); |
40 |
} |
41 |
|
42 |
public void |
43 |
uninstall() { CC.getSamplerModel().removeMidiInstrumentMapListListener(this); } |
44 |
|
45 |
@Override |
46 |
public int |
47 |
size() { return CC.getSamplerModel().getMidiInstrumentMapCount() + 2; } |
48 |
|
49 |
@Override |
50 |
public Object |
51 |
get(int position) { |
52 |
if(position == 0) return noMap; |
53 |
if(position == 1) return defaultMap; |
54 |
return CC.getSamplerModel().getMidiInstrumentMap(position - 2); |
55 |
} |
56 |
|
57 |
public String |
58 |
getEmptyItemText() { return i18n.getLabel("MidiMapSpinnerAdapter.selectMap"); } |
59 |
|
60 |
public String |
61 |
getItemText(int position) { |
62 |
return getItem(position).toString(); |
63 |
} |
64 |
|
65 |
@Override |
66 |
public boolean |
67 |
compare(Object o1, Object o2) { |
68 |
if(o1 == null || o2 == null) return false; |
69 |
if(o1 instanceof MidiInstrumentMap) { |
70 |
if(o2 instanceof MidiInstrumentMap) { |
71 |
return ((MidiInstrumentMap)o1).getMapId() == ((MidiInstrumentMap)o2).getMapId(); |
72 |
} else { |
73 |
return false; |
74 |
} |
75 |
} |
76 |
|
77 |
return o1 == o2; // default map, no map |
78 |
} |
79 |
|
80 |
/** Invoked when a new MIDI instrument map is added to a list. */ |
81 |
@Override |
82 |
public void |
83 |
entryAdded(ListEvent<MidiInstrumentMap> e) { notifyDataSetChanged(); } |
84 |
|
85 |
/** Invoked when a new MIDI instrument map is removed from a list. */ |
86 |
@Override |
87 |
public void |
88 |
entryRemoved(ListEvent<MidiInstrumentMap> e) { notifyDataSetChanged(); } |
89 |
} |