Example #1
0
/* Routine was patched by Hiroaki Morimoto, revised 2003/08/15.
   Rewritten by DPL 2004/05/16 to be more understandable.
   octaveCode returns octave adjustments in the order
   [absolute or =],[relative] */
void checkOctave(voice_index voice, Char *note)
{
  Char code;

  code = octaveCode(note);
  if (code == '=') {
    setOctave(voice);
    removeOctaveCode(code, note);
  }
  if (octave(voice) == blank)
    return;
  code = octaveCode(note);
  if (isdigit(code)) {
    resetOctave(voice);
    return;
  }
  while (code == '+' || code == '-') {
    newOctave(voice, code);
    removeOctaveCode(code, note);
    code = octaveCode(note);
  }
  if (code != ' ')
    error3(voice, "You may have only one absolute octave assignment");
  insertOctaveCode(octave(voice), note);
  checkRange(voice, note);
  resetOctave(voice);
}
Example #2
0
Pyramid::Pyramid(const Image &inputImage, const double inputSigma, const int octaveCount, const double levelCount)
{
    Image levelImage = inputImage;

    double levelSigma = inputSigma;
    Image internalImage = levelImage.gaussFilter(sqrt(inputSigma * inputSigma - 0.5 * 0.5));

    int octavsCount = log2f(std::min(inputImage.getHeight(),inputImage.getWidth())/50);

    for(int octaveNumber = 0; octaveNumber < octavsCount; octaveNumber++) {
        PyramidOctave octave(octaveNumber);
        levelSigma = inputSigma;

        if(octaveNumber > 0) {
            internalImage.copy(getOctave(octaveNumber-1).getLevel(levelCount-3).getImage());
            internalImage.changeSize(qRound((double)internalImage.getWidth() / 2.0), qRound((double)internalImage.getHeight() / 2.0));
        }
        for(int levelNumber = 0; levelNumber < levelCount + 2; levelNumber++) {
            if(levelNumber == 0 ) {
                PyramidLevel level(internalImage,levelSigma,levelNumber);
                octave.addLevel(level);
            } else {
                double tempSigma;
                levelSigma = inputSigma * pow(pow(2.0, 1.0 / (levelCount-1)), levelNumber);
                internalImage.copy(octave.getLevel(levelNumber-1).getImage());
                tempSigma = sqrt(levelSigma * levelSigma - octave.getLevel(levelNumber-1).getSigma() * octave.getLevel(levelNumber-1).getSigma());
                //printf("temp sigma %lf\n", tempSigma);
                PyramidLevel level(internalImage.gaussFilter(tempSigma),levelSigma,levelNumber);
                octave.addLevel(level);
            }

        }
        addOctave(octave);
    }
}
Example #3
0
//---------------------------------------------------------------------------------------
MidiPitch FPitch::to_midi_pitch()
{
    MidiPitch nMidi = MidiPitch( (octave()+1) * 12 );

    switch( int(to_diatonic_pitch()) % 7)
    {
        case 0:  //si
            nMidi = nMidi + 11;
            break;
        case 1:  //do
            //nothing to add. The value is ok
            break;
        case 2:  //re
            nMidi = nMidi + 2;
            break;
        case 3:  //mi
            nMidi = nMidi + 4;
            break;
        case 4:  //fa
            nMidi = nMidi + 5;
            break;
        case 5:  //sol
            nMidi = nMidi + 7;
            break;
        case 6:  //la
            nMidi = nMidi + 9;
            break;
    }

    return nMidi + num_accidentals();

}
Example #4
0
static void generate(void) {
    srand(time(NULL));
    y=new2d();
    z=new2d();
    for(int a=1,t=2; t<=(SZ-1)/4; a*=2,t*=2)
        octave(a,t);
    del2d(y);
    save("land.dat");
    del2d(z);
}
Example #5
0
//---------------------------------------------------------------------------------------
FPitch DiatonicPitch::to_FPitch(EKeySignature nKey)
{
    // Get the accidentals implied by the key signature.

    // Each element of the array nAccidentals refers to one note: 0=Do, 1=Re,
    // 2=Mi, 3=Fa, ... , 6=Si and its value can be one of: 0=no accidental,
    // -1 = a flat, 1 = a sharp
    int nAccidentals[7];
    KeyUtilities::get_accidentals_for_key(nKey, nAccidentals);

    int nStep = step();
    return FPitch(nStep, octave(), nAccidentals[nStep]);
}
Example #6
0
//---------------------------------------------------------------------------------------
string DiatonicPitch::get_ldp_name()
{
    // Returns the LDP note name (without accidentals). For example,
    // pitch 29 will return "c4".

    if (is_valid())
        return m_sNoteName[step()] + m_sOctave[octave()];
    else
    {
        LOMSE_LOG_ERROR("Operation on non-valid DiatonicPitch %d", m_dp);
        return "*";
        //throw runtime_error("Operation on non-valid DiatonicPitch");
    }
}
Example #7
0
//---------------------------------------------------------------------------------------
string FPitch::to_rel_ldp_name(EKeySignature nKey)
{
    // The note LDP name, relative to received key signature, is returned.
    // For instace F4 sharp in C major will return "+f4" but in D major
    // will return "f4" as the accidental is implied by the key signature

    if (m_fp < 0)
        return "*";

    // Get the accidentals implied by the key signature.
    // Each element of the array refers to one note: 0=Do, 1=Re, 2=Mi, 3=Fa, ... , 6=Si
    // and its value can be one of: 0=no accidental, -1 = a flat, 1 = a sharp
    int nAccidentals[7];
    KeyUtilities::get_accidentals_for_key(nKey, nAccidentals);

    //compute note accidentals
    string sAnswer;
    int nAbsAcc = num_accidentals();
    switch(nAbsAcc)
    {
        case -2: sAnswer ="--"; break;
        case -1: sAnswer ="-"; break;
        case 0:  sAnswer =""; break;
        case 1:  sAnswer ="+"; break;
        case 2:  sAnswer ="x"; break;
        default:
            sAnswer = "";
    }

    //change note accidentals to take key into account
    int nStep = step();
    if (nAccidentals[nStep] != 0)
    {
        if (nAbsAcc == nAccidentals[nStep])
            sAnswer = "";   //replace note accidental by key accidental
        else if (nAbsAcc == 0)
            sAnswer = "=";  //force a natural
        //else
            //leave note accidentals
    }

    // add step letter and octave number
    sAnswer += m_sNoteName[nStep];
    sAnswer += m_sOctave[octave()];

    return sAnswer;
}
Example #8
0
Array< double, 2 > generateNoise( Vector2ui size, unsigned int seed, unsigned int octaves, double dropoff, bool tile ) {
	// Initialize the noise
	Array< double, 2 > noise( size.x, size.y );
	for( unsigned int x = 0; x < size.x; ++x ) {
		for( unsigned int y = 0; y < size.y; ++y ) {
			noise[ x ][ y ] = 0;
		}
	}

	// Loop through the octaves
	double scaling_x = 1;
	double scaling_y = 1;
	double scale_factor_x = pow( static_cast< double >( size.x ), 1. / static_cast< double >( octaves - 1 ) );
	double scale_factor_y = pow( static_cast< double >( size.y ), 1. / static_cast< double >( octaves - 1 ) );
	for( unsigned int i = 0; i < octaves; ++i ) {
		Array< double, 2 > octave( size.x, size.y );

		// Untiled octave
		if( !tile ) {
			octave = generateNoiseOctaveUntiled( size, seed, scaling_x, scaling_y );
		}

		// Tiled octave
		else {
			octave = generateNoiseOctaveTiled( size, seed, scaling_x, scaling_y );
		}

		// Combine octaves
		for( unsigned int x = 0; x < size.x; ++x ) {
			for( unsigned int y = 0; y < size.y; ++y ) {
				noise[ x ][ y ] = noise[ x ][ y ] * dropoff + octave[ x ][ y ];
			}
		}

		// Update octave parameters
		scaling_x *= scale_factor_x;
		scaling_y *= scale_factor_y;
	}

	// Normalize the noise
	noise = normalizeNoise( noise );

	return noise;
}
Example #9
0
//---------------------------------------------------------------------------------------
string FPitch::to_abs_ldp_name()
{
    // The absolute LDP note name is returned
    // If note is invalid (more than two accidentals) returns empty string

    string sAnswer;
    switch(num_accidentals()) {
        case -2: sAnswer ="--"; break;
        case -1: sAnswer ="-"; break;
        case 0:  sAnswer =""; break;
        case 1:  sAnswer ="+"; break;
        case 2:  sAnswer ="x"; break;
        default:
            return "";
    }
    sAnswer += m_sNoteName[step()];
    sAnswer += m_sOctave[octave()];
    return sAnswer;
}
float PianoKeyBoard::getBlackKeyOffset(int note)
{
    float offset(0) ;
	float space(0) ;
	int whiteKeyCount(0) ;
	int blackKeyCount(0) ;
	int octaveNote = octave(note) ;
    
	for ( int i=0; i<octaveNote; ++i )
	{
		if ( is_blackkey(i))
		{
			++blackKeyCount ;
		}
		else
		{
			++whiteKeyCount ;
		}
	}
    
	if ( octaveNote < 5 )
	{
		space = whiteKeyWidth_ - blackKeyWidth_ * 2 / 3 ;
		offset =  space * whiteKeyCount + blackKeyWidth_ * blackKeyCount ;
		offset -= whiteKeyWidth_ * (whiteKeyCount - 1) ;
	}
	else
	{
		space = whiteKeyWidth_ - blackKeyWidth_ * 3 / 4 ;
		whiteKeyCount -= 3 ;
		blackKeyCount -= 2 ;
		offset =  space * whiteKeyCount + blackKeyWidth_ * blackKeyCount ;
		offset -= whiteKeyWidth_ * (whiteKeyCount - 1) ;
	}
    
	if ( offset < 0 )
	{
		assert(false) ;
	}
    
	return offset ;
}
Example #11
0
Array< double, 2 > generateNoiseOctaveUntiled( Vector2ui size, unsigned int seed, double scaling_x, double scaling_y ) {
	// Create the octave
	Array< double, 2 > octave( size.x, size.y );
	for( unsigned int x = 0; x < size.x; ++x ) {
		for( unsigned int y = 0; y < size.y; ++y ) {
			// Recalculate the position
			double x_scaled = static_cast< double >( x ) / scaling_x;
			double y_scaled = static_cast< double >( y ) / scaling_y;

			// Calculate the sides
			unsigned int left = static_cast< unsigned int >( floor( x_scaled ) );
			unsigned int right = static_cast< unsigned int >( ceil( x_scaled ) );
			unsigned int top = static_cast< unsigned int >( floor( y_scaled ) );
			unsigned int bottom = static_cast< unsigned int >( ceil( y_scaled ) );

			// Calculate interpolation
			double x_interp = x_scaled - floor( x_scaled );
			double y_interp = y_scaled - floor( y_scaled );
			double t_x = x_interp * x_interp * ( 3 - 2 * x_interp );
			double t_y = y_interp * y_interp * ( 3 - 2 * y_interp );

			// Calculate the side values
			double topleft = noiseFunc2D( seed, left, top );
			double topright = noiseFunc2D( seed, right, top );
			double bottomleft = noiseFunc2D( seed, left, bottom );
			double bottomright = noiseFunc2D( seed, right, bottom );

			// Interpolate down to one value
			double left_value = ( 1 - t_y ) * topleft + t_y * bottomleft;
			double right_value = ( 1 - t_y ) * topright + t_y * bottomright;
			double value = ( 1 - t_x ) * left_value + t_x * right_value;

			octave[ x ][ y ] = value;
		}
	}

	return octave;
}
Example #12
0
    static Fields* parseCascade(const FileNode &root, const float mins, const float maxs, const int totals, const int method)
    {
        static const char *const SC_STAGE_TYPE          = "stageType";
        static const char *const SC_BOOST               = "BOOST";
        static const char *const SC_FEATURE_TYPE        = "featureType";
        static const char *const SC_ICF                 = "ICF";
        static const char *const SC_ORIG_W              = "width";
        static const char *const SC_ORIG_H              = "height";
        static const char *const SC_FEATURE_FORMAT      = "featureFormat";
        static const char *const SC_SHRINKAGE           = "shrinkage";
        static const char *const SC_OCTAVES             = "octaves";
        static const char *const SC_OCT_SCALE           = "scale";
        static const char *const SC_OCT_WEAKS           = "weaks";
        static const char *const SC_TREES               = "trees";
        static const char *const SC_WEAK_THRESHOLD      = "treeThreshold";
        static const char *const SC_FEATURES            = "features";
        static const char *const SC_INTERNAL            = "internalNodes";
        static const char *const SC_LEAF                = "leafValues";
        static const char *const SC_F_CHANNEL           = "channel";
        static const char *const SC_F_RECT              = "rect";

        // only Ada Boost supported
        std::string stageTypeStr = (std::string)root[SC_STAGE_TYPE];
        CV_Assert(stageTypeStr == SC_BOOST);

        // only HOG-like integral channel features supported
        std::string featureTypeStr = (std::string)root[SC_FEATURE_TYPE];
        CV_Assert(featureTypeStr == SC_ICF);

        int origWidth  = (int)root[SC_ORIG_W];
        int origHeight = (int)root[SC_ORIG_H];

        std::string fformat = (std::string)root[SC_FEATURE_FORMAT];
        bool useBoxes = (fformat == "BOX");
        ushort shrinkage = cv::saturate_cast<ushort>((int)root[SC_SHRINKAGE]);

        FileNode fn = root[SC_OCTAVES];
        if (fn.empty()) return 0;

        std::vector<device::Octave>  voctaves;
        std::vector<float>   vstages;
        std::vector<device::Node>    vnodes;
        std::vector<float>   vleaves;

        FileNodeIterator it = fn.begin(), it_end = fn.end();
        for (ushort octIndex = 0; it != it_end; ++it, ++octIndex)
        {
            FileNode fns = *it;
            float scale = powf(2.f,saturate_cast<float>((int)fns[SC_OCT_SCALE]));
            bool isUPOctave = scale >= 1;

            ushort nweaks = saturate_cast<ushort>((int)fns[SC_OCT_WEAKS]);

            ushort2 size;
            size.x = cvRound(origWidth * scale);
            size.y = cvRound(origHeight * scale);

            device::Octave octave(octIndex, nweaks, shrinkage, size, scale);
            CV_Assert(octave.stages > 0);
            voctaves.push_back(octave);

            FileNode ffs = fns[SC_FEATURES];
            if (ffs.empty()) return 0;

            std::vector<cv::Rect> feature_rects;
            std::vector<int> feature_channels;

            FileNodeIterator ftrs = ffs.begin(), ftrs_end = ffs.end();
            int feature_offset = 0;
            for (; ftrs != ftrs_end; ++ftrs, ++feature_offset )
            {
                cv::FileNode ftn = (*ftrs)[SC_F_RECT];
                cv::FileNodeIterator r_it = ftn.begin();
                int x = (int)*(r_it++);
                int y = (int)*(r_it++);
                int w = (int)*(r_it++);
                int h = (int)*(r_it++);

                if (useBoxes)
                {
                    if (isUPOctave)
                    {
                        w -= x;
                        h -= y;
                    }
                }
                else
                {
                    if (!isUPOctave)
                    {
                        w += x;
                        h += y;
                    }
                }
                feature_rects.push_back(cv::Rect(x, y, w, h));
                feature_channels.push_back((int)(*ftrs)[SC_F_CHANNEL]);
            }

            fns = fns[SC_TREES];
            if (fn.empty()) return false;

            // for each stage (~ decision tree with H = 2)
            FileNodeIterator st = fns.begin(), st_end = fns.end();
            for (; st != st_end; ++st )
            {
                FileNode octfn = *st;
                float threshold = (float)octfn[SC_WEAK_THRESHOLD];
                vstages.push_back(threshold);

                FileNode intfns = octfn[SC_INTERNAL];
                FileNodeIterator inIt = intfns.begin(), inIt_end = intfns.end();
                for (; inIt != inIt_end;)
                {
                    inIt +=2;
                    int featureIdx = (int)(*(inIt++));

                    float orig_threshold = (float)(*(inIt++));
                    unsigned int th = saturate_cast<unsigned int>((int)orig_threshold);
                    cv::Rect& r = feature_rects[featureIdx];
                    uchar4 rect;
                    rect.x = saturate_cast<uchar>(r.x);
                    rect.y = saturate_cast<uchar>(r.y);
                    rect.z = saturate_cast<uchar>(r.width);
                    rect.w = saturate_cast<uchar>(r.height);

                    unsigned int channel = saturate_cast<unsigned int>(feature_channels[featureIdx]);
                    vnodes.push_back(device::Node(rect, channel, th));
                }

                intfns = octfn[SC_LEAF];
                inIt = intfns.begin(), inIt_end = intfns.end();
                for (; inIt != inIt_end; ++inIt)
                {
                    vleaves.push_back((float)(*inIt));
                }
            }
        }

        cv::Mat hoctaves(1, (int) (voctaves.size() * sizeof(device::Octave)), CV_8UC1, (uchar*)&(voctaves[0]));
        CV_Assert(!hoctaves.empty());

        cv::Mat hstages(cv::Mat(vstages).reshape(1,1));
        CV_Assert(!hstages.empty());

        cv::Mat hnodes(1, (int) (vnodes.size() * sizeof(device::Node)), CV_8UC1, (uchar*)&(vnodes[0]) );
        CV_Assert(!hnodes.empty());

        cv::Mat hleaves(cv::Mat(vleaves).reshape(1,1));
        CV_Assert(!hleaves.empty());

        Fields* fields = new Fields(mins, maxs, totals, origWidth, origHeight, shrinkage, 0,
            hoctaves, hstages, hnodes, hleaves, method);
        fields->voctaves = voctaves;
        fields->createLevels(DEFAULT_FRAME_HEIGHT, DEFAULT_FRAME_WIDTH);

        return fields;
    }
