aboutsummaryrefslogtreecommitdiff
path: root/Src/resources/skins/Big Bento/scripts/songinfo.m
blob: 2805f95c10a4292d5bee642aa29f3bb73278f0a6 (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*---------------------------------------------------
-----------------------------------------------------
Filename:	songinfo.m
Version:	1.0

Type:		maki
Date:		20. Nov. 2006 - 22:47 
Author:		Martin Poehlmann aka Deimos
E-Mail:		martin@skinconsortium.com
Internet:	www.skinconsortium.com
		www.martin.deimos.de.vu
-----------------------------------------------------
---------------------------------------------------*/

#include <lib/std.mi>

Function int getChannels (); // returning 1 for mono, 2 for stereo, more for multichannel (e.g. 6), -1 for no info available
Function string getBitrate();
Function string getFrequency();

Global layer monster;
Global timer delayload, songInfoTimer;

Global Text Bitrate, Frequency;
Global Layer l_Bitrate, l_Frequency;
Global int tempwidth;
Global boolean param;

System.onScriptLoaded()
{
	group PlayerDisplay = getScriptgroup();

	param = (getParam() == "big");

	monster = PlayerDisplay.findObject("monster");

	Bitrate = PlayerDisplay.findObject("Bitrate");
	Frequency = PlayerDisplay.findObject("Frequency");
	l_Bitrate = PlayerDisplay.findObject("Bitrate.label");
	l_Frequency = PlayerDisplay.findObject("Frequency.label");

	delayload = new Timer;
	delayload.setDelay(100);

	songInfoTimer = new Timer;
	songInfoTimer.setDelay(1000);

	Int PlayerStatus = System.getStatus();

	if ( PlayerStatus != 0 )
	{
		delayload.start();
		bitrate.setText(getBitrate());
		Frequency.setText(getFrequency());
		if (PlayerStatus == 1)
		{
			songInfoTimer.start();
		}
	}
}

system.onScriptUnloading ()
{
	songinfotimer.stop();
	delete songinfotimer;
	delayload.stop();
	delete delayload;
}

System.onResume()
{
	delayload.start();
	songInfoTimer.start();
}

System.onPlay()
{
	delayload.start();
	songInfoTimer.start();
}

System.onStop ()
{
	monster.setXmlParam("image", "player.songinfo.na");
	songInfoTimer.stop();
}

system.onPause ()
{
	songInfoTimer.stop();
}

System.onTitleChange(String newtitle)
{
	delayload.start();
	bitrate.setText(getBitrate());
}

delayload.onTimer ()
{
	delayload.stop();
	int c = getChannels();
	if (c == -1) monster.setXmlParam("image", "player.songinfo.na");
	else if (c == 1) monster.setXmlParam("image", "player.songinfo.mono");
	else if (c == 2 || c == 3) monster.setXmlParam("image", "player.songinfo.stereo");
	else
	{
		if (tempwidth > 23) monster.setXmlParam("image", "player.songinfo.multi2");
		else monster.setXmlParam("image", "player.songinfo.multi");
	}
	//ensure to display bitrate & frequency
	bitrate.setText(getBitrate());
	Frequency.setText(getFrequency());
}

Int getChannels ()
{
	if (strsearch(getSongInfoText(), "tereo") != -1)
	{
		return 2;
	}
	else if (strsearch(getSongInfoText(), "ono") != -1)
	{
		return 1;
	}
	else if (strsearch(getSongInfoText(), "annels") != -1)
	{
		int pos = strsearch(getSongInfoText(), "annels");
		return stringToInteger(strmid(getSongInfoText(), pos - 4, 1));
	}
	else
	{
		return -1;
	}
}

songInfoTimer.onTimer ()
{
	bitrate.setText(getBitrate());
}

string getBitrate ()
{
	string sit = strlower(getSongInfoText());
	if (sit != "")
	{
		string rtn;
		int searchresult;
		for (int i = 0; i < 5; i++) {
			rtn = getToken(sit, " ", i);
			searchResult = strsearch(rtn, "kbps");
			if (searchResult>0) return StrMid(rtn, 0, searchResult);
		}
		return "";
	}
	else
	{
		return "";
	}
}

string getFrequency ()
{
	string sit = strlower(getSongInfoText());
	if (sit != "")
	{
		string rtn;
		int searchresult;
		for (int i = 0; i < 5; i++) {
			rtn = getToken(sit, " ", i);
			searchResult = strsearch(strlower(rtn), "khz");
			if (searchResult>0) 
			{
				rtn = StrMid(rtn, 0, searchResult);
				searchResult = strsearch(strlower(rtn), ".");
				if (searchResult>0)
				{
					rtn = getToken(rtn, ".", 0);
				}
				return rtn;
			}
		}
		return "";
	}
	else
	{
		return "";
	}
}

Bitrate.onTextChanged (String newtxt)
{
	if (param) return;
	if (Bitrate.getTextWidth() == tempwidth) return;
	tempwidth = getTextWidth();
	if (getTextWidth() >  23)
	{
		monster.setXmlParam("x", "-39");
		Frequency.setXmlParam("x", "-75");
		l_Bitrate.setXmlParam("x", "-91");
		l_Frequency.setXmlParam("x", "-58");		
		Bitrate.setXmlParam("w", "26");
		if (getChannels() > 3) monster.setXmlParam("image", "player.songinfo.multi2");
	}
	else
	{
		monster.setXmlParam("x", "-45");
		Frequency.setXmlParam("x", "-80");
		l_Bitrate.setXmlParam("x", "-96");
		l_Frequency.setXmlParam("x", "-63");
		Bitrate.setXmlParam("w", "20");
		if (getChannels() > 3) monster.setXmlParam("image", "player.songinfo.multi");
	}
}