Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 5a482ef2a33b7520ff616d8dc38157f3dea035aa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*******************************************************************************
 * Copyright (c) 2008, 2018 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.debug.examples.core.midi.launcher;

import org.eclipse.core.runtime.IStatus;

/**
 * Displays a time value based on underlying microsecond value
 *
 * @since 1.0
 */
public abstract class TimeControl extends SequencerControl {

	/**
	 * Constructs a time control with the given name for the
	 * given launch.
	 *
	 * @param name
	 * @param launch
	 */
	public TimeControl(String name, MidiLaunch launch) {
		super(name, launch);
	}

	@Override
	public String getValue() {
		long position = getTimeValue();
		int milli = (int) (position & 0x3F);
		int sec = (int) (position / 1000000);
		int min = sec / 60;
		sec = sec % 60;
		StringBuffer clock = new StringBuffer();
		clock.append(min);
		while (clock.length() < 2) {
			clock.insert(0, 0);
		}
		clock.append(':');
		clock.append(sec);
		while (clock.length() < 5) {
			clock.insert(3, 0);
		}
		clock.append(':');
		clock.append(milli);
		while (clock.length() < 8) {
			clock.insert(6, 0);
		}
		return clock.toString();
	}

	/**
	 * Provided by subclasses for the control.
	 *
	 * @return time in microseconds
	 */
	protected abstract long getTimeValue();

	@Override
	public boolean isEditable() {
		return false;
	}

	@Override
	public IStatus setValue(String newValue) {
		return null;
	}

	@Override
	public IStatus validateValue(String value) {
		return null;
	}

}

Back to the top