/[svn]/jsampler/trunk/src/org/jsampler/view/SessionViewConfig.java
ViewVC logotype

Contents of /jsampler/trunk/src/org/jsampler/view/SessionViewConfig.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1867 - (show annotations) (download)
Mon Mar 16 22:12:32 2009 UTC (15 years, 1 month ago) by iliev
File size: 3978 byte(s)
* proper handling of connection failures
* renamed Channels Panels to Channel Lanes
* code cleanup

1 /*
2 * JSampler - a java front-end for LinuxSampler
3 *
4 * Copyright (C) 2005-2009 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.view;
24
25 import java.util.LinkedList;
26
27 import org.jsampler.CC;
28
29 /**
30 *
31 * @author Grigor Iliev
32 */
33 public class SessionViewConfig {
34 public static class ChannelConfig {
35 public enum Type {
36 SMALL, NORMAL
37 }
38
39 public int channelsPanel = 0;
40 public Type type = Type.NORMAL;
41 public boolean expanded = false;
42 }
43
44 public static class DeviceConfig {
45 public boolean expanded = false;
46 }
47
48 private final LinkedList<ChannelConfig> channelConfigs = new LinkedList<ChannelConfig>();
49 private final LinkedList<DeviceConfig> midiDeviceConfigs = new LinkedList<DeviceConfig>();
50 private final LinkedList<DeviceConfig> audioDeviceConfigs = new LinkedList<DeviceConfig>();
51
52 public
53 SessionViewConfig(String[] conf) {
54 if(conf == null) return;
55
56 for(int i = 0; i < conf.length; i++) {
57 String s = conf[i];
58 if("[channel]".equals(s)) {
59 channelConfigs.add(parseChannel(conf, i + 1));
60 } else if("[MIDI device]".equals(s)) {
61 midiDeviceConfigs.add(parseDevice(conf, i + 1));
62 } else if("[audio device]".equals(s)) {
63 audioDeviceConfigs.add(parseDevice(conf, i + 1));
64 }
65 }
66 }
67
68 public ChannelConfig
69 pollChannelConfig() { return channelConfigs.poll(); }
70
71 public DeviceConfig
72 pollMidiDeviceConfig() { return midiDeviceConfigs.poll(); }
73
74 public DeviceConfig
75 pollAudioDeviceConfig() { return audioDeviceConfigs.poll(); }
76
77 private ChannelConfig
78 parseChannel(String[] conf, int index) {
79 ChannelConfig channelConfig = new ChannelConfig();
80 for(int i = index; i < conf.length; i++) {
81 if(conf[i].startsWith("[")) return channelConfig;
82 if(conf[i].startsWith("channelLane = ")) {
83 String s = conf[i].substring("channelLane = ".length());
84 if(s.isEmpty()) continue;
85
86 try {
87 channelConfig.channelsPanel = Integer.parseInt(s) - 1;
88 } catch(Exception x) {
89 CC.getLogger().info("Uknown channel lane: " + s);
90 }
91 } else if(conf[i].startsWith("channelsPanel = ")) {
92 String s = conf[i].substring("channelsPanel = ".length());
93 if(s.isEmpty()) continue;
94
95 try {
96 channelConfig.channelsPanel = Integer.parseInt(s) - 1;
97 } catch(Exception x) {
98 CC.getLogger().info("Uknown channel lane: " + s);
99 }
100 } else if(conf[i].startsWith("viewType = ")) {
101 String s = conf[i].substring("viewType = ".length());
102
103 if("SMALL".equals(s)) {
104 channelConfig.type = ChannelConfig.Type.SMALL;
105 } else if("NORMAL".equals(s)) {
106 channelConfig.type = ChannelConfig.Type.NORMAL;
107 } else {
108 CC.getLogger().info("Uknown channel view: " + s);
109 }
110 } else if(conf[i].startsWith("expanded = ")) {
111 String s = conf[i].substring("expanded = ".length());
112 channelConfig.expanded = Boolean.parseBoolean(s);
113 }
114 }
115 return channelConfig;
116 }
117
118 private DeviceConfig
119 parseDevice(String[] conf, int index) {
120 DeviceConfig deviceConfig = new DeviceConfig();
121 for(int i = index; i < conf.length; i++) {
122 if(conf[i].startsWith("[")) return deviceConfig;
123 if(conf[i].startsWith("expanded = ")) {
124 String s = conf[i].substring("expanded = ".length());
125 deviceConfig.expanded = Boolean.parseBoolean(s);
126 }
127 }
128 return deviceConfig;
129 }
130 }

  ViewVC Help
Powered by ViewVC