Example #13
0
bool Note::operator ==(const Note &other) const
{
    return other.id() == id() and other.octave() == octave();
}
Example #14
0
    bool fill(const FileNode &root)
    {
        // cascade properties
        static const char *const SC_STAGE_TYPE       = "stageType";
        static const char *const SC_BOOST            = "BOOST";

        static const char *const SC_FEATURE_TYPE     = "featureType";
        static const char *const SC_ICF              = "ICF";

        static const char *const SC_ORIG_W           = "width";
        static const char *const SC_ORIG_H           = "height";

        static const char *const SC_OCTAVES          = "octaves";
        static const char *const SC_TREES            = "trees";
        static const char *const SC_FEATURES         = "features";

        static const char *const SC_INTERNAL         = "internalNodes";
        static const char *const SC_LEAF             = "leafValues";

        static const char *const SC_SHRINKAGE        = "shrinkage";

        static const char *const FEATURE_FORMAT      = "featureFormat";

        // only Ada Boost supported
        std::string stageTypeStr = (string)root[SC_STAGE_TYPE];
        CV_Assert(stageTypeStr == SC_BOOST);

        std::string fformat = (string)root[FEATURE_FORMAT];
        bool useBoxes = (fformat == "BOX");

        // only HOG-like integral channel features supported
        string featureTypeStr = (string)root[SC_FEATURE_TYPE];
        CV_Assert(featureTypeStr == SC_ICF);

        origObjWidth  = (int)root[SC_ORIG_W];
        origObjHeight = (int)root[SC_ORIG_H];

        shrinkage = (int)root[SC_SHRINKAGE];

        FileNode fn = root[SC_OCTAVES];
        if (fn.empty()) return false;

        // for each octave
        FileNodeIterator it = fn.begin(), it_end = fn.end();
        for (int octIndex = 0; it != it_end; ++it, ++octIndex)
        {
            FileNode fns = *it;
            Octave octave(octIndex, cv::Size(origObjWidth, origObjHeight), fns);
            CV_Assert(octave.weaks > 0);
            octaves.push_back(octave);

            FileNode ffs = fns[SC_FEATURES];
            if (ffs.empty()) return false;

            fns = fns[SC_TREES];
            if (fn.empty()) return false;

            FileNodeIterator st = fns.begin(), st_end = fns.end();
            for (; st != st_end; ++st )
            {
                weaks.push_back(Weak(*st));

                fns = (*st)[SC_INTERNAL];
                FileNodeIterator inIt = fns.begin(), inIt_end = fns.end();
                for (; inIt != inIt_end;)
                    nodes.push_back(Node(features.size(), inIt));

                fns = (*st)[SC_LEAF];
                inIt = fns.begin(), inIt_end = fns.end();

                for (; inIt != inIt_end; ++inIt)
                    leaves.push_back((float)(*inIt));
            }

            st = ffs.begin(), st_end = ffs.end();
            for (; st != st_end; ++st )
                features.push_back(Feature(*st, useBoxes));
        }

        return true;
    }
