예제 #1
0
파일: audio_edit.c 프로젝트: AlisterH/gwc
void truncate_wavfile(struct view *v, int save_undo)
{
    int rc;
    long first, last;
    long end_pos = soundfile_count_samples();
    char undo_label[200];

    get_region_of_interest(&first, &last, v);

    if (save_undo) {
        /* split undo-data to undo separately in case of failure */
        sprintf(undo_label, "Delete audio data from %ld to %ld.", last+1, end_pos);
        if (start_save_undo(undo_label, v) < 0)
            return;
        rc = save_undo_data_remove(last+1, end_pos, 1);
        close_undo();
        if (rc == 1) /* canceled */
            return;
    }

    begin_operation("Deleting audio data") ;
    rc = soundfile_remove_samples(last+1, end_pos, 1);
    end_operation();

    if (rc != 0) {
        /* failure; FIX: needs cleanup of undo and more */
        return;
    }

    if (save_undo) {
        /* second part of undo */
        sprintf(undo_label, "Delete audio data from 0 to %ld.", first-1);
        if (start_save_undo(undo_label, v) < 0)
            return;
        rc = save_undo_data_remove(0, first-1, 1);
        close_undo();
        /* cancel ignored */
    }

    begin_operation("Deleting audio data") ;
    rc = soundfile_remove_samples(0, first-1, 1);
    end_operation();

    if (rc != 0) {
        /* failure; FIX: needs cleanup of undo and more */
        return;
    }

    adjust_view(v);

    v->first_sample = 0;
    v->last_sample  = v->n_samples - 1;
    v->selection_region = FALSE;

    resample(0, prefs.n_samples-1);
}
예제 #2
0
파일: audio_edit.c 프로젝트: AlisterH/gwc
int audioedit_delete_selection(struct view *v)
{
    int rc = -1;
    long first, last;
    char undo_label[200];

    get_region_of_interest(&first, &last, v);

    sprintf(undo_label, "Delete audio data from %ld to %ld.", first, last);
    if (start_save_undo(undo_label, v) < 0)
        return -1;
    rc = save_undo_data_remove(first, last, 1);
    close_undo();
    if (rc == 1) /* canceled */
        return -1;

    begin_operation("Deleting audio data") ;
    rc = soundfile_remove_samples(first, last - first + 1, 1);
    end_operation();

    if (rc == 0) {
        adjust_view(v);
        v->selection_region = FALSE;
        resample(first, prefs.n_samples-1);
    }
    return rc;
}
예제 #3
0
파일: audio_edit.c 프로젝트: AlisterH/gwc
static void resample(long first, long last)
{
    begin_operation("Resampling audio data");
    resample_audio_data(&prefs, first, last);
    end_operation();
    save_sample_block_data(&prefs);
    display_times();
}
예제 #4
0
파일: audio_edit.c 프로젝트: AlisterH/gwc
int audioedit_copy_selection(struct view *v)
{
    int rc;
    long first, last;
    get_region_of_interest(&first, &last, v);

    begin_operation("Saving internal clipboard");
    rc = soundfile_save_file(CLIPBOARD_FILE, first, last - first + 1, 1);
    end_operation();

    return rc;
}
예제 #5
0
파일: audio_edit.c 프로젝트: AlisterH/gwc
int audioedit_paste_selection(struct view *v)
{
    int rc = -1;
    long sample_count;

    sample_count = audioedit_count_samples_in_clipdata();
    if (sample_count > 0)
    {
        long first, last;
        char undo_label[200];
        get_region_of_interest(&first, &last, v);

        sprintf(undo_label, "Paste audio data from %ld to %ld.", first, last);
        if (start_save_undo(undo_label, v) < 0)
            return -1;
        save_undo_data_insert(first, last, 1);
        close_undo();

        begin_operation("Inserting space for clipboard data") ;
        rc = soundfile_shift_samples_right(first, sample_count, 1);
        end_operation();

        if (rc == 0) {
            begin_operation("Inserting clipboard data");
            rc = soundfile_load_file(CLIPBOARD_FILE, first, sample_count, 1);
            end_operation();

            adjust_view(v);
            v->selection_region = FALSE;

            resample(first, prefs.n_samples-1);
        }
    }

    return rc;
}
예제 #6
0
파일: audio_edit.c 프로젝트: AlisterH/gwc
int audioedit_insert_silence(struct view *v)
{
    long first, last;

    get_region_of_interest(&first, &last, v);
    if (v->selection_region) {
        char undo_label[200];

        sprintf(undo_label, "Insert silence from %ld to %ld.", first, last);
        if (start_save_undo(undo_label, v) < 0)
            return -1;
        save_undo_data_insert(first, last, 1);
        close_undo();

        begin_operation("Inserting silence") ;
        soundfile_insert_silence(first, last - first + 1, 1);
        end_operation();

        adjust_view(v);
        resample(first, prefs.n_samples-1);
        return 0;
    }
    return -1;
}
예제 #7
0
파일: i2c.c 프로젝트: ekiwi/led-table
/*
 * i2c state machine
 * returns 0 when state == IDLE
 */
uint8_t i2c_async_run(void){
	uint8_t i2c_stat;
	switch(i2c_a.state){
	case I2C_IDLE:
		if(i2c_a.connecting){					// if connecting => start connection
			i2c_send_start_condition();
			set_state(I2C_SENDING_START_CONDITON);
		}
		else if(i2c_a.stop &&(i2c_a.stop_forced || (!i2c_a.operation && i2c_a.connected))){
			i2c_send_stop_condition();
			set_state(I2C_SENDING_STOP_CONDITION);
		}
		else {
			switch(i2c_a.operation){
			case NONE:
				break;
			case READ_BYTE_ACK:
			case READ_WORD:							// the first read action of read_word and read_array is always a read_ack
			case READ_ARRAY:
				i2c_start_read_ack();				// if read_ack, issue command, set state to I2C_READING
				set_state(I2C_READING);
				break;
			case READ_BYTE_NAK:						// if read_nak, issue command, set state to I2C_READING
				i2c_start_read_nak();
				set_state(I2C_READING);
				break;
			case WRITE:								// if read, issue command, set state to I2C_WRITING
				i2c_start_write(i2c_a.b1);
				set_state(I2C_WRITING);
				break;
			case WRITE_2:
				i2c_start_write(i2c_a.b2);
				set_state(I2C_WRITING);
				break;
			}
		}
		break;

	case I2C_SENDING_START_CONDITON:
		if(i2c_trans_completed){			// if transmission has been completed
			i2c_stat = TW_STATUS;			// read i2c status
			if((i2c_stat != TW_START) && (i2c_stat != TW_REP_START)) error();	//if there is an error => return and set state
			i2c_start_send_address(i2c_a.address);	// start sending address
			set_state(I2C_SENDING_ADDRESS);			// set state to I2C_SENDING_ADDRESS
		}
		break;

	case I2C_SENDING_ADDRESS:
		if(i2c_trans_completed){			// if transmission has been completed
			i2c_stat = TW_STATUS;			// read i2c status
			if(!i2c_a.start_wait && (i2c_stat != TW_MT_SLA_ACK) && (i2c_stat != TW_MR_SLA_ACK))
				error();							//if there is an error => return and set state
			if(i2c_a.start_wait && ((i2c_stat == TW_MT_SLA_NACK )||(i2c_stat ==TW_MR_DATA_NACK))){
				i2c_send_stop_condition();		// if device bussy => send stop condition
				set_state(I2C_WAITING_FOR_DEVICE);
			}
			else {
				i2c_a.connecting = false;				// if there was no error => connected => go to idle
				i2c_a.connected = true;
				i2c_a.start_wait = false;
				set_state(I2C_IDLE);
			}
		}
		break;

	case I2C_WAITING_FOR_DEVICE:
		if(!i2c_stop_trans_not_completed){	// if transmission has been completed
			set_state(I2C_IDLE);					// restart connect
		}
		break;

	case I2C_SENDING_STOP_CONDITION:
		if(!i2c_stop_trans_not_completed){	// if transmission has been completed
			i2c_a.connected = false;
			i2c_a.stop = false;
			end_operation();
		}
		break;

	case I2C_READING:
		if(i2c_trans_completed){		// if transmission has been completed
			switch(i2c_a.operation){
			case READ_BYTE_ACK:						// if reading byte value
			case READ_BYTE_NAK:
				i2c_a.b1 = TWDR;						// save byte in byte value
				end_operation();					// done => set operation to NONE and go to IDLE
				break;
			case READ_WORD:
				if(i2c_a.reading_msb){
					i2c_a.w = (TWDR<<8);			// save msb
					i2c_a.reading_msb = false;		// not reading msb anymore
					i2c_start_read_nak();			// start reading again
					set_state(I2C_READING);			// set corresponding state
				}
				else {
					i2c_a.w |= TWDR;
					end_operation();				// done => set operation to NONE and go to IDLE
				}
				break;
			case READ_ARRAY:
				//deb_b(i2c_a.array_length);
				if(i2c_a.reading_msb){
					*i2c_a.array = ((TWDR & i2c_a.bit_mask)<<8);// save msb
					i2c_a.reading_msb = false;		// not reading msb anymore
					if(i2c_a.array_length < 2){		// if length = 1
						i2c_start_read_nak();		// start reading again
					}
					else {
						i2c_start_read_ack();		// start reading again
					}
					set_state(I2C_READING);			// set corresponding state
				}
				else{
					*i2c_a.array |= TWDR;			// save lsb
					if(i2c_a.array_length < 2){		// if length = 1
						end_operation();			// done => set operation to NONE and go to IDLE
					}
					else {
						if(i2c_a.array_length == i2c_a.array_omit_value){
							i2c_a.array_omit_value = -1;
						}
						else {
							i2c_a.array++;				// move array pointer
							i2c_a.array_length--;		// decrease length to be read
						}
						i2c_a.reading_msb = true;	// read msb next
						i2c_start_read_ack();		// start reading again
						set_state(I2C_READING);		// set corresponding state
					}
				}
				break;
			case WRITE:
			case WRITE_2:
			case NONE:
				break;
			}
		}
		break;

	case I2C_WRITING:
		if(i2c_trans_completed){		// if transmission has been completed
			i2c_stat = TW_STATUS;			// read i2c status
			if(i2c_stat != TW_MT_DATA_ACK)  error();// if there is an error => return and set state
			if(i2c_a.operation == WRITE_2){
				i2c_a.operation = WRITE;
				set_state(I2C_IDLE);
			}
			else{
				end_operation();					// if there is no error => done => set operation to NONE and go to IDLE
			}
		}
		break;

	case I2C_FAILED:
		i2c_a.failed = true;
		end_operation();
		break;

	default:
		set_state(I2C_IDLE);
		break;
	}
	return (i2c_a.state || i2c_a.start_wait || i2c_a.operation || i2c_a.stop) && !i2c_a.failed;
}