static void admm_normaleq(void* _data, float* _dst, const float* _src) { struct admm_normaleq_data* data = _data; long dims[1] = { data->N }; //float* tmp = md_alloc_sameplace(1, dims, FL_SIZE, _src ); md_clear(1, dims, _dst, sizeof(float)); for (unsigned int i = 0; i < data->num_funs; i++) { data->ops[i].normal(data->ops[i].data, data->tmp, _src); if ((NULL != data->Aop) && (NULL != data->Aop_data)) md_axpy(1, dims, _dst, data->rho, data->tmp); else md_add(1, dims, _dst, _dst, data->tmp); } if ((NULL != data->Aop) && (NULL != data->Aop_data)) { data->Aop(data->Aop_data, data->tmp, _src); md_add(1, dims, _dst, _dst, data->tmp); } //md_free( tmp ); }
/* * Read in a midi file from the specified open file pointer, fp * and return an mtree structure tree representing the file. * * Arguments: * fp - Input file pointer */ struct rootElement * midi_read(FILE *fp) { struct midistate mState; struct midistate *msp; struct rootElement *root; struct element *el; int i; msp = &mState; msp->fp = fp; msp->tempo_map = md_tempomap_new(); msp->notes = g_ptr_array_new(); msp->port = 0; root = read_head(msp); md_add(MD_CONTAINER(root), NULL); /* Leave room for the tempo map */ for (i = 0; i < root->tracks; i++) { el = MD_ELEMENT(read_track(msp)); /* If format 1 then the first track is really the tempo map */ if (root->format == 1 && i == 0 && MD_CONTAINER(el)->elements->len == 0) { /* It will be added after the loop */ md_free(el); continue; } md_add(MD_CONTAINER(root), el); } g_ptr_array_index(MD_CONTAINER(root)->elements, 0) = msp->tempo_map; msp->tempo_map = NULL; g_ptr_array_free(msp->notes, 1); return root; }
/** * Proximal function for f(z) = Ind{ || y - z ||_2 < eps } * * @param prox_data should be of type prox_l2ball_data * @param mu proximal penalty * @param z output * @param x_plus_u input */ static void prox_l2ball_fun(const operator_data_t* prox_data, float mu, float* z, const float* x_plus_u) { UNUSED(mu); struct prox_l2ball_data* pdata = CAST_DOWN(prox_l2ball_data, prox_data); if (NULL != pdata->center) md_sub(1, MD_DIMS(pdata->size), z, x_plus_u, pdata->center); else md_copy(1, MD_DIMS(pdata->size), z, x_plus_u, FL_SIZE); float q1 = md_norm(1, MD_DIMS(pdata->size), z); if (q1 > pdata->eps) md_smul(1, MD_DIMS(pdata->size), z, z, pdata->eps / q1); if (NULL != pdata->center) md_add(1, MD_DIMS(pdata->size), z, z, pdata->center); }
/* * Do extra handling of meta events. We want to save time * signature and key for use elsewhere, for example. This * routine create the correct type of class and returns it. * * Arguments: * msp - The midi file state * type - The meta event type * data - The data for the event */ static struct metaElement * handle_meta(struct midistate *msp, int type, unsigned char *data) { struct metaElement *el = NULL; struct mapElement *map = NULL; int micro_tempo; switch (type) { case MIDI_META_SEQUENCE: break; case MIDI_META_TEXT: case MIDI_META_COPYRIGHT: case MIDI_META_TRACKNAME: case MIDI_META_INSTRUMENT: case MIDI_META_LYRIC: case MIDI_META_MARKER: case MIDI_META_CUE: /* Text based events */ el = MD_META(md_text_new(type, (char*)data)); break; case MIDI_META_CHANNEL: break; case MIDI_META_PORT: msp->port = data[0]; g_free(data); break; case MIDI_META_EOT: break; case MIDI_META_TEMPO: micro_tempo = ((data[0]<<16) & 0xff0000) + ((data[1]<<8) & 0xff00) + (data[2] & 0xff); map = MD_MAP(md_tempo_new(micro_tempo)); g_free(data); break; case MIDI_META_SMPTE_OFFSET: el = MD_META(md_smpteoffset_new(data[0], data[1], data[2], data[3], data[4])); break; case MIDI_META_TIME: map = MD_MAP(md_timesig_new(data[0], 1<<data[1], data[2], data[3])); g_free(data); break; case MIDI_META_KEY: map = MD_MAP(md_keysig_new(data[0], (data[1]==1)? 1: 0)); g_free(data); break; case MIDI_META_PROP: /* Proprietry sequencer specific event */ /* Just throw it out */ break; default: g_warning("Meta event %d not implemented\n", type); break; } /* If this affected the tempo map then add it */ if (map) { MD_ELEMENT(map)->element_time = msp->current_time; md_add(MD_CONTAINER(msp->tempo_map), MD_ELEMENT(map)); } return el; }
/* * Complete the reading of the status byte. The parsed midi * command will be added to the specified track . * * Arguments: * msp - Current midi file status * track - Current track * status - Status byte, ie. current command */ static void handle_status(struct midistate *msp, struct trackElement *track, int status) { int ch; int type; int device; int length; short note, vel, control; int val; unsigned char *data; struct element *el; ch = status & 0x0f; type = status & 0xf0; /* * Do not set the device if the type is 0xf0 as these commands are * not channel specific */ device = 0; if (type != 0xf0) device = (msp->port<<4) + ch; msp->device = device; el = NULL; switch (type) { case MIDI_NOTE_OFF: note = read_int(msp, 1); vel = read_int(msp, 1); finish_note(msp, note, vel); break; case MIDI_NOTE_ON: note = read_int(msp, 1); vel = read_int(msp, 1); if (vel == 0) { /* This is really a note off */ finish_note(msp, note, vel); } else { /* Save the start, so it can be matched with the note off */ el = save_note(msp, note, vel); } break; case MIDI_KEY_AFTERTOUCH: note = read_int(msp, 1); vel = read_int(msp, 1); /* new aftertouchElement */ el = MD_ELEMENT(md_keytouch_new(note, vel)); break; case MIDI_CONTROLER: control = read_int(msp, 1); val = read_int(msp, 1); el = MD_ELEMENT(md_control_new(control, val)); break; case MIDI_PATCH: val = read_int(msp, 1); el = MD_ELEMENT(md_program_new(val)); break; case MIDI_CHANNEL_AFTERTOUCH: val = read_int(msp, 1); el = MD_ELEMENT(md_pressure_new(val)); break; case MIDI_PITCH_WHEEL: { val = read_int(msp, 1); int val2 = read_int(msp, 1); val |= val2 << 7; val -= 0x2000; /* Center it around zero */ el = MD_ELEMENT(md_pitch_new(val)); break; } /* Now for all the non-channel specific ones */ case 0xf0: /* Deal with the end of track event first */ if (ch == 0x0f) { type = read_int(msp, 1); if (type == 0x2f) { /* End of track - skip to end of real track */ track->final_time = msp->current_time; skip_chunk(msp); return; } } /* Get the length of the following data */ length = read_var(msp); data = read_data(msp, length); if (ch == 0x0f) { el = (struct element *)handle_meta(msp, type, data); } else { el = (struct element *)md_sysex_new(status, data, length); } break; default: except(formatError, "Bad status type 0x%x", type); /*NOTREACHED*/ } if (el != NULL) { el->element_time = msp->current_time; el->device_channel = device; md_add(MD_CONTAINER(track), el); } }