SpinCAD Designer - the OutputCADBlock

Software questions and issues with the FV-1

Moderator: frank

Post Reply
Digital Larry
Posts: 338
Joined: Mon Nov 12, 2012 1:12 pm
Contact:

SpinCAD Designer - the OutputCADBlock

Post by Digital Larry »

This is the first SpinCADBlock class I'm showing which actually generates code.

There are some internal parameters, lGain and rGain, which will eventually be adjustable using a popup control panel.

Down in the generateCode() method, you'll see that I query the "Input 1" pin to see if it has a connection. If it doesn't have a connection, that call will return "null". If it DOES have a connection, then I query the pin to see what register has been associated with this pin (which is set by the previous block's generateCode() method. Then I read the register, scale it by the gain value, and write that out to DACL or DACR depending on which Input Pin it was.

There is some extra code in there that verifies that the input register is within an acceptable range. Right now I'm not completely sure that it's necessary.

Code: Select all

/* SpinCAD Designer - DSP Development Tool for the Spin FV-1 
 * Copyright (C)2013 - Gary Worsham 
 * Based on ElmGen by Andrew Kilpatrick 
 * 
 *   This program is free software: you can redistribute it and/or modify 
 *   it under the terms of the GNU General Public License as published by 
 *   the Free Software Foundation, either version 3 of the License, or 
 *   (at your option) any later version. 
 * 
 *   This program is distributed in the hope that it will be useful, 
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *   GNU General Public License for more details. 
 * 
 *   You should have received a copy of the GNU General Public License 
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 *     
 */ 

package com.holycityaudio.SpinCAD.CADBlocks;

import java.awt.Color;
import java.util.Map;

import com.holycityaudio.SpinCAD.SpinCADBlock;
import com.holycityaudio.SpinCAD.SpinCADPin;
import com.holycityaudio.SpinCAD.fxblocks.basic.SpinFXBlock;

public class OutputCADBlock extends SpinCADBlock{

	/**
	 * 
	 */
	private static final long serialVersionUID = -2094768928842616450L;
	/**
	 * 
	 */
	static double lGain = 1.0;
	static double rGain = 1.0;
	
	public OutputCADBlock(int x, int y) {
		super(x, y);
		addInputPin(this);
		addInputPin(this);
		setName("Output");
		setBorderColor(Color.darkGray);
	}

	public void generateCode(SpinFXBlock eP) {
		System.out.println("Output codegen!");
      // look to see if there is a pin called "Input 1"
		SpinCADPin p = getPin("Input 1").getPinConnection();
		if (p != null) {
      // if there's an "Input 1" pin, request its register value
			int i = p.getRegister();
			if( (i >= 32 && i <= 64) || i == ADCR || i == ADCL) {
				eP.readRegister(i,lGain);
				eP.writeRegister(DACL, 0.0);
			}			
		}

   // look to see if there is a pin called "Input 2"
		 p = getPin("Input 2").getPinConnection();
		if (p != null) {
   // if there's an "Input 2" pin, request its register value
			int i = p.getRegister();
			if(( i >= 32 && i <= 64) || i == ADCR || i == ADCL) {
				eP.readRegister(i,rGain);
				eP.writeRegister(DACR, 0.0);
			}
		}
	}
Post Reply