├── .gitattributes ├── .gitignore ├── app ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── deviantdev │ │ └── pdsampleproject │ │ ├── MainActivity.java │ │ └── PDSampleProjectApplication.java │ └── res │ ├── layout │ ├── activity_main.xml │ └── content_main.xml │ ├── menu │ └── menu_main.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ └── ic_launcher.png │ ├── raw │ └── pdpatch.zip │ ├── values-de │ └── strings.xml │ ├── values-v21 │ └── styles.xml │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.gitignore.io/api/android,linux,macos,windows 2 | 3 | ### Android ### 4 | # Built application files 5 | *.apk 6 | *.ap_ 7 | 8 | # Files for the ART/Dalvik VM 9 | *.dex 10 | 11 | # Java class files 12 | *.class 13 | 14 | # Generated files 15 | bin/ 16 | gen/ 17 | out/ 18 | 19 | # Gradle files 20 | .gradle/ 21 | build/ 22 | 23 | # Local configuration file (sdk path, etc) 24 | local.properties 25 | 26 | # Proguard folder generated by Eclipse 27 | proguard/ 28 | 29 | # Log Files 30 | *.log 31 | 32 | # Android Studio Navigation editor temp files 33 | .navigation/ 34 | 35 | # Android Studio captures folder 36 | captures/ 37 | 38 | # Keystore files 39 | *.jks 40 | 41 | # External native build folder generated in Android Studio 2.2 and later 42 | .externalNativeBuild 43 | 44 | ## Android Patch ## 45 | gen-external-apklibs 46 | 47 | ### Intellij+iml ### 48 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm 49 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 50 | 51 | ## Intellij+iml Patch ## 52 | # Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023 53 | 54 | .idea/ 55 | *.iml 56 | *.ipr 57 | modules.xml 58 | 59 | ## File-based project format: 60 | *.iws 61 | 62 | ## Plugin-specific files: 63 | 64 | # IntelliJ 65 | /out/ 66 | 67 | # JIRA plugin 68 | atlassian-ide-plugin.xml 69 | 70 | # Crashlytics plugin (for Android Studio and IntelliJ) 71 | com_crashlytics_export_strings.xml 72 | crashlytics.properties 73 | crashlytics-build.properties 74 | fabric.properties 75 | 76 | ### Operating System ### 77 | 78 | 79 | ## Linux ## 80 | *~ 81 | 82 | # temporary files which can be created if a process still has a handle open of a deleted file 83 | .fuse_hidden* 84 | 85 | # KDE directory preferences 86 | .directory 87 | 88 | # Linux trash folder which might appear on any partition or disk 89 | .Trash-* 90 | 91 | # .nfs files are created when an open file is removed but is still being accessed 92 | .nfs* 93 | 94 | 95 | ## macOS ## 96 | *.DS_Store 97 | .AppleDouble 98 | .LSOverride 99 | 100 | # Icon must end with two \r 101 | Icon 102 | 103 | 104 | # Thumbnails 105 | ._* 106 | 107 | # Files that might appear in the root of a volume 108 | .DocumentRevisions-V100 109 | .fseventsd 110 | .Spotlight-V100 111 | .TemporaryItems 112 | .Trashes 113 | .VolumeIcon.icns 114 | .com.apple.timemachine.donotpresent 115 | 116 | # Directories potentially created on remote AFP share 117 | .AppleDB 118 | .AppleDesktop 119 | Network Trash Folder 120 | Temporary Items 121 | .apdisk 122 | 123 | 124 | ## Windows ## 125 | 126 | # Windows image file caches 127 | Thumbs.db 128 | ehthumbs.db 129 | 130 | # Folder config file 131 | Desktop.ini 132 | 133 | # Recycle Bin used on file shares 134 | $RECYCLE.BIN/ 135 | 136 | # Windows Installer files 137 | *.cab 138 | *.msi 139 | *.msm 140 | *.msp 141 | 142 | # Windows shortcuts 143 | *.lnk -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 24 5 | buildToolsVersion "24.0.3" 6 | 7 | defaultConfig { 8 | applicationId "com.deviantdev.pdsampleproject" 9 | minSdkVersion 19 10 | targetSdkVersion 24 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:24.2.1' 26 | compile 'com.android.support:design:24.2.1' 27 | 28 | compile 'org.puredata.android:pd-core:1.0.1' 29 | } 30 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\Users\hschu\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/deviantdev/pdsampleproject/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.deviantdev.pdsampleproject; 2 | 3 | import android.content.ComponentName; 4 | import android.content.Intent; 5 | import android.content.ServiceConnection; 6 | import android.net.Uri; 7 | import android.os.Bundle; 8 | import android.os.IBinder; 9 | import android.support.design.widget.FloatingActionButton; 10 | import android.support.v7.app.AppCompatActivity; 11 | import android.util.Log; 12 | import android.view.Menu; 13 | import android.view.MenuItem; 14 | import android.view.MotionEvent; 15 | import android.view.View; 16 | import android.widget.Button; 17 | import android.widget.CompoundButton; 18 | import android.widget.SeekBar; 19 | import android.widget.Toast; 20 | import android.widget.ToggleButton; 21 | 22 | import org.puredata.android.io.AudioParameters; 23 | import org.puredata.android.service.PdService; 24 | import org.puredata.android.utils.PdUiDispatcher; 25 | import org.puredata.core.PdBase; 26 | import org.puredata.core.utils.IoUtils; 27 | 28 | import java.io.File; 29 | import java.io.IOException; 30 | 31 | public class MainActivity extends AppCompatActivity { 32 | 33 | private static final String TAG = "PDSampleProject"; 34 | 35 | Button btnPlaySound; 36 | ToggleButton btnToggleSound; 37 | SeekBar seekbarFrequency; 38 | SeekBar seekbarVolume; 39 | 40 | /** 41 | * The PdService is provided by the pd-for-android library. 42 | */ 43 | private PdService pdService = null; 44 | 45 | /** 46 | * The volume value as integer from 0 to 100 percent 47 | */ 48 | int volume = 0; 49 | 50 | /** 51 | * Initialises the pure data service for playing audio and receiving control commands. 52 | */ 53 | private final ServiceConnection pdConnection = new ServiceConnection() { 54 | @Override 55 | public void onServiceConnected(ComponentName name, IBinder service) { 56 | pdService = ((PdService.PdBinder)service).getService(); 57 | initPd(); 58 | 59 | try { 60 | int sampleRate = AudioParameters.suggestSampleRate(); 61 | pdService.initAudio( sampleRate, 0, 2, 8 ); 62 | pdService.startAudio(); 63 | } catch (IOException e) { 64 | toast(e.toString()); 65 | } 66 | } 67 | 68 | @Override 69 | public void onServiceDisconnected(ComponentName name) { 70 | pdService.stopAudio(); 71 | } 72 | }; 73 | 74 | /** 75 | * Initialises the pure data audio interface and loads the patch file packaged within the app. 76 | */ 77 | @SuppressWarnings("ResultOfMethodCallIgnored") 78 | private void initPd() { 79 | File patchFile = null; 80 | try { 81 | PdBase.setReceiver(new PdUiDispatcher()); 82 | PdBase.subscribe("android"); 83 | File dir = getFilesDir(); 84 | IoUtils.extractZipResource( getResources().openRawResource( R.raw.pdpatch ), dir, true ); 85 | patchFile = new File( dir, "pdpatch.pd" ); 86 | PdBase.openPatch( patchFile.getAbsolutePath() ); 87 | } catch (IOException e) { 88 | Log.e(TAG, e.toString()); 89 | finish(); 90 | } finally { 91 | if (patchFile != null) { 92 | patchFile.delete(); 93 | } 94 | } 95 | } 96 | 97 | @Override 98 | protected void onCreate(Bundle savedInstanceState) { 99 | super.onCreate(savedInstanceState); 100 | setContentView(R.layout.activity_main); 101 | 102 | AudioParameters.init(this); 103 | bindService(new Intent(this, PdService.class), pdConnection, BIND_AUTO_CREATE); 104 | 105 | initGui(); 106 | } 107 | 108 | @Override 109 | protected void onDestroy() { 110 | super.onDestroy(); 111 | try { 112 | unbindService(pdConnection); 113 | } catch (IllegalArgumentException e) { 114 | pdService = null; 115 | } 116 | } 117 | 118 | @Override 119 | public boolean onCreateOptionsMenu( Menu menu ) { 120 | getMenuInflater().inflate( R.menu.menu_main, menu ); 121 | return true; 122 | } 123 | 124 | @Override 125 | public boolean onOptionsItemSelected( MenuItem item ) { 126 | int id = item.getItemId(); 127 | 128 | if ( id == R.id.action_link ) { 129 | Intent browserIntent = new Intent( Intent.ACTION_VIEW, Uri.parse( "http://www.journal.deviantdev.com/example-libpd-android-studio/" ) ); 130 | startActivity( browserIntent ); 131 | return true; 132 | } 133 | 134 | if ( id == R.id.action_exit ) { 135 | moveTaskToBack( true ); 136 | return true; 137 | } 138 | 139 | return super.onOptionsItemSelected( item ); 140 | } 141 | 142 | /** 143 | * Initialises the user interface elements and necessary handlers responsibly for the interaction with the 144 | * pre-loaded pure data patch. The code is really pure data patch specific. 145 | */ 146 | private void initGui() { 147 | // touch to play button 148 | this.btnPlaySound = (Button) findViewById( R.id.buttonPlaySound ); 149 | this.btnPlaySound.setOnTouchListener( new View.OnTouchListener() { 150 | @Override 151 | public boolean onTouch( View v, MotionEvent event ) { 152 | if ( event.getAction() == MotionEvent.ACTION_DOWN ) { 153 | PdBase.sendFloat( "osc_volume", volume / 100f ); // send volume (0 to 1) 154 | } else if ( event.getAction() == MotionEvent.ACTION_UP ) { 155 | PdBase.sendFloat( "osc_volume", 0 ); // quiet down 156 | } 157 | return false; 158 | } 159 | } ); 160 | 161 | // toggle play button 162 | this.btnToggleSound = (ToggleButton) findViewById( R.id.buttonToggleSound ); 163 | this.btnToggleSound.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() { 164 | @Override 165 | public void onCheckedChanged( CompoundButton buttonView, boolean isChecked ) { 166 | 167 | if ( btnPlaySound.isEnabled() ) { 168 | btnPlaySound.setEnabled( false ); 169 | PdBase.sendFloat( "osc_volume", volume / 100f ); // enable volume while locked 170 | } else { 171 | btnPlaySound.setEnabled( true ); 172 | PdBase.sendFloat( "osc_volume", 0 ); // quiet down for after unlock 173 | } 174 | } 175 | } ); 176 | 177 | // seekbar for volume 178 | this.seekbarVolume = (SeekBar) findViewById( R.id.seekbarVolume ); 179 | this.seekbarVolume.setMax( 100 ); 180 | this.seekbarVolume.incrementProgressBy( 1 ); 181 | this.seekbarVolume.setProgress( 0 ); 182 | this.seekbarVolume.setOnSeekBarChangeListener( new SeekBar.OnSeekBarChangeListener() { 183 | 184 | public void onProgressChanged( SeekBar seekBar, int progress, boolean fromUser ) { 185 | volume = progress; 186 | if ( btnToggleSound.isChecked() ) { 187 | PdBase.sendFloat( "osc_volume", volume / 100f ); // send volume (0 to 1) if locked 188 | } 189 | } 190 | 191 | public void onStartTrackingTouch( SeekBar seekBar ) {} 192 | 193 | public void onStopTrackingTouch( SeekBar seekBar ) {} 194 | } ); 195 | 196 | // seekbar for frequency 197 | this.seekbarFrequency = (SeekBar) findViewById( R.id.seekbarFrequency ); 198 | this.seekbarFrequency.setMax( 100 ); 199 | this.seekbarFrequency.incrementProgressBy( 1 ); 200 | this.seekbarFrequency.setProgress( 0 ); 201 | this.seekbarFrequency.setOnSeekBarChangeListener( new SeekBar.OnSeekBarChangeListener() { 202 | public void onProgressChanged( SeekBar seekBar, int progress, boolean fromUser ) { 203 | if ( progress == 0 ) progress = 1; 204 | float a = progress / 100f; 205 | float frequency = (float) ( 2500 * Math.exp( 2.19722 * a ) - 2500 ); 206 | PdBase.sendFloat( "osc_pitch", frequency ); 207 | } 208 | 209 | public void onStartTrackingTouch( SeekBar seekBar ) {} 210 | 211 | public void onStopTrackingTouch( SeekBar seekBar ) {} 212 | } ); 213 | 214 | FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); 215 | if ( fab != null ) { 216 | fab.setOnClickListener(new View.OnClickListener() { 217 | @Override 218 | public void onClick(View view) { 219 | Intent i = new Intent(Intent.ACTION_SEND); 220 | i.setType("message/rfc822"); 221 | i.putExtra(Intent.EXTRA_EMAIL , new String[]{"contact@deviantdev.com"}); 222 | i.putExtra( Intent.EXTRA_SUBJECT, "Mail to the Author..."); 223 | i.putExtra(Intent.EXTRA_TEXT , "Thanks for all the fish!"); 224 | try { 225 | startActivity(Intent.createChooser(i, "Send mail...")); 226 | } catch (android.content.ActivityNotFoundException ex) { 227 | Toast.makeText(MainActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show(); 228 | } 229 | } 230 | }); 231 | } 232 | } 233 | 234 | /** 235 | * Trigger a native Android toast message. 236 | * @param text 237 | */ 238 | private void toast(final String text) { 239 | runOnUiThread(new Runnable() { 240 | @Override 241 | public void run() { 242 | Toast toast = Toast.makeText(getApplicationContext(), "", Toast.LENGTH_SHORT); 243 | toast.setText(TAG + ": " + text); 244 | toast.show(); 245 | } 246 | }); 247 | } 248 | } -------------------------------------------------------------------------------- /app/src/main/java/com/deviantdev/pdsampleproject/PDSampleProjectApplication.java: -------------------------------------------------------------------------------- 1 | package com.deviantdev.pdsampleproject; 2 | 3 | import android.app.Application; 4 | import android.content.res.Configuration; 5 | import android.content.res.Resources; 6 | 7 | import java.util.Locale; 8 | 9 | /** 10 | * App entry point to define some basic behaviour. 11 | */ 12 | public class PDSampleProjectApplication extends Application { 13 | 14 | @Override 15 | public void onCreate() { 16 | initLanguageDebugMode("en"); 17 | super.onCreate(); 18 | } 19 | 20 | /** 21 | * Forces the app to use a specific language for development and debugging purposes. 22 | * @param language ISO 639 alpha-2 or alpha-3 language code. @see Locale 23 | */ 24 | private void initLanguageDebugMode(String language) { 25 | Locale locale = new Locale(language); 26 | Locale.setDefault(locale); 27 | 28 | Configuration config = new Configuration(); 29 | config.setLocale(locale); 30 | 31 | Resources res = getApplicationContext().getResources(); 32 | res.updateConfiguration(config, res.getDisplayMetrics()); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 13 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/res/layout/content_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 25 | 26 | 31 | 32 | 38 | 39 | 44 | 45 | 46 | 51 | 52 | 58 | 59 | 64 | 65 | 66 | 72 | 73 |