Skip to content

Commit

Permalink
First pass at the synth palette, only seems to work for the AY as yet.
Browse files Browse the repository at this point in the history
Done some refactoring to use more of the android View infrastructure.
  • Loading branch information
glastonbridge committed Sep 11, 2010
1 parent d5d8e55 commit 6beea27
Show file tree
Hide file tree
Showing 7 changed files with 310 additions and 79 deletions.
22 changes: 19 additions & 3 deletions res/layout/arranger.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<org.isophonics.scanvox.Arranger
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/editlayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center" >
<org.isophonics.scanvox.Arranger
android:id="@+id/arranger"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
</org.isophonics.scanvox.Arranger>
/>
<org.isophonics.scanvox.Dashboard
android:id="@+id/dashboard"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
<ListView
android:id="@+id/synthpalette"
android:layout_width="250dip"
android:layout_centerInParent="true"
android:layout_height="wrap_content"
android:visibility="invisible" />
</RelativeLayout>
71 changes: 41 additions & 30 deletions src/org/isophonics/scanvox/Arranger.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public class GridDimensions {
protected GridDimensions gridDimensions = new GridDimensions();
private int height = 320; // will be updated later
private Dashboard dashboard;
private SoundManager soundManager;
SoundManager soundManager;

protected Arrangement arrangement=new Arrangement(0);

Expand All @@ -91,8 +91,12 @@ public Arranger(Context c) {
init();
}

public void setDashboard(Dashboard d) {
dashboard = d;
dashboard.init(this, refreshHandler, ScanVox.myMappedSynths);
}

private void init() {
dashboard = new Dashboard(getContext(),refreshHandler);

backgroundPaint = new Paint();
timeDivisionPaint = new Paint();
Expand All @@ -108,7 +112,6 @@ private void init() {
gridDimensions.x = getWidth()/arrangement.length;
height = getHeight();

invalidate();
}

/**
Expand Down Expand Up @@ -154,7 +157,7 @@ public boolean equals(Object o) {
}
}

private SoundView draggingSoundView = null;
SoundView draggingSoundView = null;
private float soundBeingMovedX, soundBeingMovedY;
/** The distance between the top left corner and where you're actually touching */
private float soundBeingMovedHandleX, soundBeingMovedHandleY;
Expand Down Expand Up @@ -220,15 +223,27 @@ private void drawRow (Canvas c, Arrangement.Row r, int rowNum) {
((SoundView)soundViews.get(s)).draw(c);
} else {
SoundView newSoundView = new SoundView(getContext(), s, gridDimensions);
// measuring is done here, as sounds are added in an ad-hoc way
newSoundView.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
newSoundView.layout((int)leftIndex,(int)topIndex,(int)rightIndex,(int)bottomIndex);
soundViews.put(s, newSoundView);
newSoundView.draw(c);
}
//drawSound(c,s, s.getStartTime()*gridDimensions.x, rowNum*gridDimensions.y);
}
}

//@Override
/*protected void onMeasure(int width, int height) {
super.onMeasure(width, height);
dashboard.measure(getMeasuredWidth(), getMeasuredHeight());
}*/

//@Override
/*protected void onLayout(boolean changed,int l,int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
dashboard.layout(l, t, r, b);
}*/

private RefreshHandler refreshHandler = new RefreshHandler();

class RefreshHandler extends Handler {
Expand All @@ -242,8 +257,7 @@ public void trigger() {
sendEmptyMessage(0);
}
};



private long lastUpdateTime = 0;

/**
Expand All @@ -263,6 +277,11 @@ public boolean onTouchEvent(MotionEvent event) {
return true;
lastUpdateTime = now;

if (dashboard.onTouchEvent(event)) {
invalidate();
return true;
}

if (event.getAction()==MotionEvent.ACTION_DOWN) {
if ( draggingSoundView != null ) {
// Sanity check, we should never have an action down before a previous action up
Expand All @@ -285,36 +304,28 @@ public boolean onTouchEvent(MotionEvent event) {
return true;
}
}
// DASHBOARD FUNCTIONS
int buttonId = dashboard.identifyButton((int)event.getX(), (int)event.getY());
if (buttonId != -1) {
if (buttonId == Dashboard.recordId) {
if(soundManager!=null) {
if (soundManager.recording) {
soundManager.stopRecording();
dashboard.stopRecording();
} else {
startRecording();
}
}
} else if (buttonId == Dashboard.trashId) {
Toast.makeText(getContext(),"Drag a sound onto the trashcan to delete it.",Toast.LENGTH_SHORT).show();
}
}
} else if (event.getAction()==MotionEvent.ACTION_MOVE) {
soundBeingMovedX = event.getX() - soundBeingMovedHandleX;
soundBeingMovedY = event.getY() - soundBeingMovedHandleY;
invalidate();
return true;
} else if (event.getAction()==MotionEvent.ACTION_UP && draggingSoundView != null) {
int buttonId = dashboard.identifyButton((int)event.getX(), (int)event.getY());
if (buttonId == Dashboard.trashId) {
soundManager.removeSound(draggingSoundView.sound.id);
draggingSoundView = null;
invalidate();
return true;
if (dashboard.draggingPaint!=null) {
MappedSynth newSynth = null;
for (MappedSynth i : ScanVox.myMappedSynths) {
if (i.getLabel().equals(dashboard.draggingPaint.getText().toString())) {
newSynth = i;
break;
}
}
if (newSynth!=null) {
PlayingSound mySound = draggingSoundView.sound.id;
mySound.synth = newSynth;
soundManager.removeSynth(mySound);
soundManager.addSynth(mySound);
dashboard.draggingPaint = null;
}
}

if (!addSoundAt(event.getX() - soundBeingMovedHandleX, event.getY() - soundBeingMovedHandleY, draggingSoundView.sound)
&& !soundBeingMovedOldHome.add(draggingSoundView.sound))
Log.e(TAG,"Could not replace a sound where it used to belong in an arrangement.");
Expand Down
Loading

0 comments on commit 6beea27

Please sign in to comment.