Esempio n. 1
0
bool hgeGUIListbox::KeyClick(int key, int chr)
{
    switch(key) {
    case HGEK_DOWN:
        if(nSelectedItem < nItems-1) {
            nSelectedItem++;
            if(nSelectedItem > nTopItem+GetNumRows()-1) {
                nTopItem=nSelectedItem-GetNumRows()+1;
            }
            return true;
        }
        break;

    case HGEK_UP:
        if(nSelectedItem > 0) {
            nSelectedItem--;
            if(nSelectedItem < nTopItem) {
                nTopItem=nSelectedItem;
            }
            return true;
        }
        break;
    }
    return false;
}
 void WidgetTableWidget::RemoveColumns( int column, int num_columns )
 {
     int columns = GetNumColumns();
     {
         DirtyLock guard_dirty(this);
         {
             for( int j=column; j < column+num_columns; ++j )
             {
                 for( int i=0; i < GetNumRows(); ++i )
                 {
                     if( Settled( j,i ) ) Retrieve( j,i );
                 }
             }
         }
         {
             for( int j=column; j < columns - num_columns; ++j )
             {
                 for( int i=0; i < GetNumRows(); ++i )
                 {
                     if( Settled( j+num_columns, i ) )
                     {
                         Cell *pcell = _settlers.Find( Pos( j+num_columns, i ) );
                         Widget *client = pcell->_settler;
                         Rect::Alignment align = pcell->_alignment;
                         Retrieve( pcell->_settler );
                         Insert( j,i,client,align );
                     }
                 }
             }
         }
     }
     TableWidget::RemoveColumns( column,num_columns );	
 }
Esempio n. 3
0
bool CPattern::operator== (const CPattern &other) const
//-----------------------------------------------------
{
	if(GetNumRows() != other.GetNumRows()
		|| GetNumChannels() != other.GetNumChannels()
		|| GetOverrideSignature() != other.GetOverrideSignature()
		|| GetRowsPerBeat() != other.GetRowsPerBeat()
		|| GetRowsPerMeasure() != other.GetRowsPerMeasure())
		return false;
	if(m_ModCommands == nullptr || other.m_ModCommands == nullptr)
		return m_ModCommands == other.m_ModCommands;

	auto i = GetNumRows() * GetNumChannels();
	auto m1 = m_ModCommands, m2 = other.m_ModCommands;
	while(i--)
	{
		if(*m1 != *m2)
		{
			return false;
		}
		m1++;
		m2++;
	}
	return true;
}
Esempio n. 4
0
    void NDMask::MaskSection(const std::vector<size_t>& sectionOffset, const NDShape& sectionShape)
    {
        // TODO: Implement batching of masking operation for masks residing on GPUs to avoid making
        // GPU invocations for each MaskSection call.

        if (sectionOffset.size() > m_maskShape.NumAxes())
            LogicError("NDMask::MaskSection: The sectionOffset cannot have dimensionality higher than the number of axes of 'this' mask");

        if (sectionShape.NumAxes() > m_maskShape.NumAxes())
            LogicError("NDMask::MaskSection: The section shape cannot have an axes count higher than the number of axes of 'this' mask");

        std::vector<size_t> offset(m_maskShape.NumAxes(), 0);
        for (size_t i = 0; i < sectionOffset.size(); ++i)
            offset[i] = sectionOffset[i];

        NDShape shape = sectionShape.AppendShape(NDShape(m_maskShape.NumAxes() - sectionShape.NumAxes(), NDShape::InferredDimension));

        auto maskMatrix = GetMatrix();
        size_t rowOffset = offset[0];
        size_t colOffset = offset[1];
        size_t sliceRowLength = (shape[0] != NDShape::InferredDimension) ? shape[0] : (maskMatrix->GetNumRows() - rowOffset);
        size_t sliceColLength = (shape[1] != NDShape::InferredDimension) ? shape[1] : (maskMatrix->GetNumCols() - colOffset);
        if ((rowOffset == 0) && (sliceRowLength == maskMatrix->GetNumRows()))
            maskMatrix->ColumnSlice(colOffset, sliceColLength).SetValue(0);
        else
        {
            // Since Matrix does not support strides in the row dimension, we will need to create separate slices for each column
            for (size_t i = colOffset; i < (colOffset + sliceColLength); ++i)
            {
                auto column = maskMatrix->ColumnSlice(i, 1);
                column.Reshape(1, maskMatrix->GetNumRows());
                column.ColumnSlice(rowOffset, sliceRowLength).SetValue(0);
            }
        }
    }
