Updating JUCE Audio modules to newest version (this will break a few things)

This commit is contained in:
Jonathan Thomas
2015-09-02 18:09:07 -05:00
parent 7d40d614a6
commit b5ff396bd4
851 changed files with 13485 additions and 7821 deletions

View File

@@ -2,7 +2,7 @@
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2013 - Raw Material Software Ltd.
Copyright (c) 2015 - ROLI Ltd.
Permission is granted to use this software under the terms of either:
a) the GPL v2 (or any later version)
@@ -42,10 +42,8 @@ import android.opengl.*;
import android.text.ClipboardManager;
import android.text.InputType;
import android.util.DisplayMetrics;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import android.util.Log;
import java.io.*;
import java.net.URL;
import java.net.HttpURLConnection;
import javax.microedition.khronos.egl.EGLConfig;
@@ -55,7 +53,7 @@ import android.media.MediaScannerConnection;
import android.media.MediaScannerConnection.MediaScannerConnectionClient;
//==============================================================================
public final class JuceAppActivity extends Activity
public class JuceAppActivity extends Activity
{
//==============================================================================
static
@@ -64,7 +62,7 @@ public final class JuceAppActivity extends Activity
}
@Override
public final void onCreate (Bundle savedInstanceState)
public void onCreate (Bundle savedInstanceState)
{
super.onCreate (savedInstanceState);
@@ -75,14 +73,16 @@ public final class JuceAppActivity extends Activity
}
@Override
protected final void onDestroy()
protected void onDestroy()
{
quitApp();
super.onDestroy();
clearDataCache();
}
@Override
protected final void onPause()
protected void onPause()
{
if (viewHolder != null)
viewHolder.onPause();
@@ -92,7 +92,7 @@ public final class JuceAppActivity extends Activity
}
@Override
protected final void onResume()
protected void onResume()
{
super.onResume();
@@ -157,6 +157,14 @@ public final class JuceAppActivity extends Activity
group.removeView (view);
}
public final void deleteOpenGLView (OpenGLView view)
{
ViewGroup group = (ViewGroup) (view.getParent());
if (group != null)
group.removeView (view);
}
final class ViewHolder extends ViewGroup
{
public ViewHolder (Context context)
@@ -323,15 +331,26 @@ public final class JuceAppActivity extends Activity
setFocusableInTouchMode (true);
setOnFocusChangeListener (this);
requestFocus();
// swap red and blue colours to match internal opengl texture format
ColorMatrix colorMatrix = new ColorMatrix();
float[] colorTransform = { 0, 0, 1.0f, 0, 0,
0, 1.0f, 0, 0, 0,
1.0f, 0, 0, 0, 0,
0, 0, 0, 1.0f, 0 };
colorMatrix.set (colorTransform);
paint.setColorFilter (new ColorMatrixColorFilter (colorMatrix));
}
//==============================================================================
private native void handlePaint (long host, Canvas canvas);
private native void handlePaint (long host, Canvas canvas, Paint paint);
@Override
public void onDraw (Canvas canvas)
{
handlePaint (host, canvas);
handlePaint (host, canvas, paint);
}
@Override
@@ -342,6 +361,7 @@ public final class JuceAppActivity extends Activity
private boolean opaque;
private long host;
private Paint paint = new Paint();
//==============================================================================
private native void handleMouseDown (long host, int index, float x, float y, long time);
@@ -440,6 +460,22 @@ public final class JuceAppActivity extends Activity
return true;
}
@Override
public boolean onKeyMultiple (int keyCode, int count, KeyEvent event)
{
if (keyCode != KeyEvent.KEYCODE_UNKNOWN || event.getAction() != KeyEvent.ACTION_MULTIPLE)
return super.onKeyMultiple (keyCode, count, event);
if (event.getCharacters() != null)
{
int utf8Char = event.getCharacters().codePointAt (0);
handleKeyDown (host, utf8Char, utf8Char);
return true;
}
return false;
}
// this is here to make keyboard entry work on a Galaxy Tab2 10.1
@Override
public InputConnection onCreateInputConnection (EditorInfo outAttrs)
@@ -666,38 +702,103 @@ public final class JuceAppActivity extends Activity
public static final HTTPStream createHTTPStream (String address,
boolean isPost, byte[] postData, String headers,
int timeOutMs, int[] statusCode,
StringBuffer responseHeaders)
StringBuffer responseHeaders,
int numRedirectsToFollow)
{
try
{
HttpURLConnection connection = (HttpURLConnection) (new URL(address)
.openConnection());
if (connection != null)
{
try
{
if (isPost)
{
connection.setRequestMethod("POST");
connection.setConnectTimeout(timeOutMs);
connection.setDoOutput(true);
connection.setChunkedStreamingMode(0);
OutputStream out = connection.getOutputStream();
out.write(postData);
out.flush();
}
// timeout parameter of zero for HttpUrlConnection is a blocking connect (negative value for juce::URL)
if (timeOutMs < 0)
timeOutMs = 0;
else if (timeOutMs == 0)
timeOutMs = 30000;
return new HTTPStream (connection, statusCode, responseHeaders);
}
catch (Throwable e)
// headers - if not empty, this string is appended onto the headers that are used for the request. It must therefore be a valid set of HTML header directives, separated by newlines.
// So convert headers string to an array, with an element for each line
String headerLines[] = headers.split("\\n");
for (;;)
{
try
{
HttpURLConnection connection = (HttpURLConnection) (new URL(address).openConnection());
if (connection != null)
{
connection.disconnect();
try
{
connection.setInstanceFollowRedirects (false);
connection.setConnectTimeout (timeOutMs);
connection.setReadTimeout (timeOutMs);
// Set request headers
for (int i = 0; i < headerLines.length; ++i)
{
int pos = headerLines[i].indexOf (":");
if (pos > 0 && pos < headerLines[i].length())
{
String field = headerLines[i].substring (0, pos);
String value = headerLines[i].substring (pos + 1);
if (value.length() > 0)
connection.setRequestProperty (field, value);
}
}
if (isPost)
{
connection.setRequestMethod ("POST");
connection.setDoOutput (true);
if (postData != null)
{
OutputStream out = connection.getOutputStream();
out.write(postData);
out.flush();
}
}
HTTPStream httpStream = new HTTPStream (connection, statusCode, responseHeaders);
// Process redirect & continue as necessary
int status = statusCode[0];
if (--numRedirectsToFollow >= 0
&& (status == 301 || status == 302 || status == 303 || status == 307))
{
// Assumes only one occurrence of "Location"
int pos1 = responseHeaders.indexOf ("Location:") + 10;
int pos2 = responseHeaders.indexOf ("\n", pos1);
if (pos2 > pos1)
{
String newLocation = responseHeaders.substring(pos1, pos2);
// Handle newLocation whether it's absolute or relative
URL baseUrl = new URL (address);
URL newUrl = new URL (baseUrl, newLocation);
String transformedNewLocation = newUrl.toString();
if (transformedNewLocation != address)
{
address = transformedNewLocation;
// Clear responseHeaders before next iteration
responseHeaders.delete (0, responseHeaders.length());
continue;
}
}
}
return httpStream;
}
catch (Throwable e)
{
connection.disconnect();
}
}
}
}
catch (Throwable e) {}
catch (Throwable e) {}
return null;
return null;
}
}
public final void launchURL (String url)
@@ -743,4 +844,85 @@ public final class JuceAppActivity extends Activity
{
new SingleMediaScanner (this, filename);
}
public final Typeface getTypeFaceFromAsset (String assetName)
{
try
{
return Typeface.createFromAsset (this.getResources().getAssets(), assetName);
}
catch (Throwable e) {}
return null;
}
final protected static char[] hexArray = "0123456789ABCDEF".toCharArray();
public static String bytesToHex (byte[] bytes)
{
char[] hexChars = new char[bytes.length * 2];
for (int j = 0; j < bytes.length; ++j)
{
int v = bytes[j] & 0xff;
hexChars[j * 2] = hexArray[v >>> 4];
hexChars[j * 2 + 1] = hexArray[v & 0x0f];
}
return new String (hexChars);
}
final private java.util.Map dataCache = new java.util.HashMap();
synchronized private final File getDataCacheFile (byte[] data)
{
try
{
java.security.MessageDigest digest = java.security.MessageDigest.getInstance ("MD5");
digest.update (data);
String key = bytesToHex (digest.digest());
if (dataCache.containsKey (key))
return (File) dataCache.get (key);
File f = new File (this.getCacheDir(), "bindata_" + key);
f.delete();
FileOutputStream os = new FileOutputStream (f);
os.write (data, 0, data.length);
dataCache.put (key, f);
return f;
}
catch (Throwable e) {}
return null;
}
private final void clearDataCache()
{
java.util.Iterator it = dataCache.values().iterator();
while (it.hasNext())
{
File f = (File) it.next();
f.delete();
}
}
public final Typeface getTypeFaceFromByteArray (byte[] data)
{
try
{
File f = getDataCacheFile (data);
if (f != null)
return Typeface.createFromFile (f);
}
catch (Exception e)
{
Log.e ("JUCE", e.toString());
}
return null;
}
}