Example #15
0
////---------------------------------------------------------------------------------------
DiatonicPitch FPitch::to_diatonic_pitch()
{
    return DiatonicPitch(step(), octave());
}
Example #16
0
Array< double, 2 > generateNoiseOctaveTiled( Vector2ui size, unsigned int seed, double scaling_x, double scaling_y ) {
	// Temporarily rescale
	Vector2ui full_size = size;
	size.x /= scaling_x;
	size.y /= scaling_y;

	// Create the octave
	Array< double, 2 > octave( size.x, size.y );
	for( unsigned int x = 0; x < size.x; ++x ) {
		for( unsigned int y = 0; y < size.y; ++y ) {
			// Recalculate the position
			double x_norm = static_cast< double >( x ) / static_cast< double >( size.x );
			double y_norm = static_cast< double >( y ) / static_cast< double >( size.y );

			// Calculate the 4D parameters
			double nx = size.x * ( 1 + cos( x_norm * ( 2 * pi ) ) ) / 2;
			double ny = size.y * ( 1 + cos( y_norm * ( 2 * pi ) ) ) / 2;
			double nu = size.x * ( 1 + sin( x_norm * ( 2 * pi ) ) ) / 2;
			double nv = size.y * ( 1 + sin( y_norm * ( 2 * pi ) ) ) / 2;

			// Calculate the sides
			unsigned int x1 = static_cast< unsigned int >( floor( nx ) );
			unsigned int x2 = static_cast< unsigned int >( ceil( nx ) );
			unsigned int y1 = static_cast< unsigned int >( floor( ny ) );
			unsigned int y2 = static_cast< unsigned int >( ceil( ny ) );
			unsigned int u1 = static_cast< unsigned int >( floor( nu ) );
			unsigned int u2 = static_cast< unsigned int >( ceil( nu ) );
			unsigned int v1 = static_cast< unsigned int >( floor( nv ) );
			unsigned int v2 = static_cast< unsigned int >( ceil( nv ) );

			// Calculate the interpolations
			double x_interp = nx - floor( nx );
			double y_interp = ny - floor( ny );
			double u_interp = nu - floor( nu );
			double v_interp = nv - floor( nv );
			double t_x = x_interp * x_interp * ( 3 - 2 * x_interp );
			double t_y = y_interp * y_interp * ( 3 - 2 * y_interp );
			double t_u = u_interp * u_interp * ( 3 - 2 * u_interp );
			double t_v = v_interp * v_interp * ( 3 - 2 * v_interp );

			// Calculate the side values
			double val_1111 = noiseFunc4D( seed, x1, y1, u1, v1 );
			double val_1112 = noiseFunc4D( seed, x1, y1, u1, v2 );
			double val_1121 = noiseFunc4D( seed, x1, y1, u2, v1 );
			double val_1122 = noiseFunc4D( seed, x1, y1, u2, v2 );
			double val_1211 = noiseFunc4D( seed, x1, y2, u1, v1 );
			double val_1212 = noiseFunc4D( seed, x1, y2, u1, v2 );
			double val_1221 = noiseFunc4D( seed, x1, y2, u2, v1 );
			double val_1222 = noiseFunc4D( seed, x1, y2, u2, v2 );
			double val_2111 = noiseFunc4D( seed, x2, y1, u1, v1 );
			double val_2112 = noiseFunc4D( seed, x2, y1, u1, v2 );
			double val_2121 = noiseFunc4D( seed, x2, y1, u2, v1 );
			double val_2122 = noiseFunc4D( seed, x2, y1, u2, v2 );
			double val_2211 = noiseFunc4D( seed, x2, y2, u1, v1 );
			double val_2212 = noiseFunc4D( seed, x2, y2, u1, v2 );
			double val_2221 = noiseFunc4D( seed, x2, y2, u2, v1 );
			double val_2222 = noiseFunc4D( seed, x2, y2, u2, v2 );

			// Interpolation over v
			double val_111 = ( 1 - t_v ) * val_1111 + t_v * val_1112;
			double val_112 = ( 1 - t_v ) * val_1121 + t_v * val_1122;
			double val_121 = ( 1 - t_v ) * val_1211 + t_v * val_1212;
			double val_122 = ( 1 - t_v ) * val_1221 + t_v * val_1222;
			double val_211 = ( 1 - t_v ) * val_2111 + t_v * val_2112;
			double val_212 = ( 1 - t_v ) * val_2121 + t_v * val_2122;
			double val_221 = ( 1 - t_v ) * val_2211 + t_v * val_2212;
			double val_222 = ( 1 - t_v ) * val_2221 + t_v * val_2222;

			// Interpolation over u
			double val_11 = ( 1 - t_u ) * val_111 + t_u * val_112;
			double val_12 = ( 1 - t_u ) * val_121 + t_u * val_122;
			double val_21 = ( 1 - t_u ) * val_211 + t_u * val_212;
			double val_22 = ( 1 - t_u ) * val_221 + t_u * val_222;

			// Interpolation over y
			double val_1 = ( 1 - t_y ) * val_11 + t_y * val_12;
			double val_2 = ( 1 - t_y ) * val_21 + t_y * val_22;

			// Interpolation over x
			double value = ( 1 - t_x ) * val_1 + t_x * val_2;

			octave[ x ][ y ] = value;
		}
	}

	// Scale the octave
	Array< double, 2 > full_octave( full_size.x, full_size.y );
	for( unsigned int x = 0; x < full_size.x; ++x ) {
		for( unsigned int y = 0; y < full_size.y; ++y ) {
			// Find the scaled down coordinates
			double x_scaled = static_cast< double >( x ) / scaling_x;
			double y_scaled = static_cast< double >( y ) / scaling_y;
			unsigned int left = static_cast< unsigned int >( floor( x_scaled ) );
			unsigned int right = static_cast< unsigned int >( ceil( x_scaled ) );
			unsigned int top = static_cast< unsigned int >( floor( y_scaled ) );
			unsigned int bottom = static_cast< unsigned int >( ceil( y_scaled ) );

			// Prevent bad coordinate access
			if( left >= size.x ) {
				left = 0;
			}
			if( right >= size.x ) {
				right = 0;
			}
			if( top >= size.y ) {
				top = 0;
			}
			if( bottom >= size.y ) {
				bottom = 0;
			}

			// Get the interpolation factors
			double x_interp = x_scaled - floor( x_scaled );
			double y_interp = y_scaled - floor( y_scaled );
			double t_x = x_interp * x_interp * ( 3. - 2. * x_interp );
			double t_y = y_interp * y_interp * ( 3. - 2. * y_interp );

			// Get the values
			double topleft_val = octave[ left ][ top ];
			double topright_val = octave[ right ][ top ];
			double bottomleft_val = octave[ left ][ bottom ];
			double bottomright_val = octave[ right ][ bottom ];

			// Interpolate down to one value
			double left_val = ( 1. - t_y ) * topleft_val + t_y * bottomleft_val;
			double right_val = ( 1. - t_y ) * topright_val + t_y * bottomright_val;
			double value = ( 1. - t_x ) * left_val + t_x * right_val;

			full_octave[ x ][ y ] = value;
		}
	}

	return full_octave;
}
Example #17
0
////---------------------------------------------------------------------------------------
FPitch FPitch::add_semitone(bool fUseSharps)
{
    // This function adds one semitone and returns the resulting pitch.
    // Step and accidentals of new note are adjusted to use one accidental at
    // maximum, of the same type as requested by fUseSharps

    // step 0   0   1   1   2   3   3   4   4   5   5   6
        //  C   C#  D   D#  E   F   F#  G   G#  A   A#  B
        //  3   4   9   10  15  20  21  26  27  32  33  38

    // step 0   1   1   2   2   3   4   4   5   5   6   6
        //  C   Db  D   Eb  E   F   Gb  G   Ab  A   Bb  B
        //  3   8   9   14  15  20  25  26  31  32  37  38


    // extract components
    int nStep = step();
    int nAcc = num_accidentals();
    int nOctave = octave();

    //Determine what type of accidentals to use for semitones: flats or sharps
    if (fUseSharps)
    {
        //Key signature is using sharps.
        //Only one accidental allowed and must be a sharp
        if (nAcc == 0)
        {
            //if no accidentals add one sharp or advance step, depending on current step
            if (nStep == 2 || nStep == 6)
                nStep++;
            else
                nAcc++;
        }
        else
        {
            if (nAcc < 0)
                //assume one flat: advance natural step
                nAcc = 0;
            else
            {
                //assume one sharp: advance to next natural step
                nStep++;
                nAcc=0;
            }
        }

        // Adjust octave
        if (nStep==7)
        {
            nStep = 0;
            nOctave++;
        }
    }
    else
    {
        //Key signature is using flats.
        //Only one accidental allowed and must be a flat
        if (nAcc == 0)
        {
            //if no accidentals advance step and, depending on new step, add one flat
            nStep++;
            if (nStep == 7) {
                nStep = 0;
                nOctave++;
            }
            else if (nStep != 3)
                nAcc--;
        }
        else
        {
            //assume one flat: remove accidentals to advance to the natural step
            nAcc=0;
        }
    }

    create(nStep, nOctave, nAcc);
    return *this;
}
Example #18
0
static void run (const gchar *name, gint nparams, const GimpParam  *param, gint *nreturn_vals, GimpParam **return_vals)
{
	static GimpParam   values[1];
	GimpPDBStatusType  status = GIMP_PDB_SUCCESS;
	GimpDrawable      *drawable;
	GimpRunMode        run_mode;

	// create working directory
	char* home = getenv("HOME");
	char dir[PATH_MAX + 1];
	strcpy ( dir, home );
	strcat ( dir, "/.gimp-octave" );
	mkdir( dir, S_IRWXU );

	run_mode = (GimpRunMode)param[0].data.d_int32;

	*return_vals  = values;
	*nreturn_vals = 1;

	values[0].type          = GIMP_PDB_STATUS;
	values[0].data.d_status = status;

	/*
	* Get drawable information...
	*/
	drawable = gimp_drawable_get (param[2].data.d_drawable);
	gimp_tile_cache_ntiles (2 * MAX (drawable->width  / gimp_tile_width () + 1 ,
					 drawable->height / gimp_tile_height () + 1));

	switch (run_mode)
	{
		case GIMP_RUN_INTERACTIVE:
			gimp_get_data (PLUG_IN_PROC, &octave_params);
			/* Reset default values show preview unmodified */

			/* initialize pixel regions and buffer */
			if (! octave_dialog (drawable))
			return;
			break;

		case GIMP_RUN_NONINTERACTIVE:
			if (nparams != 6)
			{
				status = GIMP_PDB_CALLING_ERROR;
			}
			else
			{
				reset_default();
			}
			break;

		case GIMP_RUN_WITH_LAST_VALS:
			gimp_get_data (PLUG_IN_PROC, &octave_params);
			break;

		default:
			break;
	}

	if (status == GIMP_PDB_SUCCESS)
	{
		drawable = gimp_drawable_get (param[2].data.d_drawable);

		/* here we go */
		octave (drawable);

		gimp_displays_flush ();

		/* set data for next use of filter */
		if (run_mode == GIMP_RUN_INTERACTIVE)
			gimp_set_data (PLUG_IN_PROC, &octave_params, sizeof (OctaveParams));

		gimp_drawable_detach(drawable);
		values[0].data.d_status = status;
	}
}