Esempio n. 5
0
bool hgeGUIListbox::MouseWheel(int nNotches)
{
	nTopItem-=nNotches;
	if(nTopItem<0) nTopItem=0;
	if(nTopItem>GetNumItems()-GetNumRows()) nTopItem=GetNumItems()-GetNumRows();

	return true;
}
Esempio n. 6
0
bool hgeGUIListbox::MouseWheel(const int n_notches) {
    top_item_ -= n_notches;
    if (top_item_ < 0) {
        top_item_ = 0;
    }
    if (top_item_ > GetNumItems() - GetNumRows()) {
        top_item_ = GetNumItems() - GetNumRows();
    }

    return true;
}
Esempio n. 7
0
bool NoteData::IsRangeEmpty( int track, int iIndexBegin, int iIndexEnd ) const
{
	ASSERT( track<m_iNumTracks );
	
	CLAMP( iIndexBegin, 0, GetNumRows()-1 );
	CLAMP( iIndexEnd, 0, GetNumRows()-1 );

	for( int i=iIndexBegin; i<=iIndexEnd; i++ )
		if( GetTapNoteX(track,i).type != TapNote::empty )
			return false;
	return true;
}
Esempio n. 8
0
bool MatrixMarketReader<FloatType>::MMReadHeader( const std::string &filename )
{
    FILE *mm_file = ::fopen( filename.c_str( ), "r" );
    if( mm_file == NULL )
    {
        printf( "Cannot Open Matrix-Market File !\n" );
        return 1;
    }

    if ( MMReadHeader( mm_file ) )
    {
        printf ("Matrix not supported !\n");
        return 2;
    }

    // If symmetric MM stored file, double the reported size
    if( mm_is_symmetric( Typecode ) )
        nNZ <<= 1;

    ::fclose( mm_file );

    std::clog << "Matrix: " << filename << " [nRow: " << GetNumRows( ) << "] [nCol: " << GetNumCols( ) << "] [nNZ: " << GetNumNonZeroes( ) << "]" << std::endl;

    return 0;
}
//d= max(log(s))- log(s)
void DMAlignedOptimalScore::convertScoreToDistance()
{
	/*
	ReplaceZeroWithTinyValue();
	 for (int i=1; i<GetNumRows(); ++i) 
	{
        for (int j=0; j<i; ++j) 
		{
            m_Array[i][j] = log(m_Array[i][j]);
            m_Array[j][i] = m_Array[i][j];
        }
    }*/	
	double max = GetMaxEntry();
    if (FRACTIONAL_EXTRA_OFFSET > 0) {
        max += (FRACTIONAL_EXTRA_OFFSET*max > 1) ? FRACTIONAL_EXTRA_OFFSET*max : 1;
    }
    for (int i=1; i<GetNumRows(); ++i) 
	{
        for (int j=0; j<i; ++j) 
		{
            m_Array[i][j] = (max - m_Array[i][j]);
            m_Array[j][i] = m_Array[i][j];
        }
    }	
}
Esempio n. 10
0
void NoteData::PruneUnusedAttacksFromMap()
{
	// Add all used AttackNote index values to a map.
	set<unsigned> setUsedIndices;

	int num_rows = GetNumRows();
	for( int t=0; t<m_iNumTracks; t++ )
	{
		for( int r=0; r<num_rows; r++ )
		{
			TapNote tn = GetTapNote(t, r);
			if( tn.type == TapNote::attack )
				setUsedIndices.insert( tn.attackIndex );
		}
	}

	// Remove all items from m_AttackMap that don't have corresponding
	// TapNotes in use.
	for( unsigned i=0; i<MAX_NUM_ATTACKS; i++ )
	{
		bool bInAttackMap = m_AttackMap.find(i) != m_AttackMap.end();
		bool bActuallyUsed = setUsedIndices.find(i) != setUsedIndices.end();

		if( bActuallyUsed && !bInAttackMap )
			ASSERT(0);	// something earlier than us didn't enforce consistency 

		if( bInAttackMap && !bActuallyUsed )
			m_AttackMap.erase( i );
	}
}
int NoteDataWithScoring::GetNumNWithScore( TapNoteScore tns, int MinTaps, const float fStartBeat, float fEndBeat ) const
{
	if( fEndBeat == -1 )
		fEndBeat = GetNumBeats();

	int iStartIndex = BeatToNoteRow( fStartBeat );
	int iEndIndex = BeatToNoteRow( fEndBeat );

	iStartIndex = max( iStartIndex, 0 );
	iEndIndex = min( iEndIndex, GetNumRows()-1 );

	int iNumSuccessfulDoubles = 0;
	for( int i=iStartIndex; i<=iEndIndex; i++ )
	{
		int iNumNotesThisIndex = 0;
		TapNoteScore	minTapNoteScore = TNS_MARVELOUS;
		for( int t=0; t<GetNumTracks(); t++ )
		{
			switch( GetTapNote(t, i).type )
			{
			case TapNote::tap:		
			case TapNote::hold_head: 
				iNumNotesThisIndex++;
				minTapNoteScore = min( minTapNoteScore, GetTapNoteScore(t, i) );
			}
		}
		if( iNumNotesThisIndex >= MinTaps && minTapNoteScore >= tns )
			iNumSuccessfulDoubles++;
	}
	
	return iNumSuccessfulDoubles;
}
Esempio n. 12
0
int NoteData::GetNumN( int MinTaps, float fStartBeat, float fEndBeat ) const
{
	if( fEndBeat == -1 )
		fEndBeat = GetNumBeats();

	int iStartIndex = BeatToNoteRow( fStartBeat );
	int iEndIndex = BeatToNoteRow( fEndBeat );

	/* Clamp to known-good ranges. */
	iStartIndex = max( iStartIndex, 0 );
	iEndIndex = min( iEndIndex, GetNumRows()-1 );

	int iNum = 0;
	for( int i=iStartIndex; i<=iEndIndex; i++ )
	{
		int iNumNotesThisIndex = 0;
		for( int t=0; t<m_iNumTracks; t++ )
		{
			TapNote tn = GetTapNoteX(t, i);
			if( tn.type != TapNote::mine  &&  tn.type != TapNote::empty )	// mines don't count
				iNumNotesThisIndex++;
		}
		if( iNumNotesThisIndex >= MinTaps )
			iNum++;
	}
	
	return iNum;
}
Esempio n. 13
0
int NoteData::GetNumTapNotes( float fStartBeat, float fEndBeat ) const
{
	int iNumNotes = 0;

	if( fEndBeat == -1 )
		fEndBeat = GetNumBeats();

	int iStartIndex = BeatToNoteRow( fStartBeat );
	int iEndIndex = BeatToNoteRow( fEndBeat );

	/* Clamp to known-good ranges. */
	iStartIndex = max( iStartIndex, 0 );
	iEndIndex = min( iEndIndex, GetNumRows()-1 );
	
	for( int t=0; t<m_iNumTracks; t++ )
	{
		for( int i=iStartIndex; i<=iEndIndex; i++ )
		{
			TapNote tn = GetTapNoteX(t, i);
			if( tn.type != TapNote::empty  &&  tn.type != TapNote::mine )
				iNumNotes++;
		}
	}
	
	return iNumNotes;
}
Esempio n. 14
0
int NoteData::GetNumHands( float fStartBeat, float fEndBeat ) const
{
	/* Count the number of times you have to use your hands.  This includes
	 * three taps at the same time, a tap while two hold notes are being held,
	 * etc.  Only count rows that have at least one tap note (hold heads count).
	 * Otherwise, every row of hold notes counts, so three simultaneous hold
	 * notes will count as hundreds of "hands". */
	if( fEndBeat == -1 )
		fEndBeat = GetNumBeats();

	int iStartIndex = BeatToNoteRow( fStartBeat );
	int iEndIndex = BeatToNoteRow( fEndBeat );

	/* Clamp to known-good ranges. */
	iStartIndex = max( iStartIndex, 0 );
	iEndIndex = min( iEndIndex, GetNumRows()-1 );

	int iNum = 0;
	for( int i=iStartIndex; i<=iEndIndex; i++ )
	{
		if( !RowNeedsHands(i) )
			continue;

		iNum++;
	}

	return iNum;
}
Esempio n. 15
0
int* ChCOOMatrix::GetCOO_ColIndexArray() const {
    auto der_ptr = const_cast<ChCOOMatrix*>(this);
    auto base_ptr = static_cast<ChCSMatrix*>(der_ptr);

    auto array_length = GetTrailingIndexLength();
    der_ptr->colIndex.resize(array_length);
    auto one_index_offset = one_indexed ? 1 : 0;

    if (base_ptr->IsRowMajor()) {
        // in this case, the underlaying CSR3 matrix has a full-length col index array
        // that has just to be eventually adapted to comply with the one-indexed array format
        auto col_array = base_ptr->GetCS_TrailingIndexArray();

        if (!one_indexed)
            return col_array;

        for (auto el_sel = 0; el_sel < array_length; ++el_sel) {
            der_ptr->colIndex[el_sel] = col_array[el_sel] + one_index_offset;
        }

    } else {
        // in this case, the underlaying CSR3 matrix has a compressed col index array
        // so a full-length array has to be created, expanding the CSR one
        auto col_array = base_ptr->GetCS_LeadingIndexArray();

        for (auto col_sel = 0; col_sel < GetNumRows(); ++col_sel) {
            for (auto el_sel = col_array[col_sel]; el_sel < col_array[col_sel + 1]; ++el_sel) {
                der_ptr->colIndex[el_sel] = col_sel + one_index_offset;
            }
        }
    }

    return const_cast<int*>(colIndex.data());
}
Esempio n. 16
0
void DiagonalBlockSparseMatrix::Solve(const Eigen::MatrixXd& rhs, Eigen::MatrixXd& sol)
{
	int numRows = GetNumRows();
	int numCols = GetNumCols();
	LOG_IF(FATAL, numRows != numCols) << "DiagonalBlockSparseMatrix is not a square matrix and noninvertible.";
	int rhsCols = rhs.cols();
	int rhsRows = rhs.rows();
	LOG_IF(FATAL, numCols != rhsRows) << "DiagonalBlockSparseMatrix and right hand side matrix are of different dimensions.";

	sol.resize(rhsRows, rhsCols);
	int numUntilLast = 0;
	int numDiagElements = static_cast<int>(mDiagElements.size());
	for (int i = 0; i < numDiagElements; ++i)
	{
		int numColsElement = mDiagElements[i].GetNumCols();	
		Eigen::MatrixXd partSol(numColsElement, rhsCols);
		Eigen::MatrixXd partRhs = rhs.block(numUntilLast, 0, numColsElement, rhsCols);
		
#if LLT_SOLVE
		mDiagElements[i].LltSolve(partRhs, partSol);
#else
		mDiagElements[i].ConjugateGradientSolve(partRhs, partSol);
#endif
		sol.block(numUntilLast, 0, numColsElement, rhsCols) = partSol;
		numUntilLast += numColsElement;
	}
}
// Returns the control's inherent size, based on the length of the input field and the current font size.
bool ElementFormControlTextArea::GetIntrinsicDimensions(Rocket::Core::Vector2f& dimensions)
{
	dimensions.x = (float) (GetNumColumns() * Core::ElementUtilities::GetStringWidth(this, "m"));
	dimensions.y = (float) (GetNumRows() * Core::ElementUtilities::GetLineHeight(this));

	return true;
}
/* See NoteData::GetNumHands(). */
int NoteDataWithScoring::GetSuccessfulHands( float fStartBeat, float fEndBeat ) const
{
	if( fEndBeat == -1 )
		fEndBeat = GetNumBeats();

	int iStartIndex = BeatToNoteRow( fStartBeat );
	int iEndIndex = BeatToNoteRow( fEndBeat );

	/* Clamp to known-good ranges. */
	iStartIndex = max( iStartIndex, 0 );
	iEndIndex = min( iEndIndex, GetNumRows()-1 );

	int iNum = 0;
	for( int i=iStartIndex; i<=iEndIndex; i++ )
	{
		if( !RowNeedsHands(i) )
			continue;

		bool Missed = false;
		for( int t=0; t<GetNumTracks(); t++ )
		{
			TapNote tn = GetTapNoteX(t, i);
			if( tn.type == TapNote::empty )
				continue;
			if( tn.type == TapNote::mine ) // mines don't count
				continue;
			if( GetTapNoteScore(t, i) <= TNS_BOO )
				Missed = true;
		}

		if( Missed )
			continue;

		/* Check hold scores. */
		for( int j=0; j<GetNumHoldNotes(); j++ )
		{
			const HoldNote &hn = GetHoldNote(j);
			HoldNoteResult hnr = GetHoldNoteResult( hn );

			/* Check if the row we're checking is in range. */
			if( !hn.RowIsInRange(i) )
				continue;

			/* If a hold is released *after* a hands containing it, the hands is
			 * still good.  So, ignore the judgement and only examine iLastHeldRow
			 * to be sure that the hold was still held at the point of this row.
			 * (Note that if the hold head tap was missed, then iLastHeldRow == i
			 * and this won't fail--but the tap check above will have already failed.) */
			if( hnr.iLastHeldRow < i )
				Missed = true;
		}

		if( !Missed )
			iNum++;
	}

	return iNum;
}
Esempio n. 19
0
Rect TableWidget::ColumnRect( int column ) const
{
    int last_row = GetNumRows() -1;
    
    Rect R = CellRect( column, 0) | CellRect( column, last_row);
    Rect r = ClientRect( column, 0) | ClientRect( column, last_row);

    return Rect( r.GetX1(), R.GetY1(), r.GetW(), R.GetH() );
}
Esempio n. 20
0
int NoteData::GetFirstNonEmptyTrack( int index ) const
{
	/* If this is out of range, we don't have any notes there, so all tracks are empty. */
	if( index < 0 || index >= GetNumRows() )
		return 0;

	for( int t=0; t<m_iNumTracks; t++ )
		if( GetTapNoteX( t, index ).type != TapNote::empty )
			return t;
	return -1;
}
Esempio n. 21
0
bool NoteData::IsRowEmpty( int index ) const
{
	/* If this is out of range, we don't have any notes there, so all tracks are empty. */
	if( index < 0 || index >= GetNumRows() )
		return true;

	for( int t=0; t<m_iNumTracks; t++ )
		if( GetTapNoteX(t, index).type != TapNote::empty )
			return false;
	return true;
}
Esempio n. 22
0
void AMatrix_base::LinearTransform(double b, double m, bool ignoreDiagonal) {
	int n = GetNumRows();
    for (int i=0; i<n; ++i) {
        for (int j=0; j<n; ++j) {
			if (ignoreDiagonal && i == j) {
				continue;
			} else {
				m_Array[i][j] = m*m_Array[i][j] + b;
			}
        }
    }	
}
Esempio n. 23
0
int NoteData::GetFirstTrackWithTapOrHoldHead( int index ) const
{
	/* If this is out of range, we don't have any notes there, so all tracks are empty. */
	if( index < 0 || index >= GetNumRows() )
		return -1;

	for( int t=0; t<m_iNumTracks; t++ )
	{
		TapNote tn = GetTapNoteX( t, index );
		if( tn.type == TapNote::tap || tn.type == TapNote::hold_head )
			return t;
	}
	return -1;
}
Esempio n. 24
0
bool hgeGUIListbox::KeyClick(const int key, int chr) {
    switch (key) {
    case HGEK_DOWN:
        if (selected_item_ < items_ - 1) {
            selected_item_++;
            if (selected_item_ > top_item_ + GetNumRows() - 1) {
                top_item_ = selected_item_ - GetNumRows() + 1;
            }
            return true;
        }
        break;

    case HGEK_UP:
        if (selected_item_ > 0) {
            selected_item_--;
            if (selected_item_ < top_item_) {
                top_item_ = selected_item_;
            }
            return true;
        }
        break;
    }
    return false;
}
Esempio n. 25
0
int NoteData::GetNumTracksWithTap( int index ) const
{
	/* If this is out of range, we don't have any notes there, so all tracks are empty. */
	if( index < 0 || index >= GetNumRows() )
		return 0;

	int iNum = 0;
	for( int t=0; t<m_iNumTracks; t++ )
	{
		TapNote tn = GetTapNoteX( t, index );
		if( tn.type == TapNote::tap )
			iNum++;
	}
	return iNum;
}
 bool WidgetTableWidget::Insert( int column, int row, Widget *client, int align_flg )
 {
     Rect::Alignment align = Rect::Alignment(align_flg);
     if ( column < GetNumColumns() && row < GetNumRows() && !Settled( column, row) )
     {
         Rect area = client->GetBoundingRect().Align( ClientRect( column, row), align ) ;
         Cell cell;
         cell._alignment = align;
         cell._settler = client;
         _settlers.Insert( Pos(column,row), cell);
         _placement.Insert( client, Pos(column,row) );
         HubWidget::Insert( client, area.GetX(), area.GetY() );
         return true;
     }
     else { assert(!"No such column or row"); return false; }
 }
Esempio n. 27
0
void delete_row(pattern_editor &editor) {
    auto pattern  = editor.active_pattern();
    auto &pos     = editor.pos();
    auto numrows  = pattern->GetNumRows();

    if (numrows > 2) {
        for (size_t row = pos.row; row <= numrows - 2; ++row) {
            auto evt     = pattern->GetpModCommand(row, pos.column);
            auto nextevt = pattern->GetpModCommand(row + 1, pos.column);
        }
    }
    if (numrows > 1) {
        pattern->GetpModCommand(numrows - 1, pos.column)->Clear();
    }

    editor.update();
}
Esempio n. 28
0
void HighScores::SaveScores()
{
	FILE* scores_file = fopen("scores.txt", "wt");

	if (scores_file)
	{
		for (int i = 0; i < GetNumRows("scores"); i++)
		{
			Rocket::Core::String colour_string;
			Rocket::Core::TypeConverter< Rocket::Core::Colourb, Rocket::Core::String >::Convert(scores[i].colour, colour_string);

			Rocket::Core::String score(1024, "%s\t%s\t%d\t%d\n", scores[i].name.CString(), colour_string.CString(), scores[i].wave, scores[i].score);
			fputs(score.CString(), scores_file);		
		}

		fclose(scores_file);
	}
}
Esempio n. 29
0
void hgeGUIListbox::Render()
{
	int i;
	hgeGUIListboxItem *pItem=pItems;

	for(i=0;i<nTopItem;i++) pItem=pItem->next;
	for(i=0;i<GetNumRows();i++)
	{
		if(nTopItem+i == nSelectedItem)
		{
			sprHighlight->Render(rect.x1,rect.y1+i*font->GetHeight());
			font->SetColor(texthilColor);
		}
		else font->SetColor(textColor);
		font->Render(rect.x1+3, rect.y1+i*font->GetHeight(), HGETEXT_LEFT, pItem->text);
		if(i>=nItems) return;
		pItem=pItem->next;
	}
}
Esempio n. 30
0
//  Does not assume a symmetric matrix.
void AMatrix_base::GetExtremalEntries(double& max, double& min, bool ignoreDiagonal) {
	int i, j;
	int n = GetNumRows();
	double maxEntry=kMin_Double;
	double minEntry=kMax_Double;
	for (i=0; i<n; ++i) {
		for (j=0; j<n; ++j) {
			if (ignoreDiagonal && i == j) {
				continue;
			}
			if (m_Array[i][j] > maxEntry) {
				maxEntry = m_Array[i][j];
			}
			if (m_Array[i][j] < minEntry) {
				minEntry = m_Array[i][j];
			}
		}
	}
	max = maxEntry;
	min = minEntry